User:JesseW/testing stuff.js

//************************************ General Edit automation template ************ //From (originally) http://en.wikipedia.org/w/index.php?title=User:ABCD/monobook.js&oldid=19452182 function automate{ if (/title=Image:.*&action=edit/.test(document.location.href)) { var form = document.editform; form.wpTextbox1.value = form.wpTextbox1.value + "{"+"{PUI}}" form.wpSummary.value += "{{PUI"; //form.wpMinoredit.checked = true; } }

//******* Begining of a way to automate putting pages on public watchlists ***** function autoWikiWatchlist { var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; addlimenu(tabs, 'Watchlists', 'ca-watchlists-menu'); var z=document.location.href.match(/&magiccodeupdatewatchlist=(.*)$/); if (z) { var pagename="*"+unescape(z[1])+""; var form=document.editform; var tb=form.wpTextbox1; var p=tb.value.indexOf(pagename); if (p==-1) { tb.value = tb.value+pagename+"\n"; form.wpMinoredit.checked = true; form.wpSummary.value="Adding "+pagename; form.submit; } else { if (confirm("Remove '"+unescape(z[1])+"' from watchlist?")) { var p2=tb.value.indexOf("\n", p); tb.value = tb.value.substring(0,p)+tb.value.substring(p2+1) form.wpMinoredit.checked = true; form.wpSummary.value="Removing "+pagename; form.submit; } } } } function addWikiWatchlist (name, watchlist_loc) { var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit')); var url="http://en.wikipedia.org/w/index.php?title="+watchlist_loc+name url=url+"&action=edit&magiccodeupdatewatchlist="+escape(editlk); var fullurl='javascript:void(window.open("'+url+'", "WikiWatchlist"))'; addLink('ca-watchlists-menu', fullurl, name, 'watchlist-button-'+name, 'Add this page to your '+name+' watchlist.', , ); }

$(function { autoWikiWatchlist; addWikiWatchlist("Interests", "User:JesseW/Watchlists/"); addWikiWatchlist("Wikipedia", "User:JesseW/Watchlists/"); addWikiWatchlist("Conversations", "User:JesseW/Watchlists/"); addWikiWatchlist("News", "User:JesseW/Watchlists/"); });

//************************************ Next item in list ************************************ //From User:JesseW/monobook.js (i.e. me) function doNextItem { if (/lastpage=/.test(document.location)) { var oldone=unescape(/lastpage=(.+)$/(document.location)[1]); var z=document.links, nextone=0; for (var n=0; n<z.length; n++) { if (nextone==1 & z[n].innerHTML=="diff") { oldone=String(z[n].href); break; };	   if (z[n].href==oldone) { nextone=1; } };	var baseul=new String(document.location); baseul=baseul.replace(/[&?]lastpage=.+$/,""); document.location=oldone+"&basepage="+escape(baseul); };   if (/basepage=/.test(document.location)) { ul=new String(document.location); nul=unescape(/basepage=(.+)$/(document.location)[1])+"?lastpage="+escape(ul.replace(/&basepage=.+$/,"")); addlilink(document.getElementById("p-cactions").getElementsByTagName("ul")[0],nul,"Next one",""); }; }; function startNextItem { var z=document.links; for (var n=0;n<z.length;n++) { if (z[n].innerHTML=="diff") { oldone=String(z[n].href); break;}}; baseul=new String(document.location); baseul=baseul.replace(/[&?]lastpage=.+$/,""); document.location=oldone+"&basepage="+escape(baseul); } //************************************ Changes since I last edited **************************** //http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_User_scripts/Scripts/Changes_since_I_last_edited&oldid=33908644 //From http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510 function addSinceTab { var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; if (window.location.href.indexOf("&action=history&gotosince=true")!=-1) { do_since_I_last_edited }   else if (!/wiki\/Special:|w\/index.php?title=Special:/.test(window.location.href)) { var thetitle=document.title.slice(0, String(document.title).indexOf(" - ")); var l=addlilink(tabs, "/w/index.php?title="+thetitle+"&action=history&gotosince=true", 'since', ''); l.lastChild.title="Changes since I last edited"; } } function do_since_I_last_edited { var csub=document.getElementById("contentSub"); var msg=document.createElement("p"); msg.appendChild(document.createTextNode                       ("Parsing history... please wait...")); msg.className="error"; csub.insertBefore(msg, csub.firstChild)

var username=document.getElementById("pt-userpage").textContent; var hists=document.getElementById("pagehistory").childNodes; for (n=0;n<hists.length;n++) { if (hists[n].getElementsByTagName("span")[0].textContent==username) { document.location=hists[n].childNodes[1].href; return; }       }

msg.replaceChild(document.createTextNode                        ("You have not edited this page! (recently)"),                         msg.firstChild); }

//addOnloadHook(addSinceTab); //************************************ Edit lead section ***************************** //http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_User_scripts/Scripts/Add_edit_section_0&oldid=33908474 //If you are not editing a page, a tab will appear allowing you to edit the 0th section of a page (the top area //usually used as an introduction.

function addEditSection0 { ta['ca-edit-0'] = ['', 'Edit the zeroth section of this page']; if (!document.getElementById) return; x = document.getElementById('ca-edit'); if(!x) return; y = document.createElement('LI'); y.id = 'ca-edit-0'; if (x.className == 'selected') { if (/&action=edit&section=0$/.test(window.location.href)) { x.className = 'istalk'; y.className = 'selected'; } else { x.className = 'selected istalk'; } } else if (x.className == 'selected istalk') { if (/&action=edit&section=0$/.test(window.location.href)) { x.className = 'istalk'; y.className = 'selected istalk'; } else { y.className = 'istalk'; } } else { y.className = x.className; x.className = 'istalk'; } z = document.createElement('A'); if (x.children) { z.href = x.children[0].href + '&section=0'; z.appendChild(document.createTextNode('0')); y.appendChild(z); document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling); } else { z.href = x.childNodes[0].href + '&section=0'; z.appendChild(document.createTextNode('0')); y.appendChild(z); document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling); } }

if (document.title.indexOf("Editing ") == -1) { addOnloadHook(addEditSection0); } //************************************ Purge cache tab ***************************** //http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_User_scripts/Scripts/Add_purge_to_tabs&oldid=33908589 // addPurge $( function {   var x = document.getElementById('ca-history');    if(!x) return;    if(x.children) x = x.children[0].href;    else x = x.childNodes[0].href;    addLink("p-cactions", x.replace(/=history/, "=purge"), 'purge', 'ca-purge', 'Purge the internal cache for this page', 0); });

//*****************************add Last diff*************************** //http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_User_scripts/Scripts/Show_last_diff&oldid=33908751 //From http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510 // addLastDiff $(function {    z=document.getElementById("content").childNodes;    for (var n=0;n<z.length;n++) {       if (z[n].className=="firstHeading") {        var pname=z[n].textContent;      }    }    var l=addTab("http://en.wikipedia.org/w/index.php?title=" + pname + "&diff=cur&oldid=prev", 'last', '');    l.lastChild.title="Show most recent diff"; }); //************************************ Tabs at bottom ************************************ //http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_User_scripts/Scripts/Duplicate_tabs_at_bottom&oldid=33908849 //morelinks $(function {  var tabs = document.getElementById('p-cactions').cloneNode(true);  tabs.id = 'mytabs';  var listitems = tabs.getElementsByTagName('LI');  for (i=0;i<listitems.length;i++) {    if(listitems[i].id) listitems[i].id = 'mytabs-' + listitems[i].id;  }  document.getElementById('column-content').appendChild(tabs); }); //****************** Are you sure you don't want a Summary? ******************************* //http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_User_scripts/Scripts/Force_edit_summary&oldid=32187645 function addForceSummary {   if(!/&action=edit/.test(window.location.href) && !/&action=submit/.test(window.location.href)) return; if(/&section=new/.test(window.location.href)) return; if(!document.forms.editform) return; document.forms.editform.wpSave.onclick = forceSummary; }

function forceSummary {   if(!document.forms.editform.wpSummary.value.replace(/^(?:\/\\*.*\\*\/)? *(.*) *$/,'$1'))   {        var r = prompt('Are you sure you want to submit without adding a summary?\nTo add a summary, type it in the box below:',document.forms.editform.wpSummary.value); if(r == null) { return false; } document.forms.editform.wpSummary.value = r;   } return true; }

$(addForceSummary);

//************************************ Regexp replace tab ************************************ //http://en.wikipedia.org/w/index.php?title=Wikipedia:WikiProject_User_scripts/Scripts/Replace&oldid=33941455 function replace {   var s = prompt("Search regexp?"); if(s){ var r = prompt("Replace regexp?"); if(!r && r != '') return; var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(new RegExp(s, "g"), r); } }

$(function {    if(document.forms.editform) {        addLink('p-cactions', 'javascript:replace', 'replace', 'ca-replace', 'Regexp replace for the edit window', '', 'ca-history');    } }); //************************************ Utility functions ************************************ function addlilink(tabs, url, name, id) { var na = document.createElement('a'); na.href = url; na.id = id; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); li.id = id; li.appendChild(na); tabs.appendChild(li); return li; } function addlilink2(tabs, url, name, id, title) { var l=addlilink(tabs,url,name,id); l.lastChild.title=title; return l; } /**** Add tab as menu ****/ function addlimenu(tabs, name, id) {   var na = document.createElement('a'); na.href = '#'; var mn = document.createElement('ul'); na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); li.id = id; li.className = 'tabmenu'; li.appendChild(na); li.appendChild(mn); tabs.appendChild(li); return li; }

/**** Cross browser textContent ****/ function textContent(el) { if (el.textContent) return el.textContent; return el.innerText; } /**** Fix for the stupid lack of this in standard javascript. ****/ function foreach(lst, func) {for (n=0;n<lst.length;n++) {func(lst[n])}}

/*** Improved version of addlilink ****/ function addLink(where, url, name, id, title, key, after){ //* where is the id of the toolbar where the button should be added; //  i.e. one of "p-cactions", "p-personal", or "p-navigation". //* url is the URL which will be called when the button is clicked. //  javascript: urls can be used to do more complex things. //* name is what will appear as the name of the button. //* id is the id of the button; it's best to define one. //  Use a prefix to make sure its unique. Optional. //* title is the tooltip title that gives a longer description //  of the button; if you define a accesskey, mention it here. Optional. //* key is the char you want for the accesskey. Optional. //* after is the id of the button you want to follow this one. Optional. var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); var tabs = document.getElementById(where).getElementsByTagName('ul')[0]; if(document.getElementById(after)) { tabs.insertBefore(document.getElementById(after),li); } else { tabs.appendChild(li); }   if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title];} }   // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; }

//* */