Shoplifting alert

Guard Notifier

目前為 2023-09-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Shoplifting alert
// @namespace    Phantom Scripting
// @version      0.2
// @description  Guard Notifier
// @author       ErrorNullTag
// @match        www.torn.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// @license      GPU AGPLv3
// ==/UserScript==

(function() {
    'use strict';

    let apiKey = GM_getValue('shoplifting_api_key', '');
    if (!apiKey) {
        apiKey = prompt('Enter your API key:');
        GM_setValue('shoplifting_api_key', apiKey);
    }

    function displayAlertBox(camera = false, guard = false) {
    let alertBox = document.getElementById('alertBox');
    if (!alertBox) {
        alertBox = document.createElement('div');
        alertBox.id = 'alertBox';
        alertBox.style.position = 'fixed';
        alertBox.style.right = '0';
        alertBox.style.top = '0';
        alertBox.style.width = '280px';
        alertBox.style.height = '150px';
        alertBox.style.backgroundColor = 'black';
        alertBox.style.zIndex = '99999999';
        alertBox.style.display = 'flex';
        alertBox.style.flexDirection = 'column';
        alertBox.style.justifyContent = 'center';
        alertBox.style.alignItems = 'center';
        alertBox.style.fontFamily = 'Arial, sans-serif';
        alertBox.style.padding = '10px';
        alertBox.style.border = '2px solid gold';
        document.body.appendChild(alertBox);
    }

    // Clear the content to update it
    alertBox.innerHTML = '';

    const title = document.createElement('div');
    title.innerHTML = "Phantom Scripting";
    title.style.color = 'gold';
    title.style.fontWeight = 'bold';
    title.style.marginBottom = '20px'; // Increased spacing
    title.style.fontSize = '26px'; // Slightly bigger for prominence
    alertBox.appendChild(title);

    const cameraStatus = document.createElement('div');
    cameraStatus.innerHTML = camera ? "Camera: Offline" : "Camera: Online";
    cameraStatus.style.color = camera ? 'limegreen' : 'red'; // Changed green to limegreen for better visibility
    cameraStatus.style.fontWeight = 'bold';
    cameraStatus.style.borderBottom = '1px solid white'; // Added subtle border
    cameraStatus.style.paddingBottom = '5px'; // Padding for the border
    cameraStatus.style.fontSize = '20px'; // Bigger font size for better readability

    const guardStatus = document.createElement('div');
    guardStatus.innerHTML = guard ? "Guards: Gone" : "Guards: On duty";
    guardStatus.style.color = guard ? 'limegreen' : 'red';
    guardStatus.style.fontWeight = 'bold';
    guardStatus.style.fontSize = '20px';

    alertBox.appendChild(cameraStatus);
    alertBox.appendChild(guardStatus);

    if (camera && guard) {
        alert("Time to mug Big Al's!");
    }
}


    function fetchAndDisplayData() {
        fetch(`https://api.torn.com/torn/?selections=shoplifting&key=${apiKey}`)
            .then(response => response.json())
            .then(data => {
                    const camera = data.shoplifting.big_als[0].disabled;
                    const guard = data.shoplifting.big_als[1].disabled;
                    displayAlertBox(camera, guard);
                }
            )
            .catch(error => console.error('API Error:', error));
    }

    // Render the box instantly with default values
    displayAlertBox();

    setInterval(fetchAndDisplayData, 10000);
})();