Skip to content

Instantly share code, notes, and snippets.

@jdtech3
Last active October 6, 2021 00:03
Show Gist options
  • Save jdtech3/833f17354669530d95fd0dbb5f443830 to your computer and use it in GitHub Desktop.
Save jdtech3/833f17354669530d95fd0dbb5f443830 to your computer and use it in GitHub Desktop.
// ==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