bazaarscript for avg and count added
This commit is contained in:
58
bazaar.user.js
Normal file
58
bazaar.user.js
Normal file
@@ -0,0 +1,58 @@
|
||||
// ==UserScript==
|
||||
// @name Bazaar Helper
|
||||
// @namespace https://jotde.eu
|
||||
// @updateURL https://github.com/Kivou-2000607/gym-formula/raw/master/js/gym.user.js
|
||||
// @version 0.1
|
||||
// @description try to take over the world!
|
||||
// @author JotDe:
|
||||
// @match https://www.torn.com/bazaar.php*
|
||||
// @grant GM.xmlHttpRequest
|
||||
// ==/UserScript==
|
||||
|
||||
|
||||
const callMarketApi = new Promise((resolve, reject) => {
|
||||
GM.xmlHttpRequest({
|
||||
method: "GET",
|
||||
url: "http://jotde.eu/api/market",
|
||||
onload: function(response) {
|
||||
if (response.status != 200) {
|
||||
reject(`HTTP Status ${response.status} ${response.statusText}: ${response.responseText}`);
|
||||
}
|
||||
resolve(JSON.parse(response.responseText));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
async function forElement(element) {
|
||||
while (!document.querySelector(element)) {
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
}
|
||||
}
|
||||
|
||||
async function changePlaceholder(marketItems) {
|
||||
|
||||
let itemList = document.querySelectorAll(selectedBazaarTab + " li");
|
||||
console.log(marketItems);
|
||||
itemList.forEach(item => {
|
||||
itemid = item.querySelector('img').getAttribute('src').split('/')[3];
|
||||
|
||||
marketItem = marketItems[itemid];
|
||||
if(marketItem){
|
||||
item.querySelector('div[class="amount"] input[type="text"]').setAttribute('placeholder', marketItem['count']);
|
||||
item.querySelector('div[class="price"] div[class^="input-money-group"] input[type="text"]').setAttribute('placeholder', marketItem['avg']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function writeErrorOnConsole(error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
async function run() {
|
||||
selectedBazaarTab = 'ul[class^="items-cont"][style="display:block;"]';
|
||||
await forElement(selectedBazaarTab);
|
||||
callMarketApi.then(changePlaceholder, writeErrorOnConsole);
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user