User:Prosody/vector.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.

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 */
// <pre>
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add([
		{ name: 'Cleanup', script: cleanup, forActions: 'edit' },
		{ name: 'Blockify smaller', script: function(editor) { editor.replace(/\{\{smaller\|/g, '{{smaller block|').appendEditSummary('Replaced smaller with smaller block for consistency.').options({ 'minor': true }); if (editor.get().split(/\n/).slice(-1)[0].indexOf("{{smaller block|") == 0) { window.alert("Last item's a smaller block, make sure that's okay before submitting."); }}, forActions: 'edit' }
		// add your own templates or scripts here
	]);
});
// </pre>

//importScript('User:Prosody/pagelinker.js');
//stolen^H^H^H^H^H^H borrowed from User:Billinghurst/monobook.js
function cleanup() {
	var editbox = document.getElementsByName('wpTextbox1')[0];

	// Digitized by Google (kill)
	editbox.value = editbox.value.replace(/Digitized[\s\n]+by[\s\n]+Google/, '');

	// remove trailing spaces at the end of each line
	editbox.value = editbox.value.replace(/ +\n/g, '\n');

	// remove trailing whitespace preceding a hard line break
	editbox.value = editbox.value.replace(/ +<br *\/?>/g, '<br />');

	// remove trailing whitespace at the end of page text
	editbox.value = editbox.value.replace(/\s+$/g, '');

	// remove trailing spaces at the end of refs
	editbox.value = editbox.value.replace(/ +<\/ref>/g, '</ref>');

	// remove trailing spaces at the end of template calls
	editbox.value = editbox.value.replace(/ +}}/g, '}}');

	// convert double-hyphen to mdash (avoiding breaking HTML comment syntax)
	editbox.value = editbox.value.replace(/([^\!])--([^>])/g, '$1—$2');

	// remove spacing around mdash, but only if it has spaces on both sides
	// (we don't want to remove the trailing space from "...as follows:— ",
	// bearing in mind that the space will already be gone if at end of line).
	editbox.value = editbox.value.replace(/ +— +/g, '—');

	// join words that are hyphenated across a line break
	// (but leave "|-" table syntax alone)
	editbox.value = editbox.value.replace(/([^\|])-\n/g, '$1');
 
	// stuff to do only if the page doesn't contain a <poem> tag:
	if (-1 == editbox.value.indexOf("<poem>")) {
		// remove single line breaks; preserve multiple.
		// but not if there's a tag, template or table syntax either side of the line break
		editbox.value = editbox.value.replace(/([^>}\n])\n([^<{\|\n])/g, '$1 $2');
 
		// collapse sequences of spaces into a single space
		editbox.value = editbox.value.replace(/  +/g, ' ');
		}
 
	// remove unwanted spaces around punctuation marks
	editbox.value = editbox.value.replace(/ ([;:\?!,])/g, '$1');
 
 
	//OCR fixes
	// convert i9 to 19, etc.
	editbox.value = editbox.value.replace(/[il]([0-9])/g, '1$1');
 
	// "the", "them", "their", etcetera
	editbox.value = editbox.value.replace(/tlie/g, 'the');
 
	// "U" -> "ll" when preceded by a lowercase letter.
	editbox.value = editbox.value.replace(/([a-z])U/g, '$1ll');
	
	// kill curly quotes
	editbox.value = editbox.value.replace(/[“”]/g, "\"");
	editbox.value = editbox.value.replace(/[‘’]/g, "'");
}

$(document).ready(function() {
	if (wgNamespaceNumber === 104) {
		$.get("/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=Page:" + wgTitle, function (data) {
			var content = data.evaluate("//rev", data, null, XPathResult.ANY_TYPE, null).iterateNext().innerHTML;
			content = content.substring(0, content.lastIndexOf('&lt;noinclude&gt;'));
			if (content.substring(content.length - 7) == "{{nop}}") {
				$('.pagetext').append('<p style="border: 1px solid red; text-align: center;">Nooped</p>');
			}
		});
	}
	
	if (wgAction == "edit") {
		$("#mw-content-text > p > strong").each(function () {
    		if ($(this).text() == "Warning: You are editing an out-of-date revision of this page.") {
	        	$(this).css({ "font-size": "500%", "color": "red" });
    		}
		});
	}
});