User:Vozul/common.js
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.
Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the central discussion page, Scriptorium. The code will be executed when previewing this page under some skins, including Monobook. You can in the interim if you wish to refresh the content sooner under another skin. |
The accompanying .css page for this skin is at User:Vozul/common.css. |
/**
* 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() {
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(/—/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 '<sup>{{sm|'+selected+'}}</sup>';
});
}
// </nowiki>