Jump to content

User:TheSandDoctor/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TheSandDoctor (talk | contribs) at 03:04, 11 July 2021 (+ User:SD0001/RFUD-helper.js). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Enable caching for resource loads, see [[User:SD0001/Making_user_scripts_load_faster]], @revision 3
if (!/\bnocache=\b/.test(location.href)) { // Don't enable if nocache=1 url parameter is given
	var loadResource = function(page, sitename, ctype) {
		page = page.replace(/special:mypage/i, 'User:' + mw.config.get('wgUserName'));
		return $.get(
			'https://' + sitename + '/w/api.php?titles=' + encodeURIComponent(page) + 
			'&origin=*&format=json&formatversion=2&uselang=content&maxage=86400&smaxage=86400' + 
			'&action=query&prop=revisions|info&rvprop=content&rvlimit=1'
		).then(function(apiResponse) {
			var apiPage = apiResponse.query.pages[0];
			if (apiPage.missing) {
				return;
			}
			var content = apiPage.revisions[0].content;
	    	if ((!ctype || ctype === 'text/javascript') && apiPage.contentmodel === 'javascript') {
				var scriptTag = document.createElement('script');
				scriptTag.innerHTML = content;
				document.head.appendChild(scriptTag);
		    } else if (ctype === 'text/css' && apiPage.contentmodel === 'css') {
				mw.loader.addStyleTag(content);
			} else {
				return $.Deferred().reject('Refused to load "' + page + '"@' + sitename + ': content type mismatch');
			}
		});
	};
	var getSiteTitle = function(url) {
		var siteRgx = /^(?:(?:https:)?\/\/(.*))?\/w\/index.php/.exec(url),
			titleRgx = /\btitle=([^=?&]*)/.exec(url);
		if (siteRgx && titleRgx && /\baction=raw\b/.test(url) && /\bctype=/.test(url)) {
			return [titleRgx[1], siteRgx[1] || mw.config.get('wgServerName')];	
		} else return null;
	};
	window.importScript = function(page) {
		loadResource(page, mw.config.get('wgServerName'), 'text/javascript');
	};
	window.importStyleSheet = function(page) {
		loadResource(page, mw.config.get('wgServerName'), 'text/css');
	};
	var oldMwLoaderLoad = mw.loader.load;
	mw.loader.load = function(url, type) {
		var linkParts = getSiteTitle(url);
		if (linkParts) {
			loadResource(linkParts[0], linkParts[1], type);
		} else {
			oldMwLoaderLoad.apply(mw.loader, Array.prototype.slice.call(arguments));
		}
	};
	var oldMwLoaderGetScript = mw.loader.getScript;
	mw.loader.getScript = function(url) {
		var linkParts = getSiteTitle(url);
		if (linkParts) {
			return loadResource(linkParts[0], linkParts[1], 'text/javascript');
		} else {
			return oldMwLoaderGetScript.apply(mw.loader, Array.prototype.slice.call(arguments));
		}
	};
}
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Nardog/CatChangesViewer.js&action=raw&ctype=text/javascript' );
importScript('User:SD0001/shortdescs-in-category.js'); // [[User:SD0001/shortdescs-in-category.js]]
importScript( 'User:Writ Keeper/Scripts/commonHistory.js');	// Linkback: [[User:Writ Keeper/Scripts/commonHistory.js]] - shows [inspect diff]
importScript( 'User:Enterprisey/easy-brfa.js' ); // Linkback: [[User:Enterprisey/easy-brfa.js]]
importScript( 'User:Ohconfucius/script/formatgeneral.js' ); // Linkback: [[User:Ohconfucius/script/formatgeneral.js]]
importScript('User:Ohconfucius/script/EngvarB.js'); // [[User:Ohconfucius/script/EngvarB.js]]
maxUsersCUStaleness = 300;
/** Sockpuppet investgation ([[WP:SPI]]) related scripts.*/
//importScript( 'User:Timotheus Canens/spihelper.js' ); // Linkback: [[User:Timotheus Canens/spihelper.js]] - Script to handle the administration of Sockpuppet Investigations
importScript( 'User:GeneralNotability/spihelper.js' ); // Backlink: [[User:GeneralNotability/spihelper.js]]
mw.loader.load("/w/index.php?title=User:Writ Keeper/Scripts/cuStaleness.js&action=raw&ctype=text/javascript"); // Linkback: [[User:Writ Keeper/Scripts/cuStaleness.js]] - A visual aid to quickly identify whether check user would be of any use
mw.loader.load("/w/index.php?title=User:Writ Keeper/Scripts/sockStaleness.js&action=raw&ctype=text/javascript"); // Linkback: [[User:Writ Keeper/Scripts/sockStaleness.js]] - Similar to the above. Not sure the exact different between these two

/** Others */
importScript( 'User:MusikAnimal/userRightsManager.js' );
importScript( 'User:Writ_Keeper/Scripts/massRollback.js' ); // Linkback: [[User:Writ_Keeper/Scripts/massRollback.js]] - Selecting the "rollback all" tab when viewing a user's contributions history will open all rollback links displayed there. (Use with caution)
importScript( 'User:Gary/comments in local time.js' );	// Linkback: [[User:Gary/comments in local time.js]] - Display comments in my local time based on timezone setting https://en.wikipedia.org/wiki/Wikipedia:Comments_in_Local_Time
importScript( 'User:Enterprisey/massblock.js' );
importScript( 'User:Writ Keeper/Scripts/massRevdel.js' ); // Linkback: [[User:Writ Keeper/Scripts/massRevdel.js]] - Allow for deletion of multiple revisions at once
importScript( 'User:Writ Keeper/Scripts/orangeBar.js' ); // Linkback: [[User:Writ Keeper/Scripts/orangeBar.js]] - a nice orange bar when you have talk page notifications
//importScript('User:Anomie/useridentifier.js'); // Linkback: [[User:Anomie/useridentifier.js]] Not sure what this one does....
//importScript('User:NuclearWarfare/Mark-blocked script.js'); // Linkback: [[User:NuclearWarfare/Mark-blocked script.js]] - Used to clearly ID currently blocked users by striking their username. Super useful script and my #1 recommendation to anyone reading this.
importScript('User:Stwalkerster/grouphighlight.js'); // Linkback: [[User:Stwalkerster/grouphighlight.js]] - Works in tandem with my CSS to identify administrators, bureaucrats, stewards, and arbcom
importScript( 'User:Headbomb/unreliable.js' ); // Backlink: [[User:Headbomb/unreliable.js]]
importScript( 'User:Shubinator/DYKcheck.js' );
importScript('User:Mr. Stradivarius/gadgets/SpamUserPage.js'); // Linkback: [[User:Mr. Stradivarius/gadgets/SpamUserPage.js]]
importScript('User:Ohconfucius/script/MOSNUM dates.js'); // [[User:Ohconfucius/script/MOSNUM dates.js]]
importScript('User:SD0001/RFUD-helper.js'); // [[User:SD0001/RFUD-helper.js]]