User:Vozul/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 {	pathoschild.TemplateScript.add([ // add your own templates or scripts here { name: 'Simplify quotes', script: simplifyQuotes }, { name: 'Clean page', script: clean }, { name: 'Replace dashes', script: replaceDashes }, { name: 'Remove newlines', script: removeExtraNewlines }, { name: 'Small superscript', script: smallSuperscript }, ]); });

function simplifyQuotes(editor) { editor.replace(/[“”]/g, '"')		.replace(/[‘’]/g, '\'') ; }

function clean(editor) { editor.replace(/ ([;:\?!,])/g, '$1') // remove spaces around punctuation .replace(/[\t ]+\n/g, '\n') // remove trailing spaces at the end of each line .replace(/-\n/g,'') // join hypenated words accross line break .replace(/\s+$/, '') // remove trailing whitespace at the end of the page .replace(/(?<!\n)\n(?!\n)/g, ' ') // replace single newlines with spaces, leave 2+ newlines alone .replace(/[\t ]*"[\t ]*/g, '"'); // remove spaces around double quotes }

function replaceDashes(editor) { editor.replace(//g, '—') .replace(/&mdash;/g, '—') .replace(/–/g, '-') .replace(/--/g, '—'); }

function removeExtraNewlines(editor) { editor.replace(/(?<!\n)\n(?!\n)/g, ' '); // replace single newlines with spaces, leave 2+ newlines alone }

function smallSuperscript(editor) { editor.replaceSelection(function(selected) {		return 'undefined';	}); } //