User:Splash/vector.js

// //For 'Gadgets' popupAdminLinks=true; popupFixDabs=true;

////////////////////////////////////////// // Tabs by Korath // returns  name ///////////////////////////////////////// function addlilink2(url, name) { var na = document.createElement('a'); na.setAttribute('href', url);

var txt = document.createTextNode(name); na.appendChild(txt);

var li = document.createElement('li'); li.appendChild(na); return li; }

function add_link2(url, name) { var na = document.createElement('a'); na.setAttribute('href', url); na.appendChild(document.createTextNode(name));

var li = document.createElement('li'); li.appendChild(na);

var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; tabs.appendChild(li);

//This makes them look right in Vector item = li; fixTab(item); }

// appends msg to the currently-editted page, sets the summary to summ, // and marks or unmarks the Watch this page checkbox according to watch. function edit_summary_watch(msg, summ, watch, line) { var f = document.editform, t = f.wpTextbox1; if ((t.value.length > 0) && (line == 1)) t.value += '\n'; t.value += msg; f.wpSummary.value += summ; f.wpWatchthis.checked = watch; }

function prepend_summary_watch(msg, summ, watch) { var f = document.editform, t = f.wpTextbox1; t.value = msg + '\n' + t.value; f.wpSummary.value += summ; f.wpWatchthis.checked = watch; }

function delete_reason(process){ if(process==1) {       document.forms.deleteconfirm.wpReason.value = 'Wikipedia( talk)?):/, ) + ; }   else if(process==2) {       document.forms.deleteconfirm.wpReason.value = 'PROD: \"\"'; } }

// adds various tabs to call the above function add_tabs { var c1 = document.getElementById('column-one'); var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

// Only add for pages with "Editing User talk:" somewhere in the title if (document.title.indexOf("Editing User talk:") != -1) {     tabs.appendChild(add_link2('javascript:edit_summary_watch(" ~" + "~" + "~" + "~\n", "", true, 1)',"T1")); tabs.appendChild(add_link2('javascript:edit_summary_watch(" ~" + "~" + "~" + "~\n", "", true, 1)',"T2")); tabs.appendChild(add_link2('javascript:edit_summary_watch(" ~" + "~" + "~" + "~\n", "", true, 1)',"T2a")); tabs.appendChild(add_link2('javascript:edit_summary_watch(" ~" + "~" + "~" + "~\n", "", true, 1)',"T3")); tabs.appendChild(add_link2('javascript:edit_summary_watch(" ~" + "~" + "~" + "~\n", "", true, 1)',"T4")); tabs.appendChild(add_link2('javascript:edit_summary_watch(" ~" + "~" + "~" + "~\n", "", true, 1)',"T5")); tabs.appendChild(add_link2('javascript:edit_summary_watch(" ~" + "~" + "~" + "~\n", "", true, 1)',"Blank")); }   if(document.title.indexOf("Delete \"") != -1)    {        tabs.appendChild(add_link2('javascript:delete_reason(1)', 'AfD', ));        tabs.appendChild(add_link2('javascript:delete_reason(2)', 'PROD', ));    } }

if (window.addEventListener) window.addEventListener("load", add_tabs, false); else if (window.attachEvent) window.attachEvent("onload", add_tabs);

function hidevfd{ var divs = document.getElementsByTagName("div"); for(var x = 0; x < divs.length; ++x) if(divs[x].className.indexOf("vfd") != -1) divs[x].style.display = "none"; document.getElementById('footer').style.display = 'none'; }

function showvfd{ var divs = document.getElementsByTagName("div"); for(var x = 0; x < divs.length; ++x) if(divs[x].className.indexOf("vfd") != -1) divs[x].style.display = ""; document.getElementById('footer').style.display = ''; }

function vfdlinks{ var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; if(document.title.indexOf("Wikipedia:Articles for deletion") == 0){ add_link2('javascript:hidevfd', 'hide'); add_link2('javascript:showvfd', 'show'); } }

if (window.addEventListener) window.addEventListener("load",vfdlinks,false); else if (window.attachEvent) window.attachEvent("onload",vfdlinks);

/////////////////////////////////////////////////////////////////// // AutoVFD by Korath // This needs to change depending on skin used. //////////////////////////////////////////////////////////////////

function strip_namespace(target) { var colon = target.indexOf(':'); if (colon != -1) {     var spaces = new Array('User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category'); var ns = target.substring(0, colon); if (ns == '' || ns == 'Talk') return target.substring(colon + 1); else for (var i = 0; i < spaces.length; ++i) {           if (ns == spaces[i]                || ns == spaces[i] + '_talk') return target.substring(colon + 1); }   }

return target; }

function addpersondata { edit_summary_watch("\n{"+"{Persondata\n|NAME=\n|ALTERNATIVE NAMES=\n|SHORT DESCRIPTION=\n|DATE OF BIRTH=\n|PLACE OF BIRTH=\n|DATE OF DEATH=\n|PLACE OF DEATH=\n}"+"}", "+\[\[Wikipedia:Persondata\]\]", false, 0); }

function vfd { document.editform.wpTextbox1.value = '{' + '{' + 'subst:afd}}\n' + document.editform.wpTextbox1.value; document.editform.wpSummary.value = 'AfD'; document.editform.wpWatchthis.checked = true;

var target = document.editform.action; target = target.substring(target.indexOf('title=') + 6,                           target.lastIndexOf('&action=submit'));

var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var date = new Date; date = date.getUTCFullYear + '_' + months[date.getUTCMonth] + '_' + date.getUTCDate;

var pagename = strip_namespace(target);

//Need to handle being secure.wikimedia.org domain? var prepend = ''; if(document.domain.indexOf("secure.wikimedia.org") != -1) prepend = '/wikipedia/en';

window.open(prepend + '/w/index.php?title=Wikipedia:Articles_for_deletion/' + pagename + '&action=edit&fakeaction=afdsub&faketarget=' + target + '&preload=Template:Afd2+starter&editintro=Template:Afd3+starter',             'AfD ' + unescape(target),              'status,toolbar,location,menubar,directories,resizable,scrollbars'); window.open(prepend + '/w/index.php?title=Wikipedia:Articles_for_deletion/Log/' + date + '&action=edit&fakeaction=afdlist&faketarget=' + pagename,             'AfDLog ' + unescape(target),              'status,toolbar,location,menubar,directories,resizable,scrollbars'); }

function closevfd(result,project) {        if (project==1) {subst_text = "afd";} else if (project==2) {subst_text = "tfd";} else if (project==3) {subst_text = "cfd";} else if (project==4) {subst_text = "mfd";}

if(result == 1) {	       topclose = " \'\'\'KEEP\'\'\'. -~" + "~" + "~" + "~\n"; close_name = "keep"; }

else if(result == 2) {	       topclose = " \'\'\'MERGE\'\'\' to \'\' \'\'. -~" + "~" + "~" + "~\n"; close_name = "merge"; }

else if(result == 3) {	       topclose = " \'\'\'REDIRECT\'\'\' to \'\' \'\'. -~" + "~" + "~" + "~\n"; close_name = "redir"; }       else if (result ==4) {	       topclose = " \'\'\'DELETE\'\'\'. -~" + "~" + "~" + "~\n"; close_name = "delete"; }       else if (result ==5) {	       topclose = " \'\'\'NO CONSENSUS\'\'\'. -~" + "~" + "~" + "~\n"; close_name = "no consensus"; }

if(project == 2 || project == 3) below_head_close(topclose); else if(project == 1 || project == 4) above_head_close(topclose);

if(project == 1) strip_annoying_tag;

edit_summary_watch("\n" + "", "close - " + close_name, false, 0); }

function below_head_close(closure) {   f = document.editform, t = f.wpTextbox1; z = t.value.split('===='); t.value = "====" + z[1] + "====" + '\n';  //header t.value += closure; //top close t.value += z[2]; //re-add main body }

function above_head_close(closure) {   f = document.editform, t = f.wpTextbox1; t.value = closure + "\n" + t.value; }

function strip_annoying_tag {   f = document.editform, t = f.wpTextbox1; z = t.value.split(/\n/); t.value = z[0] + z[1]; }

function vfdvote(vote) {	if (vote == 1) edit_summary_watch("*\'\'\'Delete\'\'\' -~"+"~"+"~"+"~", document.editform.wpSummary.value + "delete", true, 0); else if (vote == 2) edit_summary_watch("*\'\'\'Keep\'\'\' -~"+"~"+"~"+"~", document.editform.wpSummary.value + "keep", true, 0); else if (vote == 3) edit_summary_watch("*\'\'\'Merge\'\'\' -~"+"~"+"~"+"~", document.editform.wpSummary.value + "merge", true, 0); else if (vote == 4) edit_summary_watch("*\'\'\'Redirect\'\'\' -~"+"~"+"~"+"~", document.editform.wpSummary.value + "redirect", true, 0);

}

function vfdtalk(result, project) { /*    boiler1 = "=" + "=Articles for Deletion debate=" + "=\nThis article "; boiler2 = " an [" + "[Wikipedia:Articles for deletion|Articles for Deletion]" + "] debate. The discussion can be found [" + "[Wikipedia:Articles for deletion/{" + "{subst" + ":PAGENAME}" + "}|here]" + "]. -~" + "~" + "~" + "~";

if(result == 1) edit_summary_watch(boiler1 + "survived" + boiler2, document.editform.wpSummary.value + "link to AfD", false, 0); else if (result == 2) edit_summary_watch(boiler1 + "was merged with and redirected to \'\' \'\' as a result of" + boiler2, document.editform.wpSummary.value + "link to AfD", false, 0); else if (result == 3) edit_summary_watch(boiler1 + "was redirected to \'\' \'\' as a result of" + boiler2, document.editform.wpSummary.value + "link to AfD", false, 0); if (project == 1) {		txt = "afd"; Ctxt = "AfD"; }	else if (project == 2) {		txt = "tfd"; Ctxt = "TfD"; }	else if (project == 3) {		txt = "cfd"; Ctxt = "CfD"; }	else if (project == 4) {		txt = "mfd"; Ctxt = "MfD"; }    boiler1 = "{" + "{old " + txt + "|date= |result="; boiler2 = "}" + "}";

if(result == 1) prepend_summary_watch(boiler1 + "keep" + boiler2, "Result of " + Ctxt + " was keep", false); else if (result == 2) prepend_summary_watch(boiler1 + "merge to [" + "[]" + "]" + boiler2, "Result of " + Ctxt + " was merge+redirect", false); else if (result == 3) prepend_summary_watch(boiler1 + "redirect to [" + "[]" + "]" + boiler2, "Result of " + Ctxt + " was redirect", false); else if(result == 4) prepend_summary_watch(boiler1 + "no consensus" + boiler2, "Result of " + Ctxt + " was no consensus", false);

}

function deletiontags {       if (document.title.indexOf("Editing Wikipedia:Votes for deletion") != -1 || document.title.indexOf("Editing Wikipedia:Pages for deletion") != -1 || document.title.indexOf("Editing Wikipedia:Articles for deletion") != -1 || document.title.indexOf("Wikipedia:Templates for deletion/Log") != -1 || document.title.indexOf("Wikipedia:Categories for discussion/Log") != -1 || document.title.indexOf("Wikipedia:Miscellany for deletion") != -1) {           if (document.title.indexOf("Articles") != -1) {project = 1;} else if (document.title.indexOf("Templates") != -1) {project = 2;} else if (document.title.indexOf("Categories") != -1) {project = 3;} else if (document.title.indexOf("Miscellany") != -1) {project = 4;} //add_link2('javascript:vfdvote(1)', 'v - d'); //add_link2('javascript:vfdvote(2)', 'v - k'); //add_link2('javascript:vfdvote(3)', 'v - m'); //add_link2('javascript:vfdvote(4)', 'v - r'); add_link2('javascript:closevfd(1,project)', 'c k'); add_link2('javascript:closevfd(2,project)', 'c m'); add_link2('javascript:closevfd(3,project)', 'c r'); add_link2('javascript:closevfd(4,project)', 'c d'); add_link2('javascript:closevfd(5,project)', 'c nc'); }       else if (document.title.indexOf("Editing Wikipedia:") == -1  && document.title.indexOf("Editing Talk:") == -1  && document.title.indexOf("Editing Category talk:") == -1 && document.title.indexOf("Editing Category:") == -1 && document.title.indexOf("Editing Template talk:") == -1 && document.title.indexOf("Editing Template:") == -1 && document.title.indexOf("Editing User talk:") == -1 && document.title.indexOf("Editing User:") == -1) {           add_link2('javascript:vfd', 'vfd'); //add_link2('javascript:copyvio', 'copyvio'); add_link2('javascript:addpersondata', 'person'); }       else if (document.title.indexOf("Editing Wikipedia:") == -1 && document.title.indexOf("Editing User:") == -1 && document.title.indexOf("Editing User talk:") == -1 && document.title.indexOf("Editing Category:") == -1 && document.title.indexOf("Editing Template:") == -1 && document.title.indexOf("Editing File:") == -1) {       	if (document.title.indexOf("Editing Talk:") != -1) {project = 1; txt    = 'afd'; }       	else if  (document.title.indexOf("Editing Template talk:") != -1) {project = 2; txt    = 'tfd'; }       	else if  (document.title.indexOf("Editing Category talk:") != -1) {project = 3; txt    = 'cfd'; }       	else if  (document.title.indexOf("Editing Wikipedia talk:") != -1) {project = 4; txt    = 'mfd'; }           add_link2('javascript:vfdtalk(1, ' + project + ')', txt + ' k'); add_link2('javascript:vfdtalk(2, ' + project + ')', txt + ' m'); add_link2('javascript:vfdtalk(3, ' + project + ')', txt + ' r'); add_link2('javascript:vfdtalk(4, ' + project + ')', txt + ' nc'); } }

function autoafd { if (document.title.indexOf('Editing ') == 0) {     var action = ''; var target = ''; if (location.search) {         var l = location.search.substring(1).split('&'); for (var i = 0; i < l.length; ++i) {             var eq = l[i].indexOf('='); var name = l[i].substring(0, eq); if (name == 'fakeaction') var action = l[i].substring(eq + 1); else if (name == 'faketarget') var target = unescape(l[i].substring(eq + 1)).replace(/_/g, ' '); }       }

if (action == 'afdlist') {         var marker = '\n'; var z = document.editform.wpTextbox1.value.split(marker);

document.editform.wpTextbox1.value = z[0] + marker + '\n' + z[1]; //document.editform.wpTextbox1.value += '\n'; document.editform.wpSummary.value = 'Articles for deletion/' + target + ''; document.editform.wpWatchthis.checked = false; }     else if (action == 'afdsub') {         var v = document.editform.wpTextbox1.value; var pre = ' ~\n'; if (v.length > 0 && v!=pre) {             target = document.editform.action; target = unescape(target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit'))).replace(/_/g, ' '); window.alert("There's an old AfD at the default location already.\n\n" +                          'Please either move it out of the way (and update existing links to it), or file the AfD by hand in another location (such as ' + target + ' (2)).'); }         else {           //The actual AfD is pre-populated these days, so just some admin here document.editform.wpSummary.value = 'Nominate'; document.editform.wpWatchthis.checked = true; }       }      else deletiontags; } }

if (window.addEventListener) window.addEventListener('load', autoafd, false); else if (window.attachEvent) window.attachEvent('onload', autoafd);

// Like document.getElementsByTagName, but finds only direct children of a given node function node_getElementsByTagName(node, tag) { var arr = new Array; tag = tag.toUpperCase; for (node = node.firstChild; node; node = node.nextSibling) if (node.tagName == tag) arr[arr.length] = node; return arr; }

function fixTab(item) { if (item.firstChild.innerHTML.indexOf(' ') == -1) item.firstChild.innerHTML = " " + item.firstChild.innerHTML + " "; } addOnloadHook(function { document.getElementById('p-cactions').className = 'vectorTabs';  var elems = document.getElementById('p-cactions').getElementsByTagName('li');  for (var i = 0; i < elems.length; i++)    fixTab(elems[i]);  var twinkleElem = document.getElementById('p-twinkle');  if (twinkleElem)    twinkleElem.className = 'vectorTabs'; }) //