Flying OC Alert

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

当前为 2025-04-25 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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))

})();