User:Steel359/csd.js

//This was copied from User:GeorgeMoney/csd.js and modified by me (99% his work, 1% mine).

//When you install this script, you will also need to install cookie functions: //User:GeorgeMoney/UserScripts/helpers/all //You will also need the addlilink module //_-_-_-_-_-_-_-_-_-_CSD-_-_-_-_ if(window.location.href.indexOf('speedydel') != -1 && window.location.href.indexOf('action=delete') != -1) { addOnloadHook(function { doeasycsd; }); }

//The accesskey to use on the tab var tab_shortcut = "a";

//the criteria to not show "content was" var nocontent = "G1|G2|G3|G4|G5|G6|G7|G8|G9|G10|G11|G12|A1|A2|A3|A4|A5|A6|A7|A8|R1|R2|R3|I1|I2|I3|I4|I5|I6|I7|I8|I9|C1|C2|C3|U1|U2|T1|P1|P2";

//Delete the talkpage along with the main page var deletetalk = true;

//Namespaces to not delete the talkpage of var nodeletetalkNS = "User|Help";

//Image deletion extention var image_use = false;

//The summary to use when removing from article var image_sum = "Commenting out Image:$1 because it has been deleted";

//The button to click when commenting out image var image_click = 'wpSave';

//If image not found on page, ask to skip it, or just skip it period var image_asktoskip =  false;

//Article wikilink removal extention var article_use = false;

//Summary to use when removing wikilink var article_sum = "Removing wikilink to $1 because it was deleted";

//The button to click when removing wikilink var article_click = 'wpSave';

//The namespaces to ask you if you want to remove link from it (namespace of the page deleted) var article_remove_ns = ""; //"User|Talk|Wikipedia"; //if is blank, it means main namespace

//If link not found on page, ask to skip it var article_asktoskip =  false;

//namespaces to not remove link (namespace of page where the link is being removed from) var article_noremove_ns = "User|Wikipedia|User_talk|Image|Category|Category_talk";

//To open the creator's talk page Please set this to false it is experimental var useopentp = false;

//Default summary for criterias. $1 means where the criteria name will go //This is NOT what is used if you leave the inputbox blank. See above //This is called from the function defaultsum var thedefaultsum = "CSD $1";

//The default criteria to use if the inputbox is blank //Note: This is NOT the defaultsum. The defaultsum is the summary to use as default for criterias that you haven't set a special summary //This is ONLY used if the inputbox is blank, or you entered a summary that is not defined //This just calls the summary for whatever value you put in the var var defaultcrit = "I4";

var msgs = { //This is all the messages used in the script

//Extra summaries that you will type into the inputbox. so if you type "extra1" it will go to the value of "extra1" //Make sure there is a comma at the end of every line //Note: The extra summaries are case sensitive. The WP:CSD ones are not extra1: "Extra summary",

//All the criterias. Replace defualtsum('foo') with "yoursummary". so   G1: defaultsum('G1'),  becomes   G1: "yoursummary", G1: defaultsum('G1'), G2: defaultsum('G2'), G3: defaultsum('G3'), G4: defaultsum('G4'), G5: defaultsum('G5'), G6: defaultsum('G6'), G7: defaultsum('G7'), G8: defaultsum('G8'), G9: defaultsum('G9'), G10: defaultsum('G10'), G11: defaultsum('G11'), G12: defaultsum('G12'),

A1: defaultsum('A1'), A2: defaultsum('A2'), A3: defaultsum('A3'), A4: defaultsum('A4'), A5: defaultsum('A5'), A6: defaultsum('A6'), A7: defaultsum('A7'), A8: defaultsum('A8'),

R1: defaultsum('R1'), R2: defaultsum('R2'), R3: defaultsum('R3'),

I1: defaultsum('I1'), I2: defaultsum('I2'), I3: defaultsum('I3'), I4: defaultsum('I4'), I5: defaultsum('I5'), I6: defaultsum('I6'), I7: defaultsum('I7'), I8: defaultsum('I8'), I9: defaultsum('I9'),

C1: defaultsum('C1'), C2: defaultsum('C2'), C3: defaultsum('C3'),

U1: defaultsum('U1'), U2: defaultsum('U2'),

T1: defaultsum('T1'),

P1: defaultsum('P1'), P2: defaultsum('P2'),

prod: 'Prod 5+ days',

dummy: 'this is a dummy entry to break the comma' };

if(/*document.getElementById('ca-delete')*/wgCanonicalNamespace != 'Special') { $(function { var tbsd = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; addlilink(tbsd, 'javascript:doeasycsd', 'speedy delete', 'ca-speedy', 'speedy delete', tab_shortcut); }); }

var nocontent = nocontent.split('|'); var nodeletetalkNS = nodeletetalkNS.split('|'); var article_remove_ns = article_remove_ns.split('|'); var article_noremove_ns = article_noremove_ns.split('|');

var myPageName = wgPageName.replace(/_/g, ' ');

//alert(msgs.thedefaultsum + msgs.extra1); function defaultsum(h) { var f = thedefaultsum.replace(/\$1/g, h); return f; } function doeasycsd { var alm = true; if(window.location.href.indexOf('useurl') == -1) { var otherurlstf = ""; var useprompt = true; if(document.getElementById('delete')) { useprompt = false; var md = document.getElementById('delete'); var linksf = md.getElementsByTagName('a'); //                     alert("DEBUG: Over the next "+(linksf.length+1)+" alerts, you will see the urls of all the links in the speedy tag"); for(var i=0; i<linksf.length; i++) { var ll = linksf[i]; //                             alert("DEBUG: Link #"+(i+1)+": href: "+ll.href+"\ninnerHTML: "+ll.innerHTML); if(ll.href.indexOf("Wikipedia:Criteria_for_speedy_deletion") != -1||ll.href.indexOf("WP:CSD") != -1) { var usecrit = ll.href.split('#'); if(usecrit[1] == undefined) usecrit = false; else { //                                     alert("DEBUG: WP:CSD criteria was found on link #"+(i+1)+": href: "+ll.href); usecrit = usecrit[1]; break; }               } else var usecrit = false; }       if(usecrit === false) { useprompt = true; //ok not a speedy lets try for a prod for(var i=0; i<linksf.length; i++) { var ll = linksf[i]; if(ll.href.indexOf("Template:Prodwarning") != -1) { var useprod = true; break; } else var useprod = false; }               if(useprod) { var useprompt = false; var r = prompt('A prod tag was found on this page. Delete?'); if(r=="") r = 'prod'; }       } else { var r = prompt(''+usecrit+' was found on this page. Delete?'); if(r=="") r = usecrit; } }

if(useprompt) var r = prompt('Enter speedy criterion.'); if(r == null) { return; } else if(r=="s") { var re = prompt('What extra summary?'); var usesum = re; var lr = "spec"; var alm = false; } else if(r=="h") { var re = prompt('What extra summary to use \nwithout showing "content was"?'); var usesum = re; var lr = "specnc"; var alm = false; }

for(var i = 0; i<article_remove_ns.length; i++) { var nf = article_remove_ns[i]; if(wgCanonicalNamespace == nf) { var dolink = true; break; } else { var dolink = false; } } if(window.location.href.indexOf('?') != -1) var charuse = '&'; else var charuse = '?'; if(wgCanonicalNamespace == "Image"&&image_use) { if(confirm("Would you also like to remove all the file links from this image?")) { var gop = window.location.href.replace('action=delete', '')+charuse+'&imageopen=true'; otherurlstf = "&ext_dorem_img=true&ext_dorem_goto="+escape(gop); }} else if(dolink && article_use) { if(confirm("Would you also like to remove all the wikilinks pointing to this page?")) { var nop = unescape(window.location.href).replace(wgPageName, 'Special:Whatlinkshere/'+wgPageName)+charuse+'&linkopen=true'; otherurlstf = "&ext_dorem_art=true&ext_dorem_goto="+escape(nop); }} } else { var r = gvo('delcrit'); } if(r.indexOf('s|') == 0) { var usesum = r.replace('s|', ''); var lr = "spec"; var alm = false; } else if(r.indexOf('h|') == 0) { var usesum = r.replace('h|', ''); var lr = "specnc"; var alm = false; }

if(r!=''&&alm) { var cr = r.toUpperCase; eval('if(msgs.'+cr+' != undefined) { var usesum = msgs.'+cr+'; var lr = \+cr+'\'; } else if(msgs.'+r+' != undefined) { var usesum = msgs.'+r+'; var lr = \+r+'\'; } else { var usesum = msgs.'+defaultcrit+'; var lr = defaultcrit; }'); }

if(window.location.href.indexOf('speedydel') == -1) { if(lr == "spec") { lr = "s|"+usesum; } if(lr == "specnc") { lr = "h|"+usesum; } if(wgNamespaceNumber % 2 == 0 && deletetalk) var urldeletetalk = "&deletetalk="+escape(((wgCanonicalNamespace != '')?wgCanonicalNamespace+'_talk:':'Talk:')+wgTitle); else var urldeletetalk = ""; window.location.href = (document.getElementById('ca-delete').firstChild.href+'&speedydel=true&delcrit='+escape(lr)+'&useurl=true'+urldeletetalk+otherurlstf); if(useopentp) { window.open(document.getElementById('ca-history').firstChild.href+'&opentalk=true&limit=1'); window.open(document.getElementById('ca-history').firstChild.href+'&opentalk=true&opencontribs=true&limit=1'); } } else if(window.location.href.indexOf('speedydel') != -1) { var mydel = document.getElementById('wpReason'); if(mydel) { var olddelsum = mydel.value; for(var i = 0; i<nocontent.length; i++) { var nc = nocontent[i]; if(lr == nc||lr=="specnc") { var donotc = true; break; } else { var donotc = false; }       }        if(donotc||mydel.value=="") { var olddelsum = ""; } else { var olddelsum = "- "+olddelsum; } var newdelsum = usesum+" "+olddelsum; document.getElementById('wpReason').value = newdelsum; var inputs = document.getElementsByTagName('input'); for(var i = 0; i<nodeletetalkNS.length; i++) { var nd = nodeletetalkNS[i]; if(wgCanonicalNamespace == nd) { var donod = false; break; } else { var donod = true; }       }        if(window.location.href.indexOf('deletetalk') != -1&&deletetalk&&donod) { var wop = window.location.href.split('&deletetalk=')[0].replace(wgPageName, gvo('deletetalk'));//+'&closewindow=true'; createCookie('delscript_goto', escape(wop)); }       if(window.location.href.indexOf('ext_dorem_img=true') != -1) { var gop = gvo('ext_dorem_goto'); createCookie('delscript_goto', escape(gop)); createCookie('delscript_imagepage', escape(wgTitle)); }       if(window.location.href.indexOf('ext_dorem_art=true') != -1)  { var nop = gvo('ext_dorem_goto'); createCookie('delscript_goto', escape(nop)); createCookie('delscript_linkpage', escape(myPageName)); }   for (i=0; i<inputs.length; i++) { if (inputs[i].name == 'wpConfirmB') { inputs[i].click; }       }        }    }

}

if(readCookie('delscript_goto') != null) { var cookie = unescape(readCookie('delscript_goto')); eraseCookie('delscript_goto'); window.location.href = (cookie); }

if(window.location.href.indexOf('imageopen=true') != -1) { var togoto = ""; $(function {

if(readCookie('delscript_doimg') == null) { var ok = true; if(ok) { createCookie('delscript_image_ok', 0); var main1 = document.getElementById('filelinks'); if(main1) { var main2 = main1.nextSibling.nextSibling; if(main2) { var main3 = main2.nextSibling; if(main3) { var main4 = main3.nextSibling.nextSibling; if(main4) { if(main2.tagName == "P" && main3.id == "linkstoimage" && main4.tagName == "UL") { var lis = main4.getElementsByTagName('li'); for(var i = 0; i < lis.length; i++) { var hr = lis[i].firstChild.href; var realpg = unescape(readCookie('delscript_imagepage')); var wnopen = hr+'?action=edit&remimage=true&image_to_delete='+escape(realpg); //window.open(wnopen); togoto += "|"+wnopen; }                       togoto += "|"+window.location.href.split('&imageopen=true')[0]; createCookie('delscript_togoto', escape(togoto.substr(1))); createCookie('delscript_doimg', 'yes'); eraseCookie('delscript_oktogoto'); location.reload; }       }}}} }} else { eraseCookie('delscript_doimg'); createCookie('delscript_numgoto', '0'); var oldnum = parseInt(readCookie('delscript_numgoto')); var newnum = oldnum + 1; createCookie('delscript_numgoto', newnum); var myarr = unescape(readCookie('delscript_togoto')).split('|'); //alert('doimg. togoto is set, and it is: '+myarr+'; numgoto is: '+readCookie('delscript_numgoto')+' newnum: '+newnum+'; oldnum: '+oldnum); window.location.href = myarr[oldnum]; } }); }

if(window.location.href.indexOf('linkopen=true') != -1) { var togoto = ""; var templategoto = ""; $(function {       if(readCookie('delscript_doart') == null) {        var ok = true;        if(ok) {        if(readCookie('delscript_latergoto') != null) { togoto = unescape(readCookie('delscript_latergoto')); eraseCookie('delscript_latergoto'); var notemplate = true; }        else {         var notemplate = false;        var lis = document.getElementById('bodyContent').getElementsByTagName('ul')[0].getElementsByTagName('li');        for(var i = 0; i < lis.length; i++) {                var hr = lis[i].firstChild;                if(!hr) continue;                hr = hr.href;                if(hr.indexOf('&redirect=no') != -1) var isRedir = true;                else var isRedir = false;                var page_ns = hr.substr(('http://'+location.host).length);                page_ns = page_ns.split(':')[0];                if(page_ns == hr) page_ns = "";                else {                page_ns = page_ns.split('/'); page_ns = page_ns[(page_ns.length - 1)]; }               for(var j=0; j<article_noremove_ns.length; j++) { var nk = article_noremove_ns[j]; if(page_ns == nk) { var oktocont = false; break; } else var oktocont = true; }               if(!oktocont) continue; var realpg = unescape(readCookie('delscript_linkpage')); if(!isRedir) var wnopen = hr+'?&action=edit&remlink=true&link_to_delete='+escape(realpg); else var wnopen = hr+'?&action=delete&speedydel=true&delcrit=r1&useurl=true'; if(page_ns == "Template") templategoto += "|"+wnopen; else togoto += "|"+wnopen; }       togoto += "|"+window.location.href.split('&linkopen=true')[0]; }       if(templategoto != '') templategoto += "|"+window.location.href; if(togoto.indexOf('|') == 0) togoto = togoto.substr(1); if(templategoto.indexOf('|') == 0) templategoto = templategoto.substr(1); if(notemplate) templategoto = ""; var mygoto = (templategoto != '')?templategoto:togoto; if(mygoto == templategoto) createCookie('delscript_latergoto', escape(togoto)); createCookie('delscript_togoto', escape(mygoto)); createCookie('delscript_doart', 'yes'); eraseCookie('delscript_oktogoto'); location.reload; }} else { eraseCookie('delscript_doart'); createCookie('delscript_numgoto', '0'); var oldnum = parseInt(readCookie('delscript_numgoto')); var newnum = oldnum + 1; createCookie('delscript_numgoto', newnum); var myarr = unescape(readCookie('delscript_togoto')).split('|'); //alert('doimg. togoto is set, and it is: '+myarr+'; numgoto is: '+readCookie('delscript_numgoto')+' newnum: '+newnum+'; oldnum: '+oldnum); window.location.href = myarr[oldnum]; } }); }

if(window.location.href.indexOf('remimage=true') != -1 && window.location.href.indexOf('action=edit') != -1) { $(function {       var oldtext = document.getElementById('wpTextbox1').value;        var txt = document.getElementById('wpTextbox1');        var img = gvo('image_to_delete');        var regimg = img.replace(/\./g, '\\.').replace(/\*/g, '\\*').replace(/\//g, '\\/')                                        .replace(/[ _]/g, '[ _]')        var reg1 = new RegExp('\\[\\[[Ii]mage:\\s*'+regimg+'\\s*(\\|.*?\\]|\\])\\]', "ig");        var rpl1 = ;        var reg2 = new RegExp('([Ii]mage:)?'+regimg, "ig");        var rpl2 = ;        var newtext = oldtext.replace(reg1, rpl1);        var is_same = (newtext == oldtext);        if(is_same) newtext = oldtext.replace(reg2, rpl2);        txt.value = newtext;        document.getElementById('wpSummary').value = image_sum.replace(/\$1/g, img);        document.getElementById('wpMinoredit').checked = "checked";        document.getElementById('wpWatchthis').checked = "";        if(is_same&&image_asktoskip) {                var oktoclick = confirm("The image, "+img+" was not found on this page \n probably due to it being in an odd format \n press ok to go and remove it yourself,\n or cancel to just abort this edit and move on to the next");        } else var oktoclick = false;        createCookie('delscript_oktogoto', 'yes');        if(!oktoclick) document.getElementById(image_click).click;                //if(image_click == "wpSave") window.close; }); }

if(window.location.href.indexOf('remlink=true') != -1 && window.location.href.indexOf('action=edit') != -1) { $(function {       var oldtext = document.getElementById('wpTextbox1').value;        var txt = document.getElementById('wpTextbox1');        var lnk = gvo('link_to_delete');        var reglnk = lnk.replace(/\./g, '\\.').replace(/\*/g, '\\*').replace(/\//g, '\\/')                                        .replace(/[ _]/g, '[ _]')        var reg = new RegExp('\\[\\['+reglnk+'\\|?(.*?)\\]\\]', "ig");        newtext = oldtext.replace(reg, '');        newtext = newtext.replace(/\{\{D\:\}\}/g, lnk);        newtext = newtext.replace(/\{\{D:(.*?)\}\}/g, '$1');        txt.value = newtext;        document.getElementById('wpSummary').value = article_sum.replace(/\$1/g, lnk);        document.getElementById('wpMinoredit').checked = "checked";        document.getElementById('wpWatchthis').checked = "";        if(newtext == oldtext&&article_asktoskip) {                var oktoclick = confirm("The link, "+lnk+" was not found on this page \n probably due to it being in an odd format \n press ok to go and remove it yourself,\n or cancel to just abort this edit and move on to the next"); } else var oktoclick = false; createCookie('delscript_oktogoto', 'yes'); if(!oktoclick) document.getElementById(article_click).click; //if(image_click == "wpSave") window.close; }); }

if(readCookie('delscript_togoto') != null&&readCookie('delscript_oktogoto') != null) { //             alert('Togoto is set, and it is: '+readCookie('delscript_togoto')+'; numgoto is: '+readCookie('delscript_numgoto')); var oldnum = parseInt(readCookie('delscript_numgoto')); var newnum = oldnum + 1; createCookie('delscript_numgoto', newnum); var myarr = unescape(readCookie('delscript_togoto')).split('|'); if(newnum == myarr.length) { eraseCookie('delscript_togoto'); eraseCookie('delscript_numgoto'); } eraseCookie('delscript_oktogoto'); window.location.href = myarr[oldnum]; }

if(useopentp && window.location.href.indexOf('opentalk=true') != -1 && window.location.href.indexOf('action=history') != -1) { $(function { for(var i=0; i<document.links.length; i++) { var l = document.links[i]; if(l.innerHTML.indexOf('Earliest') == 0) { window.location.href = (l.href+'&opentalk=true'); return; } else { foundit = false; } } if(!foundit) { for(var i=0; i<document.getElementsByTagName('form').length; i++){ var k = document.getElementsByTagName('form')[i]; if(k.method=="get" && k.firstChild.name == "title" && k.firstChild.type == "hidden") { var lastli = k.getElementsByTagName('li')[(k.getElementsByTagName('li').length - 1)]; var g = lastli.getElementsByTagName('span')[0].getElementsByTagName('a'); for(var j = 0; j<g.length; j++) { var f = g[j]; if(f.firstChild.data == "Talk") { var go = f.href; } else if(f.firstChild.data == "contribs"&&window.location.href.indexOf('opencontribs=true') != -1) { var wo = f.href; } } } } if(window.location.href.indexOf('opencontribs=true') != -1) { window.location.href = (wo); } if(window.location.href.indexOf('opencontribs=true') == -1) { window.location.href = (go); } } }); }

//URL parameter function: //Originally from User:Lupin/autoedit.js function gvo(paramName) { var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)'); var h=document.location; var m; if (m=cmdRe.exec(h)) { try { return unescape(decodeURI(m[1])); } catch (someError) {} } return null; };

if(window.location.href.indexOf('action=delete') != -1 && document.title.indexOf('Action complete') == 0&&!deletetalk) { $(function { if(document.getElementById('t-whatlinkshere').firstChild.href.indexOf('&') != -1) { var chara = '&'; } else { var chara = '?'; } window.location.href = (document.getElementById('t-whatlinkshere').firstChild.href+chara+'delfrom=true'); }); } if(window.location.href.indexOf('delfrom=true') != -1&&!deletetalk) { $(function { var bx = document.getElementById('contentSub'); var hea = bx; var bxlw = document.createElement('div'); bxlw.id = "msgwrapper"; bxlw.innerHTML = ' Page successfully deleted!  '; hea.parentNode.insertBefore(bxlw, hea.nextSibling); }); }

//END //