Call me out as much as possible? All critisim/help apreciated. What exactly am I doing wrong? Code (Text): // ==UserScript== // @name Test // @namespace Test // @description Test // @include http://www.google.com/ // ==/UserScript== var add = document.createElement("button"); add.textContent= "View Todays Comic!"; add.addEventListener("click", function() { window.open('http://www.explosm.net/comics/1772/') } Doesn't make a button on google, doesnt do anything actually. So what am I doing wrong? Thanks :-D
Try this ; Code (Text): table = document.evaluate('//td[@class="navtd"]/font[@class="navtd"]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0); //assuming there is exactly one table var button = document.createElement("a"); button.href = "http://google.com"; // your link here var image = document.createElement("img"); image.src = "http://whatever.com/image.jpg"; // your button source here button.appendChild(image); table.appendChild(button);
So I put that as: Code (Text): // ==UserScript== // @name test // @namespace z // @description test // @include * // ==/UserScript== table = document.evaluate('//td[@class="navtd"]/font[@class="navtd"]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0); //assuming there is exactly one table var button = document.createElement("a"); button.href = "http://explosm.net"; // your link here var image = document.createElement("img"); image.src = "http://btc.montana.edu/ceres/html/Polar/images/circle.jpg"; button.appendChild(image); table.appendChild(button); Nothing happened...? (I made a random circle the img source)
You need to put the button on the page and you need to do that before you try to add an event listener Code (Text): // ==UserScript== // @name Test // @namespace Test // @description Test // @include http://www.google.com/ // ==/UserScript== var add = document.createElement("button"); add.innerHTML = "View Todays Comic!"; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("click", function() { window.open('http://www.explosm.net/comics/1772/');}, false }
you forget to add }, false) in the end.. try= Code (Text): // ==UserScript== // @name Test // @namespace Test // @description Test // @include http://www.google.com/ // ==/UserScript== var add = document.createElement("button"); add.value = "View Todays Comic!"; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("click", function() {window.open('http://www.explosm.net/comics/1772/');}, false) Do you have console² instaled on your firefox? if you don´t, please do me a favor, install that. https://addons.mozilla.org/en-US/firefox/addon/1815 click ctrl + shift +j and look at console and check for errors.
Alrighty. Now I got a tiny lil button. How do I make it big? Suggestions? PS: This is a rolling project learning experience XD (Writing your suggestions down in notepad to learn lol)
you wanna a big button? like, "click here to open a new page"? Try: Code (Text): // ==UserScript== // @name Test // @namespace Test // @description Test // @include http://www.google.com/ // ==/UserScript== var add = document.createElement("input"); add.type = "button"; add.value = "View Todays Comic!"; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("click", function() {window.open('http://www.explosm.net/comics/1772/');}, false)
If you use createElement button then you should use innerHTML If you use createElement input then the type is button and the value is the button text. Code (Text): var add = document.createElement("button"); add.innerHTML = "View Todays Comic!"; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("click", function() { window.open('http://www.explosm.net/comics/1772/'); }, false)
Could I make the button have, inside the innerhtml thing, a picture? like.. .... add.innerHTML = <img src="http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg", border = 0">; .... You guys pwn btw! Thanks, Fexxel
Well, you can´t make the image inside the button (sorry i didn´t say that before...) But you can make a DIV. Code (Text): // ==UserScript== // @name Test // @namespace Test // @description Test // @include http://www.google.com/ // ==/UserScript== var add = document.createElement("div"); add.innerHTML = "<img src='http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg', border = '0'>"; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {window.open('http://www.explosm.net/comics/1772/');}, false) Or you can creat a image too... Code (Text): // ==UserScript== // @name Test // @namespace Test // @description Test // @include http://www.google.com/ // ==/UserScript== var add = document.createElement("img"); add.src = "http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg"; add.style.border = '0'; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {window.open('http://www.explosm.net/comics/1772/');}, false) Try it yourself...
Alrighty, (+Rep'd btw) So I now know how to make a button and an image that clicks to a webpage. And say I wanted to make the img smaller: Code (Text): var add = document.createElement("div"); add.innerHTML = "<img src='http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg', length = '100' width = '100' border = '0'>"; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {window.open('http://www.explosm.net/comics/1772/');}, false) Correct? and if I wanted it to click to be smaller I could.. Code (Text): var add = document.createElement("div"); add.innerHTML = "<img src='http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg', border = '0'>"; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {"<img src=http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg', length = '100' width = '100' border = '0'>";}, false) Now if I wanted to put the img somewhere else... (Lets move to neopets.com shall we?) How would I put it say, in the left side, or say, in the top left corner of the page? You said you use "document.body.appendchild(add);" and mentioned other methods. What other methods are there, and which ones the easiest to use (in terms of moving the object to diff. places) Thanks SOO MUCH Steinn! I will dedicate meh progs to youz!!!, Fexxel
if you wanna a smaller image, don´t use innertHTML = "img width height" use, style.width, style.height like: Code (Text): var add = document.createElement("img"); add.src = "http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg" add.style.width = "100px" add.style.height = "100px" add.style.border = "0"; document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {window.open('http://www.explosm.net/comics/1772/');}, false) If you wanna rezise the image when you click, use the code: Code (Text): var add = document.createElement("img"); add.src = "http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg" document.body.appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {this.style.width="100px"; this.style.height="100px";}, false) For place the image in somewhere, you have to "attack" an object. For example if you wanna place the image in sider bar of neopets: Use the code: Code (Text): var add = document.createElement("img"); add.src = "http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg" document.getElementsByClassName( 'sidebar' )[0].appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {this.style.width="100px"; this.style.height="100px";}, false) you saw the "getElementsByClassName('siderbar')[0]? So, you will ad the image in the sidebar.. If you wanna add the image in the top, you can use: Code (Text): var add = document.createElement("img"); add.src = "http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg" var place = document.getElementById( 'content' ); place.parentNode.insertBefore(add, place);// you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {this.style.width="100px"; this.style.height="100px";}, false) Just know how to attack an element. Look at another scripts and search how they attack that elements... what do you wanna creat? I can help you...
So I could do... Code (Text): var add = document.createElement("img"); add.src = "http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg" document.getElementsByClassName( 'bottom' )[0].appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {this.style.width="100px"; this.style.height="100px";}, false) or Code (Text): var add = document.createElement("img"); add.src = "http://hoox.files.wordpress.com/2008/02/cyanide-and-happiness-pizza.jpg" document.getElementsByClassName( 'top' )[0].appendChild(add); // you can use other methods to place the button where you like. add.addEventListener("mouseover", function() {this.style.cursor="pointer";}, false) // this will fake a link, since, when you click, a new tab will open add.addEventListener("click", function() {this.style.width="100px"; this.style.height="100px";}, false) ? Alright, looks like I needa learn how to attack that thing XD. Could I find the name of the places in the html source of the page? Anyways, I was just doing this for general knowledge but.. I have an idea An igloo helper. Theres a button in the sidebar that says "Check the Igloo!", and when you get there it sets the url from... http://www.neopets.com/winter/igloo.phtml to http://www.neopets.com/winter/igloo2.phtml (You can't directly go to http://www.neopets.com/winter/igloo2.phtml because you need the refferal of igloo.phtml...) --OR-- A button that flashes when its 3 seconds before the jobs are going to refresh (xx:09:57 NST) and makes an alert (I figured out how to do that btw XD) saying "Visit job page! about to refresh!!!" And then when you click the button it brings you to the basic jobs so you can grab one. Good? -Added the Style.width and width px thing to notes, as well as 'sidebar'[0]- YOU ROX!!!! <3 I'll +Rep you ASAP.. Fexxel
Install the script mason, he change the refferal... i change the whole refferal from neopets (i guess). https://addons.mozilla.org/en-US/firefox/addon/10636 There is an tutorial on this script that shows how to install and config mason: http://userscripts.org/scripts/show/54076 just change the snowager for igloo. ---- Yes you can attack in that way... Search on google for "xpath", "document.getElements" than you learn how to attack an element. Don´t forget to install firebug, console² and xpath checker. (search at addons.mozzila.) --- About the jobs warning, i´m studying how to do that.. it´s not too hard, i know how to get neopian time... So i just need time to do that, finish my actual scripts... Will open a new page when the employment is done. Also checks if you´re make all jobs... I was think aabout one that grabbs the best job too.. ---- I don´t like to change neopets layout, TNT can check if you´re doing or not, so, it´s not good.
-About the layout changing: Then can you put it in the side bars? (Not the sidebar, but outside the neopets layout. the grey area when you maximize the screen with a large computer. -Oof, I'm not at the stage where I can handle grabbing the best job . I'd like to make a script something like this though... WEll, I'll do this in rough vb.net... if strhtml.contains("10:00") then w.request("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic") end if if strhtml.contains("20:00").. ect... I have absolutely no idea how to do that in javascript... ---- As for xpath, I didnt find anything on google... What I gathered was that it's for looking through XML files... And then you do that line of code you said... "document.getElements" to get the elements (like sidebar)? EDIT: OOH! FOUND A NICE TIDBIT! Code (Text): if (document.body.innerHTML.indexOf("xxx")>-1) {action} So I could make that... Code (Text): // ==UserScript== // @name Neopets Job Navigator // @namespace http://userscripts.org // @description at 10:00 NST, 20:00 NST, 30:00 NST, 40:00 NST, 50:00 NST and 00:00 NST you are brought to the basic jobs page of neopets.com // @author Steinn+Fex Fo' Life! // @include http://*.neopets.com/* // @exclude http://images.neopets.com/* // @exclude http://*.neopets.com/ads* // ==/UserScript== if (document.body.innerHTML.indexOf("10:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("20:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("30:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("40:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("50:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("00:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("10:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("20:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("30:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("40:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("50:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("00:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} end if I think I might need something to go before the if part... A before statement thing.
Well, if domain is http://www.neopets.com they can see if you change the layout or not.. they are not checking this now, but, someday... chelsa ask me that, so, look my answer (i don´t wanna write again ) Well, a big friend mine creat this function... You can get the actual time, the exactly time when you call the function. keep the instructions and you will understand. First, add in the header of the script the code: Code (Text): // @require http://userscripts.org/scripts/source/54000.user.js Should stay something like that: Code (Text): // @name test // @namespace Steinn // @description test // @require http://userscripts.org/scripts/source/54000.user.js // @include *neopets.com* It´s really important you add this... (here´s where the function is lol) after you add this part, SAVE the script on your computer, in somewhere like, my documents. After save, open again in the browser and install... You can upload the script in some page and install. But the most important, its the part when you install him again. If you didn´t do this part, the script doesn´t work... Now its just you get the time: Code (Text): var nst = NeopetsDocument.Time(true); //this will get time whole tim and date var h = nst.getHours(); // this will get hours var m = nst.getMinutes(); // minutes var s = nst.getSeconds(); // seconds alert(h + ":" + m + ":" + s); // alert for see the result. Like a told you, i dindn´t creat this script. This guy create: http://userscripts.org/users/wesley This is the script: http://userscripts.org/scripts/show/54000 Like license is GNU GPL, you can copy the code If you really wanna study, you have to read a lot... Look at this pages: http://www-xray.ast.cam.ac.uk/~jgraham/ ... orial.html I can teach you somethings, cause there´s any good tutorial for learn that... Look, How to attack sidebar using getelements: Code (Text): document.getElementsByClassName("sidebar")[0]; // its important you add this 0. he shows what element he wants to attack. if its the first, the second, thirt... Now look how to attack using xPATH: Code (Text): document.evaluate("//td[@class='sidebar']",document,null,8,null).singleNodeValue; Or Code (Text): document.evaluate("/html/body/div/div[3]/table/tbody/tr/td/div[3]/table/tbody/tr/td",document,null,8,null).singleNodeValue; Use the best option to attack don´t forget, you have to install firebug, xpath checker, console²
Sorry double post but i need... About you code, so, what happend if its: 22:01? The script will not work....
The employment agency restocks its jobs at 10:00, 20:00, 30:00, ect.. (every 10 minutes)... You don't need 22:01. --- As for xpath: I couldn't find xpath finder but I found xpath Checker... https://addons.mozilla.org/en-US/firefox/addon/1095 I put it on my firefox, along with firebug and console. (Console is awesome by the way) -- Code (Text): if (document.body.innerHTML.indexOf("10:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("20:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("30:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("40:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("50:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("00:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("10:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("20:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("30:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("40:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("50:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} else if (document.body.innerHTML.indexOf("00:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");} end if So It won't work?... Edit: Tested the script, it doesn't work!!! According to console, I need something in the beggining... before the if part..