Jump to content

User:Paper9oll/FormatterTagger.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.
// <nowiki>
mw.config.set('userjs-templatescript', { regexEditor: false });
$.ajax("//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js", { dataType: "script", cache: true }).then(function () {
	pathoschild.TemplateScript.add([
		{
			name: 'Formatter/Tagger',
			tooltip: 'Formatting and tagging unreliable sources',
			script: function (editor) {
				runFunction(editor, 'all');
			}
		},
		{
			name: 'Tagger',
			tooltip: 'Tagging unreliable sources',
			script: function (editor) {
				runFunction(editor, 'tagger');
			}
		},
		{
			name: 'Settings',
			tooltip: 'Settings',
			script: function () {
				runSettings();
			}
		}
	],
		{
			category: 'Paper9ollScripts',
			forActions: 'edit',
			forNamespaces: [0, 2, 118]
		});
});

function loadScript(callback) {
	if (mw.config.get('wgDBname') === 'enwiki') {
		var script = document.createElement('script');
		script.type = 'text/javascript';
		var url = '//en.wikipedia.org/w/index.php?title=User:Paper9oll/FormatterTagger-core.js&action=raw&ctype=text/javascript';
		var cacheBuster = 'cache=' + Date.now();
		url += (url.indexOf('?') === -1 ? '?' : '&') + cacheBuster;
		script.src = url;
		script.onload = callback;
		document.head.appendChild(script);
	}
}

function runSettings() {
	loadScript(function () {
		init.checkVersion();
		settings.settings();
	});
}

function runFunction(editor, type) {
	loadScript(function () {
		init.checkVersion();
		warning.user(editor);
		warning.usageWarning().then(function () {
			if (type !== 'tagger') {
				logger.clear();
				hatnotes.hatnotes(editor);
				typography.typography(editor);
				infobox.infobox(editor);
				wikitable.wikitable(editor);
				template.template(editor);
				efn.format(editor);
				cite.cite(editor);
			}
			if (type === 'tagger' || type === 'all') {
				unreliableSource.KO(editor);
				unreliableSource.RSP(editor);
			}
			if (type === 'all') {
				editSummary.auto(editor);
			}
			else if (type === 'tagger') {
				editSummary.tagger(editor);
			}
		});
	});
}
// </nowiki>