User:Quarl/autocloseafd.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

// 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();
}
 
addOnloadHook(autocloseafd_load);
 
//</nowiki></pre>