User:Quarl/autocloseafd.js

// 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

//

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);

//