사용자:용인 학생/massReplace.js

위키백과, 우리 모두의 백과사전.

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.

// <syntaxhighlight lang=javascript>
// Adds a "Replace" tab which pops up two prompt boxes; one for a regexp and one for a replacement
function wpTextboxMassReplace()
{
    var s = prompt("Search regexp:");
    var txt = document.editform.wpTextbox1;
    while (true) {
        if (!s) return;
        var s_r = new RegExp(s, "m");
        if (s_r.test(txt.value)) {
            var r = prompt("Replace /"+s+"/ with:");
            r = r.replace(/\\n/g,"\n"); // unescape newlines
            if (!r && r !== '') return;
            var count = prompt( "How many times do you want to run the regexp?" )
            if (!count && count !== '') return;
            for (var i = 0; i < count; i++) {
            	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:wpTextboxMassReplace()', 'Replace-mass', 'ca-massreplace',
                       'Regexp replace for the edit window', 'R', document.getElementById('ca-history'));
    }
});

// </syntaxhighlight>

//