BCT Defaultor

Set BCT as the default flight method

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);

})();