From 1177e2305ecd8920643589b95fc28c6433170933 Mon Sep 17 00:00:00 2001 From: JotDe Date: Sun, 3 May 2020 23:26:33 +0200 Subject: [PATCH] bazaarscript for avg and count added --- bazaar.user.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 bazaar.user.js diff --git a/bazaar.user.js b/bazaar.user.js new file mode 100644 index 0000000..86090f4 --- /dev/null +++ b/bazaar.user.js @@ -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(); \ No newline at end of file