Cracking Banner

Moves cracking stats info into the top banner

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
})();