Skip to content
TORNLIFE More

[Userscript] Larger Chain Timer

Started by Annosz [2896714] on in Tools & Userscripts.

8 replies · 952 views · thread synced · 5 days ago · View on torn.com
About this thread

Posts archived: 9 / 9 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
9
Discussion span
→
People posting
7
Likes on archived posts
24
Authority score
37 / 100
Historical score
35 / 100
Story score
47 / 100
Engagement score
62 / 100
Annosz [2896714]
Can be very helpful while guarding, even if other tools (like chain alerts) are in use. Simply makes the chain timer larger and more visible.

This is something that I always did by tinkering with the CSS anyways, but it's way easier to use this way - and it was a great exercise as a first-timer in scripting :)

[image: i.imgur.com]

Only active while a chain is going on, will not change the layout on cooldown or without a chain. Naturally it's not PDA compatible, as you don't see the timer there.

Download it and install with Tampermonkey: https://github.com/Annosz/torn-userscripts/raw/main/larger_chain_timer.user.js
Zeus01 [386249]

This is a pretty useful script. It was working fine for awhile and now this error message shows up and no longer works for me. Is there a way I can fix this issue? A solution for this would be great, Thanks -  eslint: no-undef - 'wait for key elements' is not defined. 

sleek [3900953]

Hi, I tried this script & it wasn't working for me. (Most probably coz Ched & team have changed the class names to various elements).

 

I tried resolving it.

Here is my bug fix for the main code:

 

// ==UserScript==
// @name         Chain Timer
// @namespace    sleek.script.chain_timer
// @version      3.2
// @description  Enlarges chain timer and colors from green to red as time runs out.
// @author       sleek
// @match        https://www.torn.com/*
// @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// ==/UserScript==

// Changelog:
// v1.0 - Initial release. Hardcoded class names for chain timer elements. (By Annosz [2896714] from Github)
// v2.0 - Added dynamic colors to better visualize the chain timer. (By Vassilios [2276659])
// v3.0 - Replaced hardcoded class names with structural DOM traversal anchored on Chain:
// v3.1 - Added check to reset elements if chain count is < 10
// v3.2 - Added cooldown detection via progress div classList and absent speed element.
//         resetStyles() now fires when chain enters cooldown state.

(function () {
    'use strict';

    let initialized = false;

    function resolveChainElements() {
        const chainLabel = [...document.querySelectorAll('p')].find(
            el => el.textContent.trim() === 'Chain:'
        );
        if (!chainLabel) return null;

        const barStats = chainLabel.parentElement;
        const allP = barStats.querySelectorAll('p');
        const barValue = allP[1];
        const timeLeft = allP[allP.length - 1];
        const chainBar = barStats.parentElement;

        const progressDiv = [...chainBar.children].find(el =>
            el !== barStats &&
            [...el.classList].some(cls => cls.toLowerCase().startsWith('progress'))
        ) ?? null;

        const speed = [...chainBar.children].find(el =>
            el !== barStats &&
            el.tagName === 'DIV' &&
            el.querySelector('span')?.textContent.trim().startsWith('x')
        ) ?? null;

        const tickList = chainBar.querySelector('ul');

        return { barStats, barValue, timeLeft, speed, progressDiv, tickList };
    }
    function getChainCount(barValue) {
        return parseInt(barValue.textContent.trim()) || 0;
    }

    function isInCooldown(els) {
        const hasCooldownClass = els.progressDiv
            ? [...els.progressDiv.classList].some(cls => cls.toLowerCase().includes('cooldown'))
            : false;
        return hasCooldownClass || els.speed === null;
    }

    function applyStyles(els) {
        const { barStats, timeLeft, speed, tickList } = els;
        barStats.style.display = 'block';
        timeLeft.style.fontSize = '60px';
        timeLeft.style.height = '62px';
        if (speed) speed.style.top = 'unset';
        if (tickList) tickList.style.height = '8px';

        const text = timeLeft.textContent.trim();
        if (!text.includes(':')) return;
        const [m, s] = text.split(':').map(Number);
        const ratio = Math.max(0, Math.min(1, ((m * 60 + s) || 0) / 300));
        timeLeft.style.color = `rgb(${Math.round(255 * (1 - ratio))},${Math.round(255 * ratio)},0)`;
    }

    function resetStyles(els) {
        const { barStats, timeLeft, speed, tickList } = els;
        barStats.style.display = '';
        timeLeft.style.fontSize = '';
        timeLeft.style.height = '';
        timeLeft.style.color = '';
        if (speed) speed.style.top = '';
        if (tickList) tickList.style.height = '';
    }

    function actionFunction(jNode) {
        if (jNode[0].textContent.trim() !== 'Chain:') return;
        if (initialized) return;
        initialized = true;

        const els = resolveChainElements();
        if (!els) return;

        const tick = () => {
            if (isInCooldown(els) || getChainCount(els.barValue) < 10) {
                resetStyles(els);
            } else {
                applyStyles(els);
            }
        };

        tick();
        setInterval(tick, 1000);
    }

    waitForKeyElements('p', actionFunction);

})();


If it's not working, please comment, I will try to resolve it.

Thanks.

Mentions: Annosz [2896714] · Vassilios [2276659]

Annosz [2896714]

Hey guys!
Sorry, I am not big on following up on forum posts and I actually had no idea so many people use this script. Luckily Zeus01 reached out to me and I finally got around to update it. New version should work again.

Thanks for all the activity!