User:Pathoschild/regex.js
// <pre>
/*************
*** Semi-auto regex replacement toolbar
*************/
if(wgAction=='edit' || wgAction=='submit') {
/* create toolbar */
function regexReplaceMenu() {
/* get elements */
// note: these must be global.
editbox = document.getElementById('wpTextbox1');
editreason = document.getElementById('wpSummary');
sidebar = document.getElementById('column-one');
/* create menu */
var container = document.createElement('div');
container.setAttribute('class','portlet');
container.setAttribute('id','p-regex');
sidebar.appendChild(container);
var header = document.createElement('h5');
header.appendChild(document.createTextNode('Templates'));
container.appendChild(header);
var toolbox = document.createElement('div');
toolbox.setAttribute('class','p-body');
container.appendChild(toolbox);
var toollist = document.createElement('ul');
toolbox.appendChild(toollist);
/* define menu items */
function regexTool(name,functionname) {
var newline = document.createElement('li');
newline.setAttribute('style','list-style:none !important;');
var newlink = document.createElement('a');
newlink.setAttribute('href','javascript:'+functionname);
newlink.setAttribute('title',name);
newlink.setAttribute('class','sidebar-link');
newlink.setAttribute('style','color:gray !important;'); // temporary hack, move to CSS later
newlink.appendChild(document.createTextNode(name));
newline.appendChild(newlink);
toollist.appendChild(newline);
}
/* create menu */
regexTool('Redirect to talk','redirtalk()');
regexTool('Block template cleanup','blockcleanup()');
}
/* simplify code */
function regex(search,replace) {
editbox.value = editbox.value.replace(search,replace);
}
function reason(reason,mode) {
if(mode=='append' && editreason.value.match(/[^\s]/)) {
editreason.value = editreason.value+', '+reason;
}
else {
editreason.value = reason;
}
}
/* define tools */
function redirtalk() {
// replace all with redirect
editbox.value = '#REDIRECT [[{{subst:TALKPAGENAME}}]]';
reason('Redirected to talk page');
}
function blockcleanup() {
/* remove template modifiers */
regex(/{{(?:msg:|template:)/ig,'{{');
/* fix redirects */
// indefblockeduser
regex(/{{(?:blockedindef|indef(?:block|blocked|blockuser|blockeduser-big|blockeduser-nocat|vandal)?|page(?:blank|move)vandal|vpblock)(?:\|[^\}]*)?}}/ig,'{{indefblockeduser}}');
// sockpuppeteer
regex(/{{puppetmaster/ig,'{{sockpuppeteer');
regex(/{{sockpuppeteerProven}}/ig,'{{sockpuppeteer|blocked}}');
// sockpuppets
regex(/{{blockedsock\|([^}]+)}}/ig,'{{sockpuppet|$1|2=blocked}}');
regex(/{{sockpuppet(?:proven|Block|Blocked)\|([^}]*)/ig,'{{sockpuppet|$1|2=blocked}}');
/* fix redundancy */
// multiple indefs (probably from redirect fixes)
regex(/{{indefblockeduser}}([\s\S]*){{indefblockeduser}}/ig,'{{indefblockeduser}}$1');
/* adjust edit summary */
reason('template cleanup','append');
}
/* load script */
addOnloadHook(regexReplaceMenu);
}
// </pre>
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.