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
 * @update-token [[File:pathoschild/templatescript.js]]
 */
// <nowiki>
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	/*********
	** Register scripts
	*********/
	pathoschild.TemplateScript.add([
		// all namespace
		//{ name: '{{rh}}', script: RunningHeader },
		{ name: 'clean up', script: cleanup },
		{ name: 'nop', script: nop },
		{ name: 'DefSort Subpage', script: defsortsubpage },
	
		// main namespace
		{ name: 'pn [[//]]', script: PrevNext1, forNamespaces: 0 },
		{ name: 'Pages', script: tag_pages, forNamespaces: 0 },
		{ name: 'Pages++', script: tag_pages_section, forNamespaces: 0 }
	]);
// create a user defined object
var myLintHints = { };

// specify some object component
myLintHints.rooms = "*";

// communicate user defined object
mw.hook( "lintHint.config" ).fire( myLintHints );

// finally, load gadget
mw.loader.load( "https://en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/lintHint/r.js&action=raw&bcache=1&maxage=86400&ctype=text/javascript" );

	/*********
	** Define scripts
	*********/
	function PrevNext1(editor) {
		var prevnextlink = '[[..//]]';
		editor.replace(/\| previous   \= \n \| next       \= /, '| previous   \= ' + prevnextlink + '\n \| next       \= ' + prevnextlink);
	}
	
	//subst: #tag and some fields
	function tag_pages(editor) {
		editor.replaceSelection(function(pre) {
			return '<pages index="Diverman.djvu" from="" to=""></pages>';
		});
	}
	
	function tag_pages_section(editor) {
		editor.replaceSelection(function(pre) {
			//return '{{subst'+':#tag:pages||index="{{subst'+':BASEPAGENAME}}.djvu" from= to= fromsection="{{subst'+':SUBPAGENAME}}" tosection="{{subst'+':SUBPAGENAME}}"}}';
			return '<pages index="Diverman.djvu" from="" to="" fromsection="common.js" tosection="common.js"></pages>';
		});
	}
	
	function defsortsubpage(editor) {
		editor.append('{{DEFAULTSORT:{{subst:SUBPAGENAME}}}}');
	}
	
	function cleanup(editor) {
		var headerbox = editor.forField('#wpHeaderTextbox');
		var footerbox = editor.forField('#wpFooterTextbox');
	
		editor
			// Digitized by Google (kill)
			.replace(/Digitized[\s\n]+by[^\n]+\n(Google)?/, '')
		
			// remove trailing spaces at the end of each line
			.replace(/ +\n/g, '\n')
		
			// remove trailing whitespace preceding a hard line break
			.replace(/ +<br *\/?>/g, '<br />')
		
			// remove trailing whitespace at the end of page text
			.replace(/\s+$/g, '')
		
			// remove trailing spaces at the end of refs
			.replace(/ +<\/ref>/g, '</ref>')
		
			// remove trailing spaces at the end of template calls
			.replace(/ +}}/g, '}}')
		
			// convert double-hyphen to mdash (avoiding breaking HTML comment syntax)
			.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).
			.replace(/ +— +/g, '—')
		
			// join words that are hyphenated across a line break
			// (but leave "|-" table syntax alone)
			.replace(/([^\|])-\n/g, '$1');
	
		// stuff to do only if the page doesn't contain a <poem> tag:
		if (!editor.contains('<poem>')) {
			editor
				// remove single line breaks; preserve multiple.
				// but not if there's a tag, template or table syntax either side of the line break
				.replace(/([^(>||#)}\n])\n([^<{\|\n])/g, '$1 $2')
		
				// collapse sequences of spaces into a single space
				.replace(/  +/g, ' ');
		}
		
		editor
			// remove unwanted spaces around punctuation marks
			.replace(/ ([;:\?!,])/g, '$1')
		
			//OCR fixes
			// convert i9 to 19, etc.
			//.replace(/[il]([0-9])/g, '1$1')
		
			// " the", " them", " their", etcetera
			.replace(/ tlie/g, ' the')
		
			// "U" -> "ll" when preceded by a lowercase letter.
			.replace(/([a-z])U/g, '$1ll')
		
			// {{c}} to {{center}}
			.replace(/{{c\|/g, '{{center|');
			
		headerbox.replace(/{{c\|/g, '{{center|');
		footerbox.replace(/{{c\|/g, '{{center|');
	
		// {{rh}} to {{RunningHeader}}
		headerbox.replace(/{{rh\|/gi, '{{RunningHeader|');
		
		editor
			//{{hws}} & {{hwe}} expanded
			.replace(/{{hws\|/g, '{{hyphenated word start|')
			.replace(/{{hwe\|/g, '{{hyphenated word end|')
		
			// expand diacritical templates
			.replace(/{{((ae|oe|\w[:`'~^-]))}}/g, '{{subst' + ':$1}}');
	}
	//end of cleanup
	
	// nop at bottom of editbox
	function nop(editor) {
		editor.append('\n{{nop}}');
	}
});
// </nowiki>