Cracking Banner

Moves cracking stats info into the top banner

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
})();