Cracking Banner

Moves cracking stats info into the top banner

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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