RyuFive / Bazaar/Auction Copy

// ==UserScript==
// @name         Bazaar/Auction Copy
// @match      https://www.torn.com/bazaar.php?userId=*
// @match      https://www.torn.com/amarket.php*
// @namespace    https://openuserjs.org/users/RyuFive/BazaarAuction_Copy
// @version      0.2
// @description  try to take over the world!
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @license MIT
// @grant GM_setClipboard
// ==/UserScript==

// ==OpenUserJS==
// @author RyuFive
// ==/OpenUserJS==

var once = true
var string = ""

var MutationObserver = window.MutationObserver;
var myObserver = new MutationObserver(mutationHandler);
var obsConfig = {
  childList: true,
  attributes: true,
  subtree: true,
  attributeFilter: ['class, style']
};

myObserver.observe(document, obsConfig);

function mutationHandler(mutationRecords) {

  mutationRecords.forEach(function (mutation) {
    if (mutation.type == "childList") {
      if (document.URL.includes("bazaar")) {
        var tooltip = mutation.addedNodes[0]
        if (tooltip && tooltip.className && tooltip.className == "items-list-wrap") {
          var person = document.querySelector(".right-round").innerHTML.split('>')[1].split('\'s')[0]
          var item_name = tooltip.getElementsByTagName('span')[2].innerHTML.split('>')[2].split('<')[0].split('The ')[1]

          var titles = tooltip.getElementsByClassName('title')

          for (let i = 0; i < titles.length; i++) {
            if (titles[i].innerText.includes('Quality')) var quality = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
            if (titles[i].innerText.includes('Accuracy')) var accuracy = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
            if (titles[i].innerText.includes('Damage')) var damage = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
            if (titles[i].innerText.includes('Armor')) var armor = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
            if (titles[i].innerText.includes('Bonus')) {
              var bonus = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
              var temp = titles[i].parentElement.getAttribute('title').split('br/>')[1].split('%')[0]
              if (typeof (temp) == "string") percent = temp
              else var percent = temp.split(' ')[temp.length - 1]
            }
          }
          var upperRow = tooltip.parentElement.parentElement.firstChild
          for (let j = 0; j < upperRow.childElementCount; j++) {
            var selection = upperRow.children[j]
            if (selection.classList.length > 2) var value = selection.getElementsByTagName('p')[1].innerText.split('$')[1]
          }
          if (once == false) string += ";"
          string = string + person + ',' + item_name + ',' + quality + ',' + accuracy + ',' + damage + ',' + armor + ',' + percent + ',' + bonus + ',' + value
          GM_setClipboard(string)
          once = false
        }
      }
      else {
        temp = mutation.addedNodes
        if (temp.length == 8) {
          tooltip = temp[6]

          person = tooltip.parentElement.parentElement.getElementsByClassName("name")[0].innerText.split(": ")[1]
          item_name = tooltip.parentElement.getElementsByClassName("bold")[0].innerText.split("The ")[1]

          titles = tooltip.getElementsByClassName('title')

          for (let i = 0; i < titles.length; i++) {
            if (titles[i].innerText.includes('Quality')) quality = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
            if (titles[i].innerText.includes('Accuracy')) accuracy = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
            if (titles[i].innerText.includes('Damage')) damage = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
            if (titles[i].innerText.includes('Armor')) armor = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
            if (titles[i].innerText.includes('Bonus')) {
              bonus = titles[i].parentElement.getAttribute('aria-label').split(' ')[1]
              temp = titles[i].parentElement.getAttribute('title').split('br/>')[1].split('%')[0]
              if (typeof (temp) == "string") percent = temp
              else percent = temp.split(' ')[temp.length - 1]
            }
          }
          value = tooltip.parentElement.parentElement.getElementsByClassName("c-bid-wrap")[0].innerText.split("$")[1]
          if (once == false) string += ";"
          string = string + person + ',' + item_name + ',' + quality + ',' + accuracy + ',' + damage + ',' + armor + ',' + percent + ',' + bonus + ',' + value
          GM_setClipboard(string)
          once = false
        }
      }
    }
  });
}