Jump to content

User:UninvitedCompany/common.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// from User:Pythoncoder/Scripts/userHighlighter.js

//<nowiki>
/**
 * User highlighter 3.0
 * ---------------------
 * A jQuery/mediawiki-heavy rewrite of [[User:Amalthea/userhighlighter.js]]
 * 
 * This script highlights links to admins' userpages or talkpages in bodyContent
 * (that is, everything but the tabs, personal links at the top of the screen and sidebar)
 * by giving them a gold background. It also colors links to userpages of users with lower
 * and higher-ranked permissions
 *
 * See [[User:Theopolisme/Scripts/adminhighlighter]] for more details.
 *
 * Version 3.0 merges Bellezzasolo and Amorymeltzer's version.
 * TODO: Rollback, Techadmin
 *
 * @author theopolisme
 * @author Bellezzasolo
 * @author Amorymeltzer
 * @author Pythoncoder
 */
mw.hook('wikipage.content').add(function($, mw){
	var ecdata, pcdata, mvdata, tpdata, addata;
	$.when(
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/arbcom.json', function(data){
		acdata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/bureaucrat.json', function(data){
		crdata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/oversight.json', function(data){
		osdata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/checkuser.json', function(data){
		cudata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/excon.js', function(data){
		ecdata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pcusr.js', function(data){
		pcdata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pgmvr.js', function(data){
		mvdata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/temop.js', function(data){
		tpdata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Amalthea_(bot)/userhighlighter.js/sysop.js', function(data){
		addata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/ptusr.js', function(data){
		ptdata = data;
	}),
	$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/interface-admin.json', function(data){
		iadata = data;
	})).then(function() {
	ADMINHIGHLIGHT_EXTLINKS = window.ADMINHIGHLIGHT_EXTLINKS || false;
	ADMINHIGHLIGHT_NAMESPACES = [-1,2,3];
	mw.loader.using(['mediawiki.util','mediawiki.Uri', 'mediawiki.Title'], function() {
		mw.util.addCSS("[class~=userhighlighter_excon] {background-color: #99f}");
		mw.util.addCSS("[class~=userhighlighter_pcusr] {background-color: #ddd}");
		mw.util.addCSS("[class~=userhighlighter_ptusr] {background-color: #9ff}");
		mw.util.addCSS("[class~=userhighlighter_pgmvr] {background-color: #bf9}");
		mw.util.addCSS("[class~=userhighlighter_temop] {background-color: #fce}");
		mw.util.addCSS("[class~=userhighlighter_sysop] {background-color: #ff9}");
		mw.util.addCSS("[class~=userhighlighter_checkuser] {background-color: #9df}");
		mw.util.addCSS("[class~=userhighlighter_oversight] {background-color: #888}");
		mw.util.addCSS("[class~=userhighlighter_interface-admin] {background-color: #9fd}");
		mw.util.addCSS("[class~=userhighlighter_bureaucrat] {background-color: #fd9}");
		mw.util.addCSS("[class~=userhighlighter_arbcom] {background-color: #f99}");
		$('#article a, #bodyContent a, #mw_contentholder a').each(function(index,linkraw){
			try {
				var link = $(linkraw);
				var url = link.attr('href');
				if (!url || url.charAt(0) === '#') return; // Skip <a> elements that aren't actually links; skip anchors
				if (url.lastIndexOf("http://", 0) !== 0 && url.lastIndexOf("https://", 0) !== 0 && url.lastIndexOf("/", 0) !== 0) return; //require http(s) links, avoid "javascript:..." etc. which mw.Uri does not support
				var uri = new mw.Uri(url);
				if (!ADMINHIGHLIGHT_EXTLINKS && !$.isEmptyObject(uri.query)) return; // Skip links with query strings if highlighting external links is disabled
				if (uri.host == 'en.wikipedia.org') {
					var mwtitle = new mw.Title(mw.util.getParamValue('title',url) || decodeURIComponent(uri.path.slice(6))); // Try to get the title parameter of URL; if not available, remove '/wiki/' and use that
					if ($.inArray(mwtitle.getNamespaceId(), ADMINHIGHLIGHT_NAMESPACES)>=0) {
						var user = mwtitle.getMain().replace(/_/g," ");
						if (mwtitle.getNamespaceId() === -1) user = user.replace('Contributions/',''); // For special page "Contributions/<username>"
						if (mwtitle.getNamespaceId() === -1) user = user.replace('Contribs/',''); // The Contribs abbreviation too
						
						if(acdata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_arbcom');
						}
						if(crdata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_bureaucrat');
						}
						if(osdata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_oversight');
						}
						if(cudata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_checkuser');
						}
						if (addata[user] == 1) {
							link.addClass(link.attr('class') + ' userhighlighter_sysop');
						}
					}
				}
			} catch (e) {
				// Sometimes we will run into unparsable links, so just log these and move on
				window.console && console.error('Admin highlighter recoverable error',e.message);
			}
		});
	});
	});
}(jQuery, mediaWiki));

// from User:Enterprisey/url-select-revdel.js
$( function () {
    if( mw.config.get( "wgAction" ) === "history" ) {
        mw.loader.using( [ "mediawiki.util" ], function () {
            var param = mw.util.getParamValue( "revdel_select" );
            if( param ) {
                var pageHistory = document.getElementById( "pagehistory" );
                var oldids = param.split( "|" ).filter( Boolean );
                if( oldids.some( function ( oldid ) { return oldid.indexOf( ".." ) >= 0; } ) ) {
                    var allCheckboxes = Array.prototype.slice.call( pageHistory.querySelectorAll( "input[name^='ids[']" ) );
                }
                function expandRange ( range ) {
                    var start = range[0],
                        end = range[1],
                        startCheckbox = pageHistory.querySelector( "input[name='ids[" + start + "]']" ),
                        endCheckbox = pageHistory.querySelector( "input[name='ids[" + end + "]']" ),
                        startIdx = allCheckboxes.indexOf( startCheckbox ),
                        endIdx = allCheckboxes.indexOf( endCheckbox ),
                        checkboxes = [];
                    if( !startCheckbox ) throw( "No checkbox found for revision " + start );
                    if( !endCheckbox ) throw( "No checkbox found for revision " + end );
                    for( var idx = startIdx, inc = Math.sign( endIdx - startIdx );
                            idx != endIdx; idx += inc ) {
                        checkboxes.push( allCheckboxes[ idx ] );
                    }
                    checkboxes.push( endCheckbox );
                    return checkboxes;
                }
                var singletonSelectors = [];
                function makeChecked( box ) { box.checked = true; }
                for( var i = 0, n = oldids.length; i < n; i++ ) {
                    if( oldids[i].indexOf( ".." ) >= 0 ) {
                        expandRange( oldids[i].split( ".." ) ).forEach( makeChecked );
                    } else {
                        singletonSelectors.push( "input[name='ids[" + oldids[i] + "]']" );
                    }
                }
                if( singletonSelectors.length ) {
                    Array.prototype.slice.call( document.querySelectorAll(
                            singletonSelectors.join( "," ) ) ).forEach( makeChecked );
                }
            }
        } );
    }
} );
//</nowiki>