Jump to content

User:SD0001/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SD0001 (talk | contribs) at 14:56, 2 August 2021 (localtime comments provided by CD now). 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.
/* jshint maxerr: 999 */
mw.loader.load('http://localhost:5500');
	
// Enable caching for resource loads, see [[User:SD0001/Making_user_scripts_load_faster]], @revision 3
if(!/\bnocache=\b/.test(location.href)){var e=function(e,t,r){return e=e.replace(/special:mypage/i,"User:"+mw.config.get("wgUserName")),$.get("https://"+t+"/w/api.php?titles="+encodeURIComponent(e)+"&origin=*&format=json&formatversion=2&uselang=content&maxage=86400&smaxage=86400&action=query&prop=revisions|info&rvprop=content&rvlimit=1").then((function(n){var a=n.query.pages[0];if(!a.missing){var o=a.revisions[0].content;if(r&&"text/javascript"!==r||"javascript"!==a.contentmodel){if("text/css"!==r||"css"!==a.contentmodel)return $.Deferred().reject('Refused to load "'+e+'"@'+t+": content type mismatch");mw.loader.addStyleTag(o)}else{var i=document.createElement("script");i.innerHTML=o,document.head.appendChild(i)}}}))},t=function(e){var t=/^(?:(?:https:)?\/\/(.*))?\/w\/index.php/.exec(e),r=/\btitle=([^=?&]*)/.exec(e);return t&&r&&/\baction=raw\b/.test(e)&&/\bctype=/.test(e)?[r[1],t[1]||mw.config.get("wgServerName")]:null};window.importScript=function(t){e(t,mw.config.get("wgServerName"),"text/javascript")},window.importStyleSheet=function(t){e(t,mw.config.get("wgServerName"),"text/css")};var r=mw.loader.load;mw.loader.load=function(n,a){var o=t(n);o?e(o[0],o[1],a):r.apply(mw.loader,Array.prototype.slice.call(arguments))};var n=mw.loader.getScript;mw.loader.getScript=function(r){var a=t(r);return a?e(a[0],a[1],"text/javascript"):n.apply(mw.loader,Array.prototype.slice.call(arguments))}}


window.msg = function(msg, p1,p2,p3,p4,p5,p6,p7) {
	new mw.Api().loadMessagesIfMissing([msg]).then(function() { console.log(mw.msg(msg, p1,p2,p3,p4,p5,p6,p7)) });
};

$.ready.then(function() {
	// When redirected to a section, show the "Redirected from" text at the top of the section too, and add section name at the top
	if( $('.mw-redirectedfrom')[0] && window.location.hash ) {
		var hash = window.location.hash, sectionName = hash.slice(1).replace(/_/g, ' ');
		var redirectedFromSpan = $('.mw-redirectedfrom')[0];
		$('#' + $.escapeSelector(hash.slice(1))).parent().after(
			$(redirectedFromSpan).clone().attr('id', 'contentSub2')
		);
        redirectedFromSpan.innerHTML = redirectedFromSpan.innerHTML
        	.replace(/\)$/, ' to section <a href="' + hash + '">' + decodeURIComponent(sectionName) + '</a>)');
	}
	
	if (mw.config.get('skin') === 'vector') {
		
		// Add link to common.js in #p-personal
		$('#p-personal ul li:nth-child(5)').after('<li><a href="/wiki/User:SD0001/common.js">Scripts</a></li>');
		
		// Make the subject page button not follow the redirect
		if ($("#p-namespaces a")[0].className.includes('mw-redirect')) {
			$("#p-namespaces a")[0].href += '?redirect=no';
		}
	}
	
	importScript('User:SD0001/skin-pref.js');


	// reduce font size of code on mobile
	// disable syntax highlightening of large code blocks as it causes mobile browser to crash 
	if (/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
		mw.loader.addStyleTag('.mw-highlight pre { font-size: 70%; }');
		$('pre').each(function() {
			if (this.childElementCount > 2000) {
				this.textContent = this.textContent;
		    }
		});
	}
	
	var expansions = {
        "wp:afd": "WP:Articles for deletion",
        "wp:tfd": "WP:Templates for discussion/Log",
        "wp:cfd": "WP:Categories for discussion/Log",
        "wp:rfd": "WP:Redirects for discussion/Log",
        "wp:ffd": "WP:Files for discussion/Log",
        "wp:mfd": "WP:Miscellany for deletion",
        "wp:drv": "WP:Deletion review",
        "wp:mrv": "WP:Move review",
        "template:dykn": "Template:Did you know nominations", // t: expands to template:
        "wp:pr": "WP:Peer review",
        "wp:gar": "WP:Good article reassessment",
        "wp:fac": "WP:Featured article candidates",
        "wp:rfa": "WP:Requests for adminship",
        "wp:rfb": "WP:Requests for bureaucratship",
        "wp:rfc": "WP:Requests for comment",
        "wp:brfa": "WP:Bots/Requests for approval",

        // namespaces
        "t": "Template",
        "c": "Category"
    };
    
    // ripped off from [[User:Enterprisey/search-shortcuts]]
    $( "#searchInput" ).on( "keydown", function( event ) {
        if( event.key === "/" || event.key === ":" ) {
            var val = $( this ).val().toLowerCase();
            if( expansions[val] ) {
                $( this ).val( expansions[val] );
            }
        }
    } );

});

// Comments in local time
window.LocalComments = {
    dateDifference: false,
    dateFormat: 'dmy',
    dayOfWeek: false,
    dropDays: 0,
    dropMonths: 0,
    timeFirst: true,
    twentyFourHours: false
};

// script-installer
window.sciNoConfirm = true;

// pop-ups
window.popupFixDabs = true;
window.popupDabsAutoClick = 'wpPreview';

// MoreMenu
mw.hook('moremenu.ready').add(function (config) {
    MoreMenu.addLink(
        'page',
        'ORES',
        'https://ores.wikimedia.org/scores/enwiki/?models=articlequality|articletopic|draftquality|drafttopic&revids=' + mw.config.get('wgRevisionId')
    );
});

mw.loader.using('mediawiki.util').then(function() {
	if (mw.util.getParamValue('action') === 'history') {
		importScript('User:Ale_jrb/Scripts/userhist.js');  // [[User:Ale_jrb/Scripts/userhist.js]]
		importScript('User:SD0001/hide-reverted-edits.js'); // Backlink: [[User:SD0001/hide-reverted-edits.js]]
		$(mw.util.addPortletLink('p-cactions', '#', 'YR HV')).click(function(e) {
			e.preventDefault();
			importScript('User:Yair_rand/HistoryView.js');
		});
	} else if (mw.util.getParamValue('diff') || mw.config.get('wgPageName') === 'Special:ComparePages') {
		importScript('User:Enterprisey/diff-permalink.js'); // [[User:Enterprisey/diff-permalink.js]] 
		importScript('User:Evad37/TextDiff.js'); // [[User:Evad37/TextDiff.js]]
	}	
});

if (mw.config.get('wgNamespaceNumber') === 0) {
	importScript('User:Titodutta/scripts/SearchHelper.js'); // Backlink: [[User:Titodutta/scripts/SearchHelper.js]]
	// also imported below for draftspace
	importScript('User:Headbomb/unreliable.js'); // [[User:SD0001/unreliable.js]], [[User:Headbomb/unlreliable.js]]
} else if (mw.config.get('wgNamespaceNumber') % 2 === 1 || mw.config.get('wgCanonicalNamespace') === 'Project') {
	// importScript('User:DannyS712/DiscussionCloser.js'); // Backlink: [[User:Abelmoschus Esculentus/DiscussionCloser.js]], [[User:DannyS712/DiscussionCloser.js]]
	importScript('User:Technical 13/Scripts/OneClickArchiver.js'); // [[User:Technical 13/Scripts/OneClickArchiver.js]] 
	importScript('User:Jackmcbarn/editProtectedHelper.js'); // [[User:Jackmcbarn/editProtectedHelper.js]]
	
	if (mw.config.get('wgCanonicalNamespace') === 'Project') {
		if (mw.config.get('wgPageName').indexOf('Wikipedia:Articles_for_deletion') === 0) {
			importScript('User:SD0001/afd-edits-since-nomination.js'); // Backlink: [[User:SD0001/afd-edits-since-nomination.js]]
		} else if (mw.config.get('wgPageName').indexOf('Wikipedia:Requested_articles') === 0) {
			importScript('User:Enterprisey/req-helper.js'); // [[User:Enterprisey/req-helper.js]]
		} else if (mw.config.get('wgPageName') === 'Wikipedia:Bots/Requests_for_approval/request') {
			importScript('User:Enterprisey/easy-brfa.js'); // [[User:Enterprisey/easy-brfa.js]]
		} else if (mw.config.get('wgPageName') === 'Wikipedia:AutoWikiBrowser/Script') {
			importScript('User:Joeytje50/JWB.js/load.js'); // [[User:Joeytje50/JWB.js/load.js]]
		}
	}
} else if ( ['Template', 'Module'].indexOf(mw.config.get("wgCanonicalNamespace")) !== -1 ) {
	importScript('User:Enterprisey/sync-template-sandbox.js'); // [[User:Enterprisey/sync-template-sandbox.js]] 
	importScript('User:SD0001/sandbox4.js'); // [[User:Jackmcbarn/advancedtemplatesandbox.js]], [[User:SD0001/sandbox4.js]]
} else if (mw.config.get('wgCanonicalNamespace') === 'Draft') {
	importScript('User:SD0001/draft-sort-burst.js'); // [[User:SD0001/draft-sort-burst.js]]
	draft_sort_burst_watchlistOption = 'watch';
	importScript('User:SD0001/edits-since-decline.js'); // Backlink: [[User:SD0001/edits-since-decline.js]]
	importScript('User:Headbomb/unreliable.js'); // also imported for mainspace
} else if (mw.config.get('wgCanonicalNamespace') === 'Category') {
	importScript('User:קיפודנחש/cat-a-lot.js'); // Backlink: [[User:קיפודנחש/cat-a-lot.js]]
	importScript('User:SD0001/shortdescs-in-category.js'); // Backlink: [[User:SD0001/shortdescs-in-category.js]]
	importScript('User:Nardog/CatChangesViewer.js'); // Backlink: [[User:Nardog/CatChangesViewer.js]]
} else if (mw.config.get('wgCanonicalNamespace') === 'Special') {
	if (mw.config.get('wgCanonicalSpecialPageName') === 'Whatlinkshere') {
		mw.loader.load('//www.wikidata.org/w/index.php?title=MediaWiki:Linkscount.js&action=raw&ctype=text/javascript'); // [[wikidata:MediaWiki:Linkscount.js]]
	} else if (mw.config.get('wgPageName') === 'Special:RecentChanges') {
		importScript('User:SD0001/RC-links-new-tab.js'); // Backlink: [[User:SD0001/RC-links-new-tab.js]]
	} else if (mw.config.get('wgCanonicalSpecialPageName') === 'Log') {
		importScript('User:Amorymeltzer/logSwap.js'); // Backlink: [[User:Amorymeltzer/logSwap.js]]
	} else if (mw.config.get('wgPageName') === 'Special:PrivateSandbox') {
		importScript('User:SD0001/private-sandbox.js'); // Backlink: [[User:SD0001/private-sandbox.js]]
	}
} else if (mw.config.get('wgPageName') === 'MediaWiki:Gadgets-definition') {
	mw.loader.load('//en.wiktionary.org/w/index.php?title=User:Erutuon/scripts/gadgets-definition.js&action=raw&ctype=text/javascript'); // [[wikt:User:Erutuon/scripts/gadgets-definition.js]]
}
	
var codePage = ['javascript', 'json', 'css', 'sanitized-css', 'Scribunto'].includes(mw.config.get('wgPageContentModel'));
var templatePage = mw.config.get('wgCanonicalNamespace') === 'Template' && !mw.config.get('wgPageName').endsWith('/doc');
if (codePage || templatePage) {
	$.ready.then(function() {
		$('#mw-script-doc .mbox-text').append(" Install using <code>importScript('"+mw.config.get('wgPageName').replace(/_/g, ' ')+"');</code>");
	});
	importScript( 'User:Danski454/codeEditWindowSize.js' ); // Backlink: [[User:Danski454/codeEditWindowSize.js]]
	window.codeEditorHeight = 661;
	importScript('User:Nardog/CodeEditorAssist.js'); // Backlink: [[User:Nardog/CodeEditorAssist.js]]
	mw.loader.load('//en.wiktionary.org/w/index.php?title=MediaWiki:Gadget-CodeLinks.js&action=raw&ctype=text/javascript'); // [[wikt:MediaWiki:Gadget-CodeLinks.js]]
}
	
importScript('User:Ale_jrb/Scripts/csdhelper.js');   // [[User:Ale_jrb/Scripts/csdhelper.js]]
importScript('User:Enterprisey/undo-last-edit.js'); // [[User:Enterprisey/undo-last-edit.js]] 
importScript('User:SD0001/deleted-metadata-link.js'); // [[User:SD0001/deleted-metadata-link.js]]
importScript('User:SD0001/np-shortcuts.js'); // [[User:SD0001/np-shortcuts.js]]
importScript('User:Evad37/rater.js'); // [[User:Evad37/rater.js]]
importScript('User:SD0001/DYK-helper.js'); // Backlink: [[User:SD0001/DYK-helper.js]]
importScript('User:SD0001/StubSorter.js'); // Backlink: [[User:SD0001/StubSorter.js]]
importScript('User:SD0001/W-Ping.js'); // Backlink: [[User:SD0001/W-Ping.js]]
// importScript('User:SD0001/easy-merge.js'); // Backlink: [[User:SD0001/easy-merge.js]]
importScript('User:SD0001/QuickEdit.js'); // Backlink: [[User:BrandonXLF/QuickEdit.js]]
// importScript('User:Awesome Aasim/xfdvote.js'); // Backlink: [[User:Awesome Aasim/xfdvote.js]]
importScript('User:SD0001/GAN-helper.js'); // Backlink: [[User:SD0001/GAN-helper.js]]

importScript('User:Jack who built the house/convenientDiscussions.js'); // [[commons:User:Jack who built the house/Convenient Discussions]]
importScript('User:SD0001/dark-mode-toggle.js'); // Backlink: [[User:SD0001/dark-mode-toggle.js]]