User:L10nM4st3r/common.js

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

Note: After saving, you have to bypass your browser's cache to see the changes.

  • Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
  • Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
  • Opera, Konqueror and Safari users can just click the Reload button.
  • Chrome: press Ctrl+F5 or Shift+F5
window.wTools_config = {
	editorShowInvisibleCharacters: true,
	editorShowIndentGuides: true,
}

//mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:L10nM4st3r/Template_Remover.js&action=raw&ctype=text/javascript');


//if (mw.config.get("wgAction") === "view" && mw.config.get("wgPageName") === "User:L10nM4st3r/Tools")
    //mw.loader.load('//en.uncyclopedia.co/w/index.php?title=User:L10nM4st3r/maintenance_tools.js&action=raw&ctype=text/javascript');



//mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:L10nM4st3r/wToolCore/Unstable.js&action=raw&ctype=text/javascript');
mw.loader.load('https://en.uncyclopedia.co/w/index.php?title=User:L10nM4st3r/convenientDiscussionsConfig.js&action=raw&ctype=text/javascript');

// Fix this later
//mw.loader.load('https://en.uncyclopedia.co/w/index.php?title=User:L10nM4st3r/achivement.js&action=raw&ctype=text/javascript');



// Loads [[User:L10nM4st3r/botScript.js/LogPrettifier.js]]
if (mw.config.get("wgPageName") === "User:C.A.T_3000/log" && mw.config.get("wgAction") === "view")
	mw.loader.load('https://en.uncyclopedia.co/w/index.php?title=User:L10nM4st3r/botScript.js/LogPrettifier.js&action=raw&ctype=text/javascript');

/**
 * The code on this page was taken from [[User:JJPMaster/CurateThisPage2/markpatrolled1.js]] and [[User:JJPMaster/CurateThisPage2/markpatrolled2.js]], and then slightly modified by [[User:L10nM4st3r]].
 * 
 * Adds a portlet link which allows you to patrol all the edits to a page all at once, and adds a [mark as patrolled] link to change list items, which have the red exclamation mark.
 */

/**
 * Adds a portlet link which allows you to patrol all the edits to a page all at once.
 */
setTimeout(function () {


var api = new mw.Api();
var userGroups = mw.config.get("wgUserGroups"),
	canUseMarkPatrolledTool = userGroups.includes("rolbackers") || userGroups.includes("sysop") || userGroups.includes("bureaucrat") || userGroups.includes("sysadmin");


/*%fold%*/if (canUseMarkPatrolledTool && mw.config.get("wgNamespaceNumber") >= 0) {
	mw.util.addPortletLink('p-cactions', '#', 'Mark as patrolled', 'markpatrolled', 'Just mark this page, and all recent revisions, as patrolled!');
	
	$("#markpatrolled").click(function (e) {
		e.preventDefault();
		
		var page_title = mw.config.get("wgPageName"),
			params = {
				action: 'query',
				list: 'recentchanges',
				rcprop: 'title|ids|sizes|flags|user',
				rctitle: page_title,
				rcshow: "unpatrolled",
				format: 'json'
			};
		
		api.get( params ).done( function ( data ) {
			var recentchanges = data.query.recentchanges,
			totalRevisionsMarked = 0,
				  totalRevisionsToMark = 0;
			
			if (recentchanges.length == 0) {
				mw.notify( "No revisions to patrol." );
			}
			for (var rcIndex = 0; rcIndex < recentchanges.length; rcIndex ++ ) {
				var rc = recentchanges[rcIndex],
				revision_id = rc.revid,
					patrol_params = {
					action: 'patrol',
					revid: revision_id,
					format: 'json'
				};
				totalRevisionsToMark ++;
				
				api.postWithToken( 'patrol', patrol_params ).done( function ( data ) {
					totalRevisionsMarked ++;
					if ( totalRevisionsMarked == totalRevisionsToMark ) {
						mw.notify( "Page successfully marked " + totalRevisionsMarked + " revisions as patrolled!" );
					}
					console.log( data );
				});
			}
		} );
	});
}


/**
 * Adds a [mark as patrolled] link to change list items, which have the red exclamation mark.
 */
if ( canUseMarkPatrolledTool && [ 'Watchlist', 'Recentchanges', 'Recentchangeslinked', 'Newpages' ].includes(mw.config.get( 'wgCanonicalSpecialPageName' )) ) {
	
	function markPatrolled( event, unpatrolledAbbrRemove ) {
		event.preventDefault();
		
		function doPatrol( revid ) {
			api.postWithToken( 'patrol', { formatversion: 2, action: 'patrol', revid: revid } )
			.then( function () {
				$( event.target ).closest( '.patrollink' ).remove();
				unpatrolledAbbrRemove();
			} );
		}
		
		
		// We were given a page title, rather than a revid. This is usually the case for file uploads, so we get the first edit for the page.
		// This is not the preffered method though, since reuploads of files will break this...
		if (event.data.pageTitle) {
			api.get( {
				action: "query",
				format: "json",
				prop: "revisions",
				titles: event.data.pageTitle,
				rvprop: "ids",
				rvlimit: "1",
				rvstart: "1970-01-01T00:00:00.000Z",
				rvdir: "newer",
				formatversion: 2
			} ).then( function ( ret ) {
				var revid = ret.query.pages[0].revisions[0].revid;
				doPatrol(revid);
			} );
		}
		else {
			doPatrol(event.data.revid);
		}
	}
	
	function main( element ) {
		$( element ).find( 'abbr.unpatrolled' ).closest( 'li, tr' ).each( function () {
			var revisionToReview;
			var pageTitle;
			
			if ( this.addedMarkPatrollLink ) {
				return;
			}
			
			this.addedMarkPatrollLink = true;
			
			var href = $( this ).find( 'a[href*="&diff="]' ).attr( 'href' );
			
			if ( href === undefined ) {
				revisionToReview = this.getAttribute( "data-mw-revid" );
				if ( typeof revisionToReview === "object" ) {
					if ( this.getAttribute( "data-mw-logaction" ) === "upload/upload" ) {
						// Try to get the last page title. If we have the page title, we can get the revid from that.
						var data = $( this ).find( "span.mw-changeslist-line-inner" );
						pageTitle = data.attr( "data-target-page" );
					}
					else {
						return;
					}
				}
			}
			else {
				var revid = href.match( /&diff=(\d*)/ )[ 1 ];
				if ( revid === '0' ) {
					revid = href.match( /&oldid=(\d*)/ )[ 1 ];
				}
				
				revisionToReview = revid;
			}
			
			
			var $target = this.nodeName === 'TR' ? $( this ).children( 'td:last' ) : $( this );
			var abbrMark = $( this ).find( 'abbr.unpatrolled' );
			
			$target
			.append( ' ',
				$( '<span>' ).addClass( 'patrollink' )
				.append( '[',
					$( '<a>' ).attr( 'href', '#' )
					.text( mw.msg( 'markaspatrolleddiff' ) )
					.click( { revid: revisionToReview, pageTitle: pageTitle }, function (event) {
						markPatrolled( event, function () {
							abbrMark.remove();
						} );
					} ),
				']' )
			);
		} );
	}
	
	api.loadMessages( 'markaspatrolleddiff' )
	.then( function () {
		mw.hook( 'wikipage.content' ).add( function ( element ) {
			setInterval( function () { main( element ); }, 500 );
		} );
	} );
}

});