-
-
Save dotcomboom/9d8e33304ff1e8ce3250bc5a1a8c956b to your computer and use it in GitHub Desktop.
// ==UserScript== | |
// @name Neopets: Shop Stock Pricer | |
// @namespace http://lince.somnolescent.net | |
// @version 0.2 | |
// @description This script lets you scrape JellyNeo for prices on the shop stock page. Does not auto-submit or otherwise automate activities, though it does send a bunch of search requests to JN when run. Use at your own risk. | |
// @author metalynx | |
// @match http://www.neopets.com/market.phtml?order_by=id* | |
// @match http://www.neopets.com/market.phtml?type=your* | |
// @icon https://www.google.com/s2/favicons?domain=neopets.com | |
// @require https://cdn.jsdelivr.net/npm/axios@~0.21.1/dist/axios.min.js | |
// @require https://cdn.jsdelivr.net/npm/axios-userscript-adapter@~0.1.2/dist/axiosGmxhrAdapter.min.js | |
// @grant GM.xmlHttpRequest | |
// @grant GM_setValue | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let offset = -5 // increase/decrease prices a fixed amount | |
let minprice = 1 | |
console.log(axios.defaults.adapter); | |
axios.defaults.adapter = axiosGmxhrAdapter; | |
let forms = document.getElementsByTagName('form') | |
for (let i = 0; i < forms.length; i++) { | |
if ((forms[i].action) == 'http://www.neopets.com/process_market.phtml') { | |
var form = forms[i]; | |
break | |
} | |
} | |
var node = document.createElement('a') | |
node.href = '#autoprice' | |
node.setAttribute('id', 'autoprice') | |
var textnode = document.createTextNode(" >>") | |
node.appendChild(textnode); | |
form.getElementsByTagName('td')[4].appendChild(node); | |
node.onclick = function(){ | |
document.getElementById("autoprice").remove() | |
let rows = form.getElementsByTagName('tr') | |
for (let i = 1; rows.length - 1; i++) { // index is set to 1 to skip the header row "Name", goes to the index just before the bottom Update/Remove All row | |
let item = rows[i].getElementsByTagName('b')[0].innerHTML | |
let pricebox = rows[i].getElementsByTagName('input')[2] | |
//console.log(item + ' is currently set to ' + pricebox.value + ' NP') | |
axios.get('https://items.jellyneo.net/search/?name=' + item.replace(' ', '+') + '&name_type=3').then(res => { | |
let parser = new DOMParser() | |
let doc = parser.parseFromString(res.data, 'text/html') | |
let links = doc.getElementsByTagName('a') | |
let price = 0 | |
for (let i = 1; i < links.length - 1; i++) { | |
if (links[i].className == 'price-history-link') { | |
price = parseInt(links[i].innerHTML.replace(',', '').replace(' NP', '')) | |
break | |
} | |
} | |
console.log('JN PRICE: ' + price + ' NP (' + item + ')') | |
pricebox.setAttribute('value', Math.max(minprice, price += offset)) | |
}); | |
} | |
} | |
})(); |
Heyo, just wanna leave a note that due to NoNeoNFTs you'll need to go to JN's site and click through the message to return to Jellyneo. That'll place a cookie so the script can access the site instead of mistakenly setting all the prices to 1. As this is a time-sensitive thing (and yeah, I'll suppose I agree NFTs are a particularly lazy way for TNT to fund the site's development) I'm not updating the script to bypass it.
I'm not sure what changed, but the script doesn't seem to run anymore. I'm still learning JS, so I am unsure what the issue might be.
I also had this issue and after a little digging, I found that the script had added the URLs for the shop stock pages into user excludes for some reason in Tampermonkey's settings. I'd check that and remove any URLs out of the User Excludes section, if there are any.
It has something to do with the error on the side I think. Axios is not defined?
Has something to do with these two lines:
console.log(axios.defaults.adapter);
axios.defaults.adapter = axiosGmxhrAdapter;
I saw that error while digging, but I believe that error appears in Tampermonkey because axios is defined when the script actually runs, not in that window where it's being inspected. There are 2 @require js libraries pointing to axios code at the top, and they seem to be operational.
Just my experience, but I still have the axios error shown, but by emptying my user excludes for the script and preventing automatic updates, it has worked just fine for me.
Figured it out. I'm dumb.
Not only do you have to change http to https in lines 7 and 8, you also have to do it in line 27.
Works beautifully on Firefox with Greasemonkey as of August 2021 😊👍