Jump to content

User:DrowssapSMM/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.
// Enable caching for resource loads, see [[User:SD0001/Making_user_scripts_load_faster]], @revision 6
if (!/\bnocache=\b/.test(location.href)) { // Don't enable if nocache=1 url parameter is given
	let loadResource = (page, sitename, ctype) => {
		page = page.replace(/special:mypage/i, 'User:' + mw.config.get('wgUserName'));
		return $.get(
			'https://' + sitename + '/w/api.php?titles=' + page + // page is already URL-encoded
			'&origin=*&format=json&formatversion=2&uselang=content&maxage=86400&smaxage=86400' + 
			'&action=query&prop=revisions|info&rvprop=content&rvlimit=1'
		).then((apiResponse) => {
			let apiPage = apiResponse.query.pages[0];
			if (apiPage.missing) {
				return;
			}
			let content = apiPage.revisions[0].content;
			if ((!ctype || ctype === 'text/javascript') && apiPage.contentmodel === 'javascript') {
				let 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');
			}
		});
	};
	let getSiteTitle = (url) => {
		let 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 = (page) => {
		loadResource(encodeURIComponent(page), mw.config.get('wgServerName'), 'text/javascript');
	};
	window.importStyleSheet = (page) => {
		loadResource(encodeURIComponent(page), mw.config.get('wgServerName'), 'text/css');
	};
	let oldMwLoaderLoad = mw.loader.load;
	mw.loader.load = function(url, type) {
		let linkParts = getSiteTitle(url);
		if (linkParts) {
			loadResource(linkParts[0], linkParts[1], type);
		} else {
			oldMwLoaderLoad.apply(mw.loader, [...arguments]);
		}
	};
	let oldMwLoaderGetScript = mw.loader.getScript;
	mw.loader.getScript = function(url) {
		let linkParts = getSiteTitle(url);
		if (linkParts) {
			return loadResource(linkParts[0], linkParts[1], 'text/javascript');
		} else {
			return oldMwLoaderGetScript.apply(mw.loader, [...arguments]);
		}
	};
}
importScript('User:Novem Linguae/Scripts/CiteHighlighter.js'); // Backlink: [[User:Novem Linguae/Scripts/CiteHighlighter.js]]
importScript('User:Ingenuity/AntiVandal.js'); // Backlink: [[User:Ingenuity/AntiVandal.js]]
importScript('User:10nm/beta.js'); // Backlink: [[User:10nm/beta.js]]
importScript('User:SD0001/GAN-helper.js'); // Backlink: [[User:SD0001/GAN-helper.js]]
importScript('User:Headbomb/unreliable.js'); // Backlink: [[User:Headbomb/unreliable.js]]
importScript('User:Schminnte/PageCuration.js'); // Backlink: [[User:Schminnte/PageCuration.js]]
importScript('User:Evad37/EditWarChecker.js'); // Backlink: [[User:Evad37/EditWarChecker.js]]
importScript('User:Awesome_Aasim/xfdvote.js'); // Backlink: [[User:Awesome_Aasim/xfdvote.js]]
importScript('User:Awesome_Aasim/redirectcreator.js'); // Backlink: [[User:Awesome_Aasim/redirectcreator.js]]
importScript('User:Qwertyytrewqqwerty/DisamAssist.js'); // Backlink: [[User:Qwertyytrewqqwerty/DisamAssist.js]]
importScript('User:Ohconfucius/script/Common_Terms.js'); // Backlink: [[User:Ohconfucius/script/Common_Terms.js]]
importScript('User:Kangaroopower/MRollback.js'); // Backlink: [[User:Kangaroopower/MRollback.js]]
importScript('User:Evad37/rater.js'); // Backlink: [[User:Evad37/rater.js]]
importScript('User:Danski454/hotcat-summary.js'); // Backlink: [[User:Danski454/hotcat-summary.js]]
importScript('User:MPGuy2824/MoveToDraft.js'); // Backlink: [[User:MPGuy2824/MoveToDraft.js]]
importScript('User:Mr._Stradivarius/gadgets/Draftify.js'); // Backlink: [[User:Mr._Stradivarius/gadgets/Draftify.js]]
importScript('User:Omni_Flames/PendingChangesLink.js'); // Backlink: [[User:Omni_Flames/PendingChangesLink.js]]
importScript('User:TheTVExpert/rmCloser.js'); // Backlink: [[User:TheTVExpert/rmCloser.js]]
importScript('User:DemonDays64/Scripts/Dumb_quotes.js'); // Backlink: [[User:DemonDays64/Scripts/Dumb_quotes.js]]
importScript('User:Ohconfucius/script/EngvarB.js'); // Backlink: [[User:Ohconfucius/script/EngvarB.js]]
importScript('User:Ohconfucius/script/MOSNUM_dates.js'); // Backlink: [[User:Ohconfucius/script/MOSNUM_dates.js]]
importScript('User:Awesome_Aasim/oneclickdelete.js'); // Backlink: [[User:Awesome_Aasim/oneclickdelete.js]]
importScript('User:SD0001/StubSorter.js'); // Backlink: [[User:SD0001/StubSorter.js]]
importScript('User:Joeytje50/JWB.js/load.js'); // Backlink: [[User:Joeytje50/JWB.js/load.js]]
importScript('User:Novem_Linguae/Scripts/GANReviewTool.js'); // Backlink: [[User:Novem_Linguae/Scripts/GANReviewTool.js]]
importScript('User:SD0001/GAR-helper.js'); // Backlink: [[User:SD0001/GAR-helper.js]]
importScript('User:Alexis_Jazz/Kill-It-With-Fire.js'); // Backlink: [[User:Alexis_Jazz/Kill-It-With-Fire.js]]
importScript('User:Wugapodes/Capricorn.js'); // Backlink: [[User:Wugapodes/Capricorn.js]]
importScript('User:Writ Keeper/Scripts/deletionFinder.js'); // Backlink: [[User:Writ Keeper/Scripts/deletionFinder.js]]
importScript('User:Þjarkur/Highlight homographs in title.js'); // Backlink: [[User:Þjarkur/Highlight homographs in title.js]]
importScript('User:Jackmcbarn/editProtectedHelper.js'); // Backlink: [[User:Jackmcbarn/editProtectedHelper.js]]
importScript('User:DannyS712/Draft_no_cat.js'); // Backlink: [[User:DannyS712/Draft_no_cat.js]]
importScript('User:Enterprisey/cv-revdel.js'); // Backlink: [[User:Enterprisey/cv-revdel.js]]
importScript('User:Ohconfucius/dashes.js'); // Backlink: [[User:Ohconfucius/dashes.js]]
importScript('User:Bradv/Scripts/Superlinks.js'); // Backlink: [[User:Bradv/Scripts/Superlinks.js]]
importScript('User:Eejit43/scripts/afcrc-helper.js'); // Backlink: [[User:Eejit43/scripts/afcrc-helper.js]]
importScript('User:Novem Linguae/Scripts/DraftCleaner.js'); // Backlink: [[User:Novem Linguae/Scripts/DraftCleaner.js]]
importScript('User:DannyS712/DiscussionCloser.js'); // Backlink: [[User:DannyS712/DiscussionCloser.js]]
importScript('User:Evad37/OneClickArchiver.js'); // Backlink: [[User:Evad37/OneClickArchiver.js]]
importScript('User:Aaron_Liu/MoveTop.js'); // Backlink: [[User:Aaron_Liu/MoveTop.js]]
importScript('User:CFA/scripts/attributetranslation.js'); // Backlink: [[User:CFA/scripts/attributetranslation.js]]
importScript('User:Lordseriouspig/StatusChangerImproved.js'); // Backlink: [[User:Lordseriouspig/StatusChangerImproved.js]]