User:Leon2323/monobook.js

// Tools: reload cache //

// START AUTOEDIT function getParamValue(paramName) { var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)'); var h=document.location; var m; if (m=cmdRe.exec(h)) { try { return decodeURI(m[1]); } catch (someError) {} } return null; };

function substitute(data,cmdBody) { // alert('sub\nfrom: '+cmdBody.from+'\nto: '+cmdBody.to+'\nflags: '+cmdBody.flags); var fromRe=RegExp(cmdBody.from, cmdBody.flags); return data.replace(fromRe, cmdBody.to); };

function execCmds(data, cmdList) { for (var i=0; i<cmdList.length; ++i) { data=cmdList[i].action(data, cmdList[i]); } return data; }

function parseCmd(str) { // returns a list of commands if (!str.length) return []; var p=false; switch (str.charAt(0)) { case 's': p=parseSubstitute(str); break; case 'j': p=parseJavascript(str); break; default: return false; } if (p) return [p].concat(parseCmd(p.remainder)); return false; };

function unEscape(str, sep) { return str.split('\\\\').join('\\') .split('\\'+sep).join(sep) .split('\\n').join('\n'); };

function runJavascript(data, argWrapper) { // flags aren't used (yet)

// from the user's viewpoint, // data is a special variable may appear inside code // and gets assigned the text in the edit box

// alert('eval-ing '+argWrapper.code);

return eval(argWrapper.code); };

function parseJavascript(str) { // takes a string like j/code/;othercmds and parses it

var tmp,code,flags;

if (str.length<3) return false; var sep=str.charAt(1); str=str.substring(2); tmp=skipOver(str,sep); if (tmp) { code=tmp.segment.split('\n').join('\\n'); str=tmp.remainder; } else return false;

flags=''; if (str.length) { tmp=skipOver(str,';') || skipToEnd(str, ';'); if (tmp) {flags=tmp.segment; str=tmp.remainder; } }

return { action: runJavascript, code: code, flags: flags, remainder: str }; };

function parseSubstitute(str) { // takes a string like s/a/b/flags;othercmds and parses it

var from,to,flags,tmp;

if (str.length<4) return false; var sep=str.charAt(1); str=str.substring(2);

tmp=skipOver(str,sep); if (tmp) { from=tmp.segment; str=tmp.remainder; } else return false;

tmp=skipOver(str,sep); if (tmp) { to=tmp.segment; str=tmp.remainder; } else return false;

flags=''; if (str.length) { tmp=skipOver(str,';') || skipToEnd(str, ';'); if (tmp) {flags=tmp.segment; str=tmp.remainder; } } return {action: substitute, from: from, to: to, flags: flags, remainder: str};

};

function skipOver(str,sep) { var endSegment=findNext(str,sep); if (endSegment<0) return false; var segment=unEscape(str.substring(0,endSegment), sep); return {segment: segment, remainder: str.substring(endSegment+1)}; }

function skipToEnd(str,sep) { return {segment: str, remainder: ''}; }

function findNext(str, ch) { for (var i=0; i<str.length; ++i) { if (str.charAt(i)=='\\') i+=2; if (str.charAt(i)==ch) return i; } return -1; };

function runOnLoad(f) { if (window.addEventListener) { window.addEventListener("load",f,false); } else if (window.attachEvent) { window.attachEvent("onload",f); } else { window._old_popup_autoedit_onload = window.onload; window.onload = function { window._old_popup_autoedit_onload; f; } } };

window.autoEdit=function { if (window.autoEdit.alreadyRan) return false; window.autoEdit.alreadyRan=true; var cmdString=getParamValue('autoedit'); if (cmdString) { try { var editbox=document.editform.wpTextbox1; } catch (dang) { return; } var cmdList=parseCmd(cmdString); var input=editbox.value; var output=execCmds(input, cmdList); editbox.value=output; }

var summary=getParamValue('autosummary'); if (summary) document.editform.wpSummary.value=summary;

var minor=getParamValue('autominor'); if (minor) { switch (minor) { case '1': case 'yes': case 'true': document.editform.wpMinoredit.checked=true; break; case '0': case 'no': case 'false': document.editform.wpMinoredit.checked=false; } }

var btn=getParamValue('autoclick'); if (btn) { if (document.editform && document.editform[btn]) { var headings=document.getElementsByTagName('h1'); if (headings) { var div=document.createElement('div'); var button=document.editform[btn]; div.innerHTML='The "' + button.value +          '" button has been automatically clicked.' + ' Please wait for the next page to load. '; document.title='('+document.title+')'; headings[0].parentNode.insertBefore(div, headings[0]); button.click; }   } else { alert('autoedit.js\n\nautoclick: could not find button "'+ btn +'".'); }   } };

runOnLoad(autoEdit); // END AUTOEDIT // START WHOISIP function whoisip { if(!document.getElementById) return; var searchForm = document.getElementById("searchform"); var whoisForm=document.createElement('form'); whoisForm.action = 'http://www.dnsstuff.com/tools/whois.ch'; whoisForm.method - 'GET'; whoisForm.innerHTML = ''; searchForm.appendChild(whoisForm); }; addOnloadHook(whoisip); // END WHOISIP // START COUNTDOWN TIMER // ************************************************** // Experimental javascript countdown timer (Splarka) // Version 0.0.3 // ************************************************** // // Usage example: // //  Only January 01 2007 00:00:00 PST until New years. // //  Javascript disabled.

function updatetimer(i) { var now = new Date; var then = timers[i].eventdate; var diff = count=Math.floor((then.getTime-now.getTime)/1000);

// catch bad date strings if(isNaN(diff)) { timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **' ; return; }

// determine plus/minus if(diff<0) { diff = -diff; var tpm = 'T plus '; } else { var tpm = 'T minus '; }

// calcuate the diff var left = (diff%60) + ' seconds'; diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + ' minutes ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + ' hours ' + left; diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left timers[i].firstChild.nodeValue = tpm + left;

// a setInterval is more efficient, but calling setTimeout // makes errors break the script rather than infinitely recurse timeouts[i] = setTimeout('updatetimer(' + i + ')',1000); }

function checktimers { //hide 'nocountdown' and show 'countdown' var nocountdowns = getElementsByClassName(document, 'span', 'nocountdown'); for(var i in nocountdowns) nocountdowns[i].style.display = 'none' var countdowns = getElementsByClassName(document, 'span', 'countdown'); for(var i in countdowns) countdowns[i].style.display = 'inline'

//set up global objects timers and timeouts. timers = getElementsByClassName(document, 'span', 'countdowndate'); //global timeouts = new Array; // generic holder for the timeouts, global if(timers.length == 0) return; for(var i in timers) { timers[i].eventdate = new Date(timers[i].firstChild.nodeValue); updatetimer(i); //start it up  } } addOnloadHook(checktimers);

// ************************************************** // - end -  Experimental javascript countdown timer // ************************************************** // END COUNTDOWN TIMER // START EDITPAGE function editpage { if(!document.getElementById) return; var searchForm = document.getElementById("searchform"); var editpageForm=document.createElement('form'); editpageForm.action = 'http://www.wikia.com/index.php'; editpageForm.method - 'GET'; editpageForm.innerHTML = ''; searchForm.appendChild(editpageForm); }; addOnloadHook(editpage); // END EDITPAGE // START DELETEDCONTRIBUTIONS function deletedcontributions { if(!document.getElementById) return; var searchForm = document.getElementById("searchform"); var deletedcontributionsForm=document.createElement('form'); deletedcontributionsForm.action = 'http://www.wikia.com/index.php'; deletedcontributionsForm.method - 'GET'; deletedcontributionsForm.innerHTML = ''; searchForm.appendChild(deletedcontributionsForm); }; addOnloadHook(deletedcontributions); // END DELETEDCONTRIBUTIONS // START LOG IN LINK gsLogInInsertBefore = 'pt-mycontris'; // leave blank to append after "logout" // function LogInLink { var li = document.createElement( 'li' ); li.id = 'pt-login';

var a = document.createElement( 'a' ); a.appendChild( document.createTextNode( 'log in' ) ); // eh, the css makes the text lowercase a.href = 'http://www.wikia.com/index.php?title=Special:Userlogin&wpName=Leon2323';

li.appendChild( a );

if ( ! gsLogInInsertBefore ) // append to end (right) of list { document.getElementById( 'pt-newlo' ).parentNode.appendChild( li ); } else { var before = document.getElementById( gsLogInInsertBefore ); before.appendChild( li, before ); } }  if ( window.addEventListener ) window.addEventListener( 'load', LogInLink, false ); else if ( window.attachEvent     ) window.attachEvent   ( 'onload', LogInLink ); // END LOG IN LINK // START NEWMESSAGE function checkMsgs { var divs = document.getElementById('bodyContent').getElementsByTagName('div'); if(divs.length <= 2) return; for(var i=0;i<divs.length;i++) { if(divs[i].className == 'usermessage') { divs[i].style.display = 'none'; var talk = document.getElementById('pt-mytalk').firstChild; talk.style.color='#ffff00'; talk.style.textDecoration='blink'; talk.style.background='#ffff00 url(http://upload.wikimedia.org/wikipedia/commons/9/96/New_%28animated%29.gif) no-repeat 0 0'; talk.style.paddingLeft='32px'; } } } addOnloadHook(checkMsgs) // END NEWMESSAGE

//