User:Humanbot~enwiki/monobook.js

// Please do not edit this page unless you know what you are doing!

// "seven"

// begin contants

const newpage = 'http://humanbot.joeyday.net/enwiki/new.php?version=seven&project=' + getCookie('project'); const editpage = 'http://humanbot.joeyday.net/enwiki/edit.php?version=seven&project=' + getCookie('project'); const selectpage = 'http://en.wikipedia.org/wiki/User:Humanbot/selectproj'; const setprojpage = 'http://en.wikipedia.org/wiki/User:Humanbot/setproj/'; const homepage = 'http://en.wikipedia.org/wiki/User:Humanbot'; const byepage = homepage;

// end constants

//

// Utility functions: cookies // http://www.netspade.com/articles/2005/11/16/javascript-cookies/ // "for you to use freely in your own code" // simplified by R3m0t

/** * Sets a Cookie with the given name and value. * * name      Name of the cookie * value     Value of the cookie * [expires] Expiration date of the cookie (default: end of current session) */ function setCookie(name, value, expires, path) { document.cookie= "hb_" + name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString : "") + "; path=/"; }

/** * Gets the value of the specified cookie. * * name Name of the desired cookie. * * Returns a string containing value of specified cookie, *  or null if cookie does not exist. */ function getCookie(name) { var dc = document.cookie; var prefix = "hb_" + name + "="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; } else { begin += 2; }   var end = document.cookie.indexOf(";", begin); if (end == -1) { end = dc.length; }   return unescape(dc.substring(begin + prefix.length, end)); }

/** * Deletes the specified cookie. * * name     name of the cookie * [path]   path of the cookie (must be same as path used to create cookie) * [domain] domain of the cookie (must be same as domain used to create cookie) */ function deleteCookie(name, path, domain) { if (getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } }

function findthe(spec) { ret = document.evaluate(spec, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); return ret.snapshotItem(0); }

// End utility functions

function HumanbotTurnON { setCookie('on', 1); document.location.href = selectpage; }

function HumanbotTurnOFF { setCookie('on', 0); setCookie('project', ''); document.location.href = byepage; }

function HumanbotAction { navbar = document.getElementById('p-tb'); navbar.appendChild(document.createTextNode(document.cookie)); title = document.location.href; if (getCookie('on') == 1) { // prepare toolbox toolboxOut = document.createElement('div'); toolboxOut.id = 'p-autobox'; toolboxOut.className = 'portlet'; heading = document.createElement('h5'); heading.innerHTML = 'humanbot'; toolboxOut.appendChild(heading); toolbox = document.createElement('div'); toolbox.className = 'pBody'; toolboxOut.appendChild(toolbox); actions = document.createElement('ul');

if (title.indexOf(setprojpage) == 0) { thisproj = title.substring(title.indexOf('/setproj/') + 9, title.length); if (getCookie('project') == thisproj) { document.location.href = newpage; } else { //change project setCookie('project', title.substring(title.indexOf('/setproj/') + 9, title.length)); window.location.reload(false); }       }        if (window.location.href == selectpage) { setCookie('project', ''); }       if (getCookie('project') != '') { if (/action=edit&humanbot=y/.test(window.location.href)) { last = (title.lastIndexOf('#') > 0) ? title.lastIndexOf('#') : title.length; page = title.substring(title.indexOf('title=') + 6, last); setCookie('page', page); var mainbox; mainbox = findthe("//textarea[@name='wpTextbox1']"); if (!mainbox) { //protected window.location.href = newpage + '&prot=' + title + '&fixer=' + findfixer; } else { mainbox.value = 'Wait. Processing article of ' + mainbox.defaultValue.length + ' characters in length.'; mainbox.disabled = true; submit = findthe("//input[@name='wpSave']"); submit.disabled = true; document.write(' ');                 }             }        } else { //no project             if (title != selectpage) { document.location.href = selectpage; } //force project selection        }        var link = document.createElement('a');        link.href = 'javascript:HumanbotTurnOFF';        link.title = 'Turn off humanbot';        link.appendChild(document.createTextNode('Off'));        var li = document.createElement('li');        li.appendChild(link);        actions.appendChild(li);

toolbox.appendChild(actions); navbar.parentNode.insertBefore(toolboxOut, navbar); } else { //currently off var link = document.createElement('a'); link.href = 'javascript:HumanbotTurnON'; link.title = 'Turn on humanbot'; link.appendChild(document.createTextNode('Humanbot'));

var li = document.createElement('li'); li.appendChild(link); navbar.getElementsByTagName('ul')[0].appendChild(li); } }

function HumanbotResponse(parsed) { alert('resp'); alert(parsed); }

function takefuncs(xmlhttpRequest, setValue, getValue, openInTab) { alert('boo'); alert(setValue); }

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

//