Last active
October 6, 2021 00:03
-
-
Save jdtech3/833f17354669530d95fd0dbb5f443830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Torn Bazaar Item IDs | |
// @namespace https://j0e.ca/ | |
// @version 0.3 | |
// @description Displays item IDs in the Bazaar | |
// @author JDTech | |
// @match https://www.torn.com/bazaar.php* | |
// @grant GM_log | |
// ==/UserScript== | |
function injectIDs() { | |
GM_log("Injecting item IDs") | |
// Grab the elements | |
let elems = document.querySelectorAll("[class*=imgBar___]") | |
let item_ids = [] | |
for (let elem of elems) { | |
// Grab item ID | |
let img_link = elem.getElementsByTagName('img')[0].src | |
let item_id = img_link.split('/')[5] | |
item_ids.push(item_id) | |
// Add item ID next to name (kinda janky, but works) | |
let name_elem = elem.nextSibling.firstChild | |
name_elem.innerHTML += ' <span style="color: blue; font-weight: bold">[' + item_id + ']</span>' | |
} | |
// Add list of all item ids to end of bazaar interface | |
//let container_elem = document.querySelector("[class*=itemsContainner___]") | |
let elem_marker = document.querySelector("[class*=devider__]") | |
item_ids = item_ids.join() | |
elem_marker.insertAdjacentHTML("afterend", '<p style="color: blue; font-weight: bold; margin-top: 10px; margin-bottom: 10px;">All IDs: ' + item_ids + '</p><hr class="devider___3aCZ5">'); | |
GM_log("Done injecting item IDs") | |
} | |
(function() { | |
'use strict'; | |
// set up the mutation observer | |
var observer = new MutationObserver(function (mutations, me) { | |
// Use something random to check for page load | |
let test_elem = document.querySelector("[class*=itemDescription___]") | |
if (test_elem) { | |
injectIDs() | |
me.disconnect() // stop observing | |
return | |
} | |
}); | |
// start observing | |
observer.observe(document, { | |
childList: true, | |
subtree: true | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment