Cracking Banner

Moves cracking stats info into the top banner

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         Cracking Banner
// @namespace    https://www.torn.com/
// @version      1.0.1
// @match        https://www.torn.com/page.php?sid=crimes*
// @author       M00SE
// @description  Moves cracking stats info into the top banner
// @license      MIT
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  function clean(text) {
    return (text || '').replace(/\s+/g, ' ').trim();
  }

  function getRows(stats) {
    return Array.from(stats.querySelectorAll('.statistic___zH4MM')).map(row => {
      const label = clean(row.querySelector('.label___k42ll')?.textContent);
      const value = clean(row.querySelector('.value___FmWPr')?.textContent);
      return { label, value };
    }).filter(row => row.label && row.value);
  }

  function drawPanel(panel, rows) {
    panel.innerHTML = rows.map(row => `
      <div style="display: flex; justify-content: space-between; gap: 8px; line-height: 1.25;">
        <span style="color: #ccc;">${row.label}</span>
        <span style="color: #fff; font-weight: bold; text-align: right;">${row.value}</span>
      </div>
    `).join('');
  }

  setInterval(() => {
    const stats = document.querySelector('.statistics___jmn48:not(#cracking-stats-copy)');
    const banner = document.querySelector('.currentCrime___MN0T1 > .bannerArea___bnT7m');

    if (!stats || !banner) return;

    let panel = document.querySelector('#cracking-stats-copy');

    if (!panel) {
      panel = document.createElement('div');
      panel.id = 'cracking-stats-copy';

      panel.setAttribute(
        'style',
        'position: absolute; top: 50%; left: 24%; transform: translate(-50%, -50%); z-index: 999999; background: rgba(0,0,0,0.85); color: white; padding: 6px 8px; width: 260px; max-width: 42%; box-sizing: border-box; font: 11px Arial, sans-serif; border-radius: 4px;'
      );

      banner.style.position = 'relative';
      banner.appendChild(panel);
    }

    drawPanel(panel, getRows(stats));
  }, 1000);
})();