Wikipedia:WikiProject User scripts/Scripts/Replace: Difference between revisions
Content deleted Content added
Waldyrious (talk | contribs) allow adding newlines in replacement |
change source to syntaxhighlight |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1:
// <
// Adds a "Replace" tab which pops up two prompt boxes; one for a regexp and one for a replacement
function wpTextboxReplace()
{
var s = prompt("Search regexp:");
while (true) {
if (!s) return;
r = r.split('\\n').join('\n'); // unescape newlines▼
if (s_r.test(txt.value)) {
▲ var txt = document.editform.wpTextbox1;
if (!r && r !== '') return;
txt.value = txt.value.replace(s_r, r);
return;
}
else {
var s_0 = s;
s = prompt("/" + s_0 + "/ did not match anything. You may enter a new regexp:");
}
}
}
addOnloadHook(function () {
if (document.forms.editform) {
mw.util.addPortletLink('p-cactions', 'javascript:wpTextboxReplace()', 'Replace', 'ca-replace',
'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));
}
});
// </
// [[Category:Wikipedia scripts]]
|