User:Liangent/Scripts/FilePrefix.js

维基百科,自由的百科全书

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

if (wgAction == "edit") {
    addOnloadHook(function() {
        var choice = document.createDocumentFragment();
        var choiceCheck = document.createElement('input');
        var choiceLabel = document.createElement('label');
        choiceCheck.setAttribute('type', 'checkbox');
        choiceCheck.setAttribute('value', '1');
        choiceCheck.setAttribute('id', 'dontConvertImage');
        choiceLabel.setAttribute('for', 'dontConvertImage');
        choiceLabel.setAttribute('title', '不要把文件前缀转换为 [[File:');
        choiceLabel.appendChild(document.createTextNode('不转换为 [[File:'));
        choice.appendChild(choiceCheck);
        choice.appendChild(document.createTextNode(' '));
        choice.appendChild(choiceLabel);
        choice.appendChild(document.createTextNode('\n'));
        $('#wpMinoredit')[0].parentNode.insertBefore(choice, $('wpMinoredit'));
        addHandler($('#editform')[0], 'submit', function(e) {
            if ($('#dontConvertImage')[0].checked) return true;
            var textBox = $('#wpTextbox1')[0];
            textBox.value = textBox.value.replace(/\[\[\s*(:?)\s*Image\s*:/gi, '[[$1File:');
            return true;
        });
    });
}