BCT Defaultor

Set BCT as the default flight method

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         BCT Defaultor
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Set BCT as the default flight method
// @author       Titanic_
// @license      MIT
// @match        https://www.torn.com/page.php?sid=travel*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    const bctSelector = 'input[name="travelType"][value="business"]';
    let hasCompleted = false;

    function selectBusinessClass() {
        const bctRadio = document.querySelector(bctSelector);

        if (!bctRadio) return false;

        if (!bctRadio.disabled && !bctRadio.checked) {
            bctRadio.click();
            hasCompleted = true;
            return true;
        }

        if (bctRadio.disabled || bctRadio.checked) {
            hasCompleted = true;
            return true;
        }

        if (bctRadio.disabled && !bctRadio.checked) console.error('[BCT] You dont have any BCT');

        return false;
    }

    const observer = new MutationObserver((mutations, obs) => {
        if (selectBusinessClass()) {
            obs.disconnect();
        }
    });

    const root = document.getElementById('travel-root');
    if (root) {
        observer.observe(root, {
            childList: true,
            subtree: true
        });

        selectBusinessClass();
    } else console.error('[BCT] Couldnt find #travel-root');

    setTimeout(() => {
        if (!hasCompleted) {
            observer.disconnect();
            console.log('[BCT] Timed out');
        }
    }, 10000);

})();