User:CalendulaAsteraceae/common.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

// Load jump to file
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Inductiveload/jump to file/load.js&action=raw&ctype=text/javascript');

/*
 * Add several tools useful when proofreading pages in the Page: namespace.
 * @see https://en.wikisource.org/wiki/Wikisource:TemplateScript
 */
// I'm not using this now but might want to in future
// mw.loader.load('//en.wikisource.org/w/index.php?title=MediaWiki:TemplateScript/proofreading.js&action=raw&ctype=text/javascript');

// First wait for mediawiki.util to load, and the page to be ready.
$.when(mw.loader.using('mediawiki.util'), $.ready).then(function () {
	const title = mw.config.get('wgPageName');
	
	// Add link to toolbar.
	mw.util.addPortletLink(
		'p-tb', /* portletId */
		'/wiki/Special:PrefixIndex/' + title, /* href */
		'Pages with prefix', /* text */
		't-prefixindex', /* id */
		'A list of all wiki pages with this prefix [⌃⌥i]', /* tooltip */
		'i' /* accesskey */
		/* '#t-recentchangeslinked' nextnode */
	);
	
	// Add warning banner to relevant pages.
	// [[User talk:CalendulaAsteraceae/Archive 7#nop]]
	var titleObject = new mw.Title(title);
	if (titleObject.getNamespacePrefix() == 'Page:') {
		var params = {
			action: 'query',
			prop: 'revisions',
			titles: title,
			rvlimit: 'max',
			rvprop: 'user',
			rvdir: 'newer',
			rvuser: 'EncycloPetey',
			rvslots: 'main',
			formatversion: '2',
			format: 'json'
		},
		api = new mw.Api();
	    api.get(params).done(function (data) {
	        var pageData = data.query.pages[0];
	        if ('revisions' in pageData) {
				var message = document.createElement('div');
				message.setAttribute('class', 'mw-message-box custom-warning-box');
				message.textContent = 'EncycloPetey has edited this page. Are you sure you want to remove that unnecessary {{nop}}?';
				$('.prp-page-content').prepend(message);
	        }
	    });
	}
});

// Load sandbox
// mw.loader.load('//en.wikisource.org/w/index.php?title=User:CalendulaAsteraceae/sandbox.js&action=raw&ctype=text/javascript');