Jump to content

User:Quarl/autocloseafd.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// requires: wikipage.js, wikipageafd.js, wikiedit.js, addlilink.js

// enhanced by: advanced_signature.js

// quarl 2006-01-04 initial version

// TODO: shortcuts; factor out afd_helper generic shortcuts code

//<pre><nowiki>

function autocloseafd_load() {
    if (window.afdP || wikiPage.sandboxP) {
        addTab('javascript:autoclose_query(wikiPage)', 'close', 'ca-autoclose', "Close this AFD discussion");
    }
}

// TODO: shortcuts
function autoclose_query(wp) {
    autoclose(wp, window.prompt("Enter closing comment.  Example: '''Delete''' as non-notable band."));
}

function autoclose(wp, comment) {
    wp.getEditorAsync(autoclose_edit, comment);
}

function autoclose_edit(editor, comment) {
    if (!comment) return;
    var add_before = "{{subst:afd top}} " + comment + " " + makeSignature() + "\n\n";
    var add_after = "\n\n{{subst:afd bottom}}\n";
    var summary = 'AFD closed; result: ' + comment;

    editor.wpTextbox1 = add_before + trim_lines(editor.wpTextbox1) + add_after;
    editor.wpSummary = summary;
    editor.submit();
}

$(autocloseafd_load);

//</nowiki></pre>