GC I Failed! Helper

Adds up losing stocks

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

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 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         GC I Failed! Helper
// @namespace    grundos.cafe
// @version      1.1
// @description  Adds up losing stocks
// @author       Sphere
// @match        https://www.grundos.cafe/games/stockmarket/portfolio/
// @grant        none
// ==/UserScript==

(() => {
  
  const rows = document.querySelectorAll('.portfolio-subtable tbody tr');
  const sellButton = document.querySelector('#show_sell');
  
  let maxLoss = 0;
  const negativeRows = [];
  
  rows.forEach(row => {
    const paid = parseInt(row.querySelector('td:nth-of-type(3)').textContent.replace(/,/g, ''), 10);
    const current = parseInt(row.querySelector('td:nth-last-of-type(3)').textContent.replace(/,/g, ''), 10);
    
    if (current < paid) {
      maxLoss += paid - current;
      negativeRows.push(row);
    }
  });
  
  const p = document.createElement('p');
  p.textContent = 'Possible loss: ';
  
  const strong = document.createElement('strong');
  strong.textContent = `${maxLoss.toLocaleString()} NP `;
  p.appendChild(strong);
  
  const button = document.createElement('input');
  button.classList.add('form-control');
  button.type = 'button';
  button.value = 'Select losing shares';
  button.addEventListener('click', event => {
    for (const row of negativeRows) {
      const shares = parseInt(row.querySelector('td').textContent.replace(/,/g, ''), 10);
      const input = row.querySelector('input');
      input.value = `${shares}`;
      
      row.parentNode.parentNode.parentNode.parentNode.style.removeProperty('display'); // lol
    }
    sellButton.style.removeProperty('display');
  });
  p.appendChild(button);
  
  const form = document.querySelector('main form');
  form.parentNode.insertBefore(p, form);
  
})();