Userscript (Greasemonkey + Tampermonkey compatible) that appends GUI to footer, automatically does a "daily" preference'd by the user. I hope this helps anyone brand new to javascript Code (Javascript): // ==UserScript== // @name Neopets Dailies // @namespace neofriends.net // @version 0.2 // @description Daily helper for neopets // @include http://www.neopets.com/* // @exclude http://www.neopets.com/winter/igloo* // @match http://www.neopets.com/bank.phtml // @match http://www.neopets.com/games/ // @match http://www.neopets.com/prehistoric/omelette.phtml // @match http://www.neopets.com/jelly/jelly.phtml // @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js // @grant GM_getValue // @grant GM_log // @grant GM_openInTab // @grant GM_registerMenuCommand // @grant GM_setValue // @copyright Carter 'Siren' June 2013 // ==/UserScript== //VARS var randNumMin = GM_getValue("mindelay"); //min in seconds var randNumMax = GM_getValue("maxdelay"); //max in seconds var randdelay = (Math.random() * (randNumMax - randNumMin + 1) + randNumMin) * 1000; //in ms, not floor'd var shares = 1000; var choice; //checks console.log(shares + " : shares"); console.log(randdelay + " : randdelay on start"); //remove #footer's background image for settings $("#footer").css('background-image', 'none'); $("#footer").css('background-color', 'rgb(207, 201, 47)'); $("#footer").css('height', '300px'); $("#footer").css('width', '700px'); $("#footer").css('text-align', 'center'); //GUI document.getElementById('footer').innerHTML = "<html><script type='text/javascript'>var saveopts = function(){var choice;if(document.getElementById('bankintcheckbox').checked==true){choice=true}else{choice=false}GM_setValue('dobank',choice);console.log(GM_getValue('dobank') + ' : gm_getvalue of dobank');}</script>" + "<body><center style=''><h2>Carter 'Siren' Daily Doer</h2></center><p>" + "Minimum Delay: <input type='text' id='txtmindelay' size='1'> seconds<br>Maximum Delay: <input type='text' id='txtmaxdelay' size='1'> seconds<br>" + "<span style=';'>collect bank interest: </span><input name='bankcheckbox' id='bankintcheckbox' type='checkbox' value='bankcheckbox'><br><span style=''>do stock:</span><input name='stockcheckbox' id='stockcheckbox' type='checkbox' value='stockcheckbox'>" + "<br><span style=''>do jelly:</span><input name='jellycb' id='jellycb' type='checkbox' value='jellycb'>" + "<br><span style=''>do tomb:</span><input name='tombcb' id='tombcb' type='checkbox' value='tombcb'>" + "<br><span style=''>do tdmbgpop (plushie):</span><input name='plushiecb' id='plushiecb' type='checkbox' value='plushiecb'>" + "<br><span style=''>do tombola:</span><input name='tombolacb' id='tombolacb' type='checkbox' value='tombolacb'>" + "<br><span style=''>do shop of offers:</span><input name='slorgcb' id='slorgcb' type='checkbox' value='slorgcb'>" + "</p><p></p><input name='save' id='savebtn' type='button' value='save preferences'>" + "<input name='goomelette' id='goomelette' type='button' value='Go To Omelette'>" + "<input name='gotomb' id='gotomb' type='button' value='Go To Deserted Tomb'>" + "<input name='gobank' id='gobank' type='button' value='Go To Bank'>" + "<input name='gojelly' id='gojelly' type='button' value='Go To Jelly'>" + "<input name='gostock' id='gostock' type='button' value='Go To Stock Market'>" + "<input name='goplushie' id='goplushie' type='button' value='Go To Blue Plushie'>" + "<input name='goslorg' id='goslorg' type='button' value='Go To Shop Of Offers (slorg)'>" + "<input name='gotombola' id='gotombola' type='button' value='Go To Tombola'>" + "<input name='checkgmval' id='checkgmval' type='button' value='Check Current Preferences (console logs)'>" + "<br><i>Instructions: all preferences are saved across page loads; you don't need to reset them every time you go to a new page. In order to change them, check/uncheck each checkbox and add numbers for new min/max delay on pages. (default min/max are 1,3 seconds)</i>" + "</body></html>"; if (GM_getValue("doslorg") == "undefined"){ GM_setValue("doslorg", true); } document.getElementById('txtmindelay').value = GM_getValue("mindelay"); if(document.getElementById('txtmindelay').value == "NaN"){ GM_setValue("mindelay", 1); //default: 1 second min document.getElementById('txtmindelay').value = parseInt(GM_getValue("mindelay")); } document.getElementById('txtmaxdelay').value = GM_getValue('maxdelay'); if(document.getElementById('txtmaxdelay').value == "NaN"){ GM_setValue("maxdelay", 3); //default: 3 seconds max document.getElementById('txtmaxdelay').value = parseInt(GM_getValue("maxdelay")); } //BANK interest //location of submit: document.getElementsByClassName('content')[0].getElementsByTagName('table')[7].getElementsByTagName('tbody')[0].getElementsByTagName('tr')[0].getElementsByTagName('td')[0].getElementsByTagName('table')[0] if (document.location.href == "http://www.neopets.com/bank.phtml" && GM_getValue("dobank") == true) { window.setTimeout("document.forms[3].submit();", randdelay); } //TOMBOLA if ((document.location.href == "http://www.neopets.com/island/tombola.phtml" || document.location.href == "http://www.neopets.com/island/tombola2.phtml") && GM_getValue("dotombola") == true){ window.setTimeout("document.forms[1].submit();", randdelay); } //OMELETTE //location of submit button: [@id="content"]/table/tbody/tr/td[2]/center[2]/form/input[2] if (document.location.href == "http://www.neopets.com/prehistoric/omelette.phtml" && GM_getValue("doomelette") == true){ setTimeout("document.forms[1].submit();", randdelay); //grab } if (document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue == " <b>You approach the massive omelette...</b>"){ console.log("omelette content value found"); setTimeout("document.forms[1].submit();", randdelay); //leave } //*[@id="content"]/table/tbody/tr/td[2]/center/p[1]/b = xpath for "you approach.." //JELLY if ((document.location.href == "http://www.neopets.com/jelly/jelly.phtml?" || document.location.href == "http://www.neopets.com/jelly/jelly.phtml?") && GM_getValue("dojelly") == true){ setTimeout("document.forms[1].submit();", randdelay); //document.forms[1] becomes the return submit form. no need for return line } //TOMB if (document.location.href == "http://www.neopets.com/worlds/geraptiku/tomb.phtml" && GM_getValue("dotomb") == true){ setTimeout("document.forms[1].submit();", randdelay); } if (document.location.href == "http://www.neopets.com/worlds/geraptiku/process_tomb.phtml" && GM_getValue("dotomb") == true){ setTimeout("document.forms[1].submit();", randdelay); } //FRUIT MACHINE if (document.location.href == "http://www.neopets.com/desert/fruit/index.phtml" && GM_getValue("dofruit") == true){ document.forms[1].submit(); setTimeout("document.forms[1].submit()", 10000); //the animation has to complete. NOT YET FINISHED } //blue PLUSHIE thing if (document.location.href == "http://www.neopets.com/faerieland/tdmbgpop.phtml" && GM_getValue("doplushie") == true){ setTimeout("document.forms[1].submit();", randdelay); //"talk to plushie" and return to world } //STOCK, much thanks to Heya if (document.location.href == "http://www.neopets.com/stockmarket.phtml?type=list&full=true" && GM_getValue("dostock") == true) { for(i=1;i<42; i++) { if(document.getElementsByClassName('content')[0].getElementsByTagName('table')[0].getElementsByTagName('tr')[i].getElementsByTagName('td')[5].innerHTML == '<b>15</b>') { setTimeout("document.location.href = document.getElementsByClassName('content')[0].getElementsByTagName('table')[0].getElementsByTagName('tr')[i].getElementsByTagName('a')[0].href;", randdelay); } } } else if (document.location.href.match('type=profile&company_id=')) { setTimeout("document.location.href = document.getElementsByClassName('content')[0].getElementsByTagName('table')[0].getElementsByTagName('a')[0].href;", randdelay); } else if (document.location.href.match('type=buy&ticker=')) { document.getElementsByName('amount_shares')[0].value = shares; setTimeout("document.forms[1].submit();", randdelay); } //go-to-location btn event listeners document.getElementById('goplushie').addEventListener('click', function(event){ document.location.href = "http://www.neopets.com/faerieland/tdmbgpop.phtml" },true) document.getElementById('gotomb').addEventListener('click', function(event){ document.location.href = "http://www.neopets.com/worlds/geraptiku/tomb.phtml" },true) document.getElementById('goomelette').addEventListener('click', function(event){ document.location.href = "http://www.neopets.com/faerieland/tdmbgpop.phtml" },true) document.getElementById('gostock').addEventListener('click', function(event){ document.location.href = "http://www.neopets.com/stockmarket.phtml?type=list&full=true" },true) document.getElementById('gobank').addEventListener('click', function(event){ document.location.href = "http://www.neopets.com/bank.phtml" },true) document.getElementById('gojelly').addEventListener('click', function(event){ document.location.href = "http://www.neopets.com/jelly/jelly.phtml" },true) document.getElementById('gotombola').addEventListener('click', function(event){ document.location.href = "http://www.neopets.com/island/tombola.phtml" }, true) document.getElementById('goslorg').addEventListener('click', function(event){ document.location.href = "http://www.neopets.com/shop_of_offers.phtml?slorg_payout=yes" }, true) document.getElementById('checkgmval').addEventListener('click', function(event){ console.log("CURRENT PREFERENCES: "); console.log(GM_getValue("dostock") + " : dostock"); console.log(GM_getValue("dobank") + " : dobank"); console.log(GM_getValue("doomelette") + " : doomelette"); console.log(GM_getValue("dojelly") + " : dojelly"); console.log(GM_getValue("dotomb") + " : dotomb"); console.log(GM_getValue("dotombola") + " : dotombola"); console.log(GM_getValue("doslorg") + " :doslorg"); }, true) //SAVEBTN.click document.getElementById('savebtn').addEventListener( 'click', function( event ) { console.log("SAVED PREFERENCES: "); if (document.getElementById('stockcheckbox').checked == true){ GM_setValue("dostock", true); } else { GM_setValue("dostock", false); } console.log(GM_getValue("dostock") + " : dostock"); if ( document.getElementById('bankintcheckbox').checked == true ) { GM_setValue("dobank", true); } else { GM_setValue("dobank", false); } console.log(GM_getValue("dobank") + " : dobank"); if (document.getElementById('jellycb').checked == true) { GM_setValue("dojelly", true); } else { GM_setValue("dojelly", false); } console.log(GM_getValue("dojelly") + " : dojelly"); if (document.getElementById('tombcb').checked == true) { GM_setValue("dotomb", true); } else { GM_setValue("dotomb", false); } console.log(GM_getValue("dotomb") + " : dotomb"); if (document.getElementById('plushiecb').checked == true) { GM_setValue("doplushie", true); } else { GM_setValue("doplushie", false); } console.log(GM_getValue("doplushie") + " : doplushie"); if (document.getElementById('tombolacb').checked == true){ GM_setValue("dotombola", true); } else { GM_setValue("dotombola", false); } console.log(GM_getValue("dotombola") + " : dotombola"); if (document.getElementById('slorgcb').checked == true){ GM_setValue("doslorg", true); } else { GM_setValue("doslorg", false); } console.log(GM_getValue("doslorg") + " : doslorg"); GM_setValue("mindelay", parseInt(document.getElementById('txtmindelay').value)); console.log(GM_getValue("mindelay") + " : mindelay"); GM_setValue("maxdelay", parseInt(document.getElementById('txtmaxdelay').value)); console.log(GM_getValue("maxdelay") + " : maxdelay"); }, true );
I spent more time researching it and understanding the aspects of it. Sadly, there is no function to serialize nodes of XPath :-( Thus, if I get <ObjectHTML...>, I can not extract the "innerHTML" (XML) of it. Would have been devilishly amazing if that was a function :-\ There is supposedly a collection of functions meant to deal with XML conversions -- hopefully including from xpath -- called XSLT. I'll look into it later to see if I can find a solution. If I do find a (working) solution, I'll post an explanation for others I was reading about the XSL functions here (I hope external link is allowed; it's too w3schools)