User:Steven Crossin/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 namespaces { name: 'clean up', script: cleanup }, { name: 'Indent', script: Indent },

// page namespace { name: 'Header', script: RunningHeader, forNamespaces: 'page' }, { name: 'Footer', script: RunningFooter, forNamespaces: 'page' }, { name: 'nop', script: nop, forNamespaces: 'page' },

// user talk pages { name: 'welcome', script: welcome, forNamespaces: 'user talk' }, { name: 'welcomeip & test', script: weliptest, forNamespaces: 'user talk' }, { name: 'welcomeip', script: welcomeip, forNamespaces: 'user talk' }, { name: 'toggle in Page:', script: HeaderToggle, forNamespaces: 'user talk' } ]);

/*********	** Define scripts *********/	//USER TALK namespace /**	 * Apply. */	function welcome(editor) { editor .append(' ~') .appendEditSummary('welcome'); }

/**	 * Apply via. */	function weliptest(editor) { editor .append(' ~\n') .appendEditSummary('welcome & test'); }

/**	 * Add. */	function welcomeip(editor) { editor .append(' ~') .appendEditSummary('welcome'); }

/**	 * Add which tells how to toggle header in Page namespace. */	function HeaderToggle(editor) { editor.append(''); }

//ALL NAMESPACE USE /**	 * All sorts of text cleaning from OCR. */	function cleanup(editor) { editor // Digitized by Google (kill) .replace(/Digitized[\s\n]+by[\s\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.get.indexOf(" ") === -1) { 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'); }

/**	 * Add to the bottom of editbox. */	function nop(editor) { editor.append(''); }

//SPECIFIC TO Page: namespace /**	 * Add to the headerbox. */	function RunningHeader(editor) { editor.forField('#wpHeaderTextbox').append(''); }

/**	 * Footerbox app; for archaic books where the first word on the next page is placed at bottom. */	function RunningFooter(editor) { editor.forField('#wpFooterTextbox').replace(/(<\/div>)/, '$1'); }

//Indent function Indent(editor) { editor.forField('#wpHeaderTextbox').replace(//g, ' '); } }); //

importScript('User:Inductiveload/Roman numerals.js'); importScript('User:Inductiveload/Running header.js'); if (mw.toolbar) { $('#wpTextbox1').wikiEditor('addToToolbar', {		section: 'main',		group: 'format',		tools: {			'custom-hws': {				label: 'hws ',				type: 'button',				icon: ,				action: {					type: 'encapsulate',					options: {						pre: ,						sampleText: 					}				}			},			'custom-hwe': {				label: 'hwe ',				type: 'button',				icon: ,				action: {					type: 'encapsulate',					options: {						pre: ,						sampleText: 					}				}			}		}	}); }