Flying OC Alert

Alerts you when you want to fly but an OC is about to start.

目前為 2025-04-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Flying OC Alert
// @namespace    http://tampermonkey.net/
// @version      0.2.2
// @description  Alerts you when you want to fly but an OC is about to start.
// @author       NichtGersti [3380912]
// @license      MIT
// @match        https://www.torn.com/page.php?sid=travel
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// ==/UserScript==

//TODO: Options

(function() {
    'use strict';

    let apiKey = "" //Minimal access or above!
    let maxWarningHours = 10
    let confirmMathQuestion = false //highest priority; makes you solve a simple addition
    let confirmPrompt = false //only if confirmMathQuestion = false; makes you write the confirmMessage
    let confirmMessage = "continue" //for confirmPrompt

    let ocUrl = "https://api.torn.com/v2/user/?selections=organizedcrime&key={apiKey}".replace("{apiKey}", apiKey)

    fetch(ocUrl).then( response => {
        if (response.ok) {
            return response.json();
        }
        throw new Error('Something went wrong');
    })
    .then( result => {

        if (result.error) {
            alert(`Error: ${result.error.code}\n${result.error.error}`)
            return
        }

        let infoOc = result.organizedCrime

        let totalSeconds = infoOc.ready_at - Math.floor(Date.now() / 1000)
        //if (totalSeconds / 3600 > 10) return

        let days = Math.floor(totalSeconds / 86400) % 24
        let hours = Math.floor(totalSeconds / 3600) % 60
        let minutes = Math.floor(totalSeconds / 60) % 60
        let seconds = totalSeconds % 60

        let timeString = ""
        if (totalSeconds > 86400) timeString += `${(days < 10) ? "0" : ""}${days}:`
        if (totalSeconds > 3600) timeString += `${(hours < 10) ? "0" : ""}${hours}:`
        if (totalSeconds > 60) timeString += `${(minutes < 10) ? "0" : ""}${minutes}:`
        timeString += `${(seconds < 10) ? "0" : ""}${seconds}`
        if (totalSeconds < 60) timeString = `${(seconds < 10) ? "0" : ""}${seconds} seconds`

        if (confirmMathQuestion) {
            let randomNumber1 = Math.ceil((Math.random() * 50))
            let randomNumber2 = Math.ceil((Math.random() * 50))
            let correctAnswer = (randomNumber1 + randomNumber2).toString()
            let message
            while (message != correctAnswer) message = prompt(`Your Organzied Crime is about to start:\n${timeString}\nSolve "${randomNumber1} + ${randomNumber2}" to continue.`)
        } else if(confirmPrompt) {
            let message
            while (message != confirmMessage) message = prompt(`Your Organzied Crime is about to start:\n${timeString}\nWrite "${confirmMessage}" to continue.`)
        } else alert(`Your Organzied Crime is about to start:\n${timeString}`)

    })
    .catch(error => console.log(error))

})();