Racing Upgrades

desc

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Racing Upgrades
// @namespace    somenamespace
// @version      0.1
// @description  desc
// @author       tos
// @match        *.torn.com/loader.php?sid=racing
// @grant        none
// ==/UserScript==

var barWrap, barValues;
barWrap = document.getElementsByClassName('bar-wrap');
for(i=0; i < barWrap.length; i++){
    barValues = getBarValues(barWrap[i]);
    barWrap[i].setAttribute('title', barValues.grey +'% ('+ barValues.sign + (barValues.color - barValues.grey) +'%)');
}

const observer = new MutationObserver((mutations) => {
  for (const mutation of mutations) {
    for (const node of mutation.addedNodes) {
      if(node.className){
          var barWrap, barValues;
          if(node.className == 'pm-items-wrap'){
              barWrap = node.getElementsByClassName('bar-wrap');
              for(i=0; i < barWrap.length; i++){
                  barValues = getBarValues(barWrap[i]);
                  var modValue = barValues.color - barValues.grey;
                  modValue = +modValue.toFixed(2);
                  barWrap[i].setAttribute('title', barValues.sign + modValue +'%');
              }
          }
          if(node.className.includes('enlist-wrap') || node.className.includes('car-selected')){
              barWrap = node.getElementsByClassName('bar-wrap');
              for(i=0; i < barWrap.length; i++){
                  barValues = getBarValues(barWrap[i]);
                  barWrap[i].setAttribute('title', barValues.grey +'% ('+ barValues.sign + (barValues.color - barValues.grey) +'%)');
              }
          }
      }
    }
  }
});

const wrapper = document.querySelector('#racingAdditionalContainer');
observer.observe(wrapper, { subtree: true, childList: true });

function getBarValues(bar){
    var barValues = {};
    barValues.color = parseFloat(bar.querySelector('.bar-color-wrap-d').style.width.split('%')[0]);
    barValues.color = +barValues.color.toFixed(2);
    barValues.grey = parseFloat(bar.querySelector('.bar-gray-light-wrap-d').style.width.split('%')[0]);
    barValues.grey = +barValues.grey.toFixed(2);
    if(barValues.color === 0){
        barValues.color = barValues.grey;
    }
    barValues.sign = '+';
    if(bar.parentElement.parentElement.parentElement.className.includes('negative')) {
        barValues.sign = '-';
    }
    return barValues;
}