Torn - Alert for shoplifting uniques

Watches for shoplifting uniques and makes LOUD NOISE when found.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Torn - Alert for shoplifting uniques
// @namespace    http://www.countlesscircles.com
// @version      2025.4
// @description  Watches for shoplifting uniques and makes LOUD NOISE when found.
// @author       Tokuki
// @license      GNU GPLv3
// @match        https://www.torn.com/page.php?sid=crimes*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const found = [];

    const audio = new Audio('https://files.catbox.moe/opm43i.mp3');
    audio.volume = 0.5;

    let storeElements = undefined;
    let audioTimeout = undefined;

    setInterval(() => {
        storeElements = document.querySelectorAll('.shoplifting-root .virtualList___noLef .virtual-item');
        if (storeElements.length === 0) {
            // The Shoplifting element isn't found - not the right page.
            return;
        }

        for (const [key, storeElement] of storeElements.entries()) {
            const uniqueContainer = storeElement.querySelector('[class^="uniqueStars"]');

            if (uniqueContainer.innerHTML) { // Unique found for this store!
                if (!found[key]) { // Check if we've already alerted the user of this instance.
                    // Logging it in the console, so I can see if I missed any while away.
                    console.log('Found a unique!');

                    // Stop and reset any existing audio playing
                    clearTimeout(audioTimeout);
                    audio.pause();
                    audio.currentTime = 0;

                    // SCREAM
                    audio.play();

                    // Mark that we found it, and already played the audio for this one.
                    found[key] = true;

                    // Stop the audio after a set time, because the audio file is long and annoying.
                    audioTimeout = setTimeout(() => {
                        audio.pause();
                    }, 4000);
                }
            } else { // No unique found for this store
                // Reset the found status, so that if a Unique went away, it can be re-triggered.
                found[key] = false;
            }
        }
    }, 1000);
})();