Torn - Bigger active chain timer

Make the chain timer larger only while it is actively counting down

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Torn - Bigger active chain timer
// @namespace    LordTiny.torn.bigger-active-chain-timer
// @version      1.1.2
// @description  Make the chain timer larger only while it is actively counting down
// @author       LordTiny [4036444]
// @match        https://www.torn.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @license      MIT
// @grant        none
// ==/UserScript==
 
(() => {
  'use strict';
 
  const STYLE_ID = 'bigger-active-chain-timer-style';
  const BIG_CLASS = 'chain-timer-big';
  const WARNING_CLASS = 'chain-timer-warning';
  const FLASH_CLASS = 'chain-timer-flash';
 
  function addStyle() {
    if (document.getElementById(STYLE_ID)) return;
 
    const style = document.createElement('style');
    style.id = STYLE_ID;
    style.textContent = `
      .${BIG_CLASS} {
        font-size: 60px !important;
        line-height: 1 !important;
        height: 62px !important;
        margin-top: 10px !important;
        margin-left: -70px !important;
      }

      .${WARNING_CLASS} {
        color: yellow !important;
        text-shadow: -3px -3px 5px rgba(255, 255, 0, .15), 3px 3px 5px rgba(255, 255, 0, .15) !important;
      }

      @keyframes subtleUrgentPulse {
        0% {
          transform: scale(1);
        }
        50% {
          transform: scale(1.08);
        }
        100% {
          transform: scale(1);
        }
      }

      .${FLASH_CLASS} {
        display: inline-block !important;
        transform-origin: center center !important;
        animation: subtleUrgentPulse 0.75s infinite !important;
      }
    `;
    document.head.appendChild(style);
  }
  
  function getSecondsRemaining(text) {
    const parts = text.trim().split(':');
    if (parts.length === 2) {
      const minutes = parseInt(parts[0], 10);
      const seconds = parseInt(parts[1], 10);
      if (!isNaN(minutes) && !isNaN(seconds)) {
        return (minutes * 60) + seconds;
      }
    }
    return null;
  }
  
  
    
 
  function isActiveTimerText(text) {
    const trimmed = text.trim();
 
    // Treat empty, zero, and common zero-time formats as inactive.
    return trimmed !== ''
      && trimmed !== '0'
      && trimmed !== '00'
      && trimmed !== '0:00'
      && trimmed !== '00:00'
      && trimmed !== '00:00:00';
  }
 
  function getTimerElement() {
    // Torn uses generated class names, so match on the stable class prefix instead of the whole class.
    return document.querySelector('[class*="bar-timeleft"]');
  }
 
  function updateTimerSize() {
    const timer = getTimerElement();
    if (!timer) return;

    const isActive = isActiveTimerText(timer.textContent);
    const secondsLeft = getSecondsRemaining(timer.textContent);
    const shouldWarn = isActive && secondsLeft !== null && secondsLeft <= 60 && secondsLeft > 30;
    const shouldFlash = isActive && secondsLeft !== null && secondsLeft <= 15;

    timer.classList.toggle(BIG_CLASS, isActive);
    timer.classList.toggle(WARNING_CLASS, shouldWarn);
    timer.classList.toggle(FLASH_CLASS, shouldFlash);
  }
 
  function start() {
    addStyle();
    updateTimerSize();
 
    const observer = new MutationObserver(updateTimerSize);
 
    observer.observe(document.body, {
      childList: true,
      subtree: true,
      characterData: true
    });
  }
 
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', start);
  } else {
    start();
  }
})();