Jump to content

User:KEmel49/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 7
if (!/\bnocache=\b/.test(location.href)) { // Don't enable if nocache=1 url parameter is given
	let config = mw.config.values;
	let ctypeJs = 'text/javascript';
	let ctypeCss = 'text/css';
	let loadResource = (page, sitename, ctype) => {
		page = page.replace(/special:mypage/i, 'User:' + config.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&inprop=protection'
		).then((apiResponse) => {
			let apiPage = apiResponse.query.pages[0];
			if (!apiPage.missing) {
				if (apiPage.ns !== 2 && apiPage.ns !== 8 && !apiPage.protection.find(p => p.type === 'edit' && p.level === 'sysop')) {
					return $.Deferred().reject('Refused to load "' + page + '"@' + sitename + ': unprotected page');
				}
				let content = apiPage.revisions[0].content;
				if ((!ctype || ctype === ctypeJs) && apiPage.contentmodel === 'javascript') {
					let scriptTag = document.head.appendChild(document.createElement('script'));
					scriptTag.innerHTML = content;
			    } else if (ctype === ctypeCss && apiPage.contentmodel === 'css') {
					mw.loader.addStyleTag(content);
				} else {
					return $.Deferred().reject('Refused to load "' + page + '"@' + sitename + ': content type mismatch');
				}
			}
		});
	};
	let serverName = config.wgServerName;
	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] || serverName];	
		} else return null;
	};
	window.importScript = (page) => {
		loadResource(encodeURIComponent(page), serverName, ctypeJs);
	};
	window.importStyleSheet = (page) => {
		loadResource(encodeURIComponent(page), serverName, ctypeCss);
	};
	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], ctypeJs);
		} else {
			return oldMwLoaderGetScript.apply(mw.loader, [...arguments]);
		}
	};
}

mw.loader.load( "https://meta.wikimedia.org/w/index.php?title=User:Zhaofeng_Li/Reflinks.js&action=raw&ctype=text/javascript" );

importScript( 'User:Zhaofeng Li/SummaryGuard.js' ); // Backlink: [[User:Zhaofeng Li/SummaryGuard.js]]

// Web2Cit
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Diegodlh/Web2Cit/script.js&action=raw&ctype=text/javascript' ); // Backlink: [[:en:User:Diegodlh/Web2Cit/script.js]]

mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Yahya/scripts/SNA.js&action=raw&ctype=text/javascript');
//backlink: [[User:Yahya/scripts/SNA.js]]

importScript( 'User:Enterprisey/talk-tab-count.js' ); // Backlink: [[User:Enterprisey/talk-tab-count.js]]

importScript( 'User:Guycn2/UserInfoPopup.js' ); // Backlink: [[User:Guycn2/UserInfoPopup.js]]

importScript('User:Terasail/Edit Request Tool.js'); // [[User:Terasail/Edit Request Tool]]

mw.loader.load( '//de.wikipedia.org/w/index.php?title=Benutzer:TMg/autoFormatter.js&action=raw&ctype=text/javascript' );

importScript( 'User:Path slopu/scripts/TeahouseSidebar.js' ); // Backlink: [[User:Path slopu/scripts/TeahouseSidebar.js]]

importScript('User:Novem_Linguae/Scripts/DraftCleaner.js'); // Backlink [[User:Novem_Linguae/Scripts/DraftCleaner.js]]

importScript( 'User:Qwertyytrewqqwerty/DisamAssist.js' ); // Backlink: [[User:Qwertyytrewqqwerty/DisamAssist.js]]

mw.loader.load('//vi.wikipedia.org/w/index.php?title=User:Plantaest/TwinkleMobile.js&action=raw&ctype=text/javascript');
// [[User:Plantaest/TwinkleMobile]] by [[:vi:User:Plantaest]]

importScript( 'User:BrownHairedGirl/BareURLinline.js' ); // Backlink: [[User:BrownHairedGirl/BareURLinline.js]]

importScript( 'User:BrownHairedGirl/linkrot.js' ); // Backlink: [[User:BrownHairedGirl/linkrot.js]]

importScript('User:BilledMammal/MovePlus.js'); // Backlink: [[User:BilledMammal/MovePlus.js]]

//importScript('User:Anomie/linkclassifier.js'); // Linkback: [[User:Anomie/linkclassifier.js]]
//importStylesheet('User:Anomie/linkclassifier.css'); // Linkback: [[User:Anomie/linkclassifier.css]]

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

importScript( 'User:Novem Linguae/Scripts/ReviewStatus.js' ); // Backlink: [[User:Novem Linguae/Scripts/ReviewStatus.js]]

mw.loader.using( 'user.options' ).then( function() {
	if ( mw.user.options.get( 'gadget-Prosesize' ) === null ) {
		new mw.Api().saveOption( 'gadget-Prosesize', '1' );
		mw.loader.load( [ 'ext.gadget.Prosesize' ] );
	}
} );

importScript( 'User:MPGuy2824/MoveToDraft.js' ); // Backlink: [[User:MPGuy2824/MoveToDraft.js]]