User:DivermanAU/common.js

/** * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor. * @see https://meta.wikimedia.org/wiki/TemplateScript * @update-token */ // $.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 ' ';		}); }	function tag_pages_section(editor) { editor.replaceSelection(function(pre) {			//return '';			return ' ';		}); }	function defsortsubpage(editor) { editor.append(''); }	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(/ +/g, ' ') // remove trailing whitespace at the end of page text .replace(/\s+$/g, '') // remove trailing spaces at the end of refs .replace(/ +<\/ref>/g, ' ') // 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 tag: if (!editor.contains(' ')) { 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') // to 			.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}}'); } }); //