Toogle beta version

Extension for foodsharing.de - toogles to beta version and back

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        Toogle beta version
// @namespace   Violentmonkey Scripts
// @match       https://*.foodsharing.*/*
// @run-at      document-idle
// @version     1.2
// @author      Martin G. (166111)
// @license     MIT
// @require     https://cdn.jsdelivr.net/npm/@violentmonkey/shortcut@1
// @description Extension for foodsharing.de - toogles to beta version and back
// ==/UserScript==

let btn = document.createElement("BUTTON");
let div = document.querySelector(".metanav-container");
div.appendChild(btn);

btn.innerHTML = "beta";
if(isBeta()){
    btn.innerHTML = "prod";
}

btn.onclick = () => {
    const aktuelleURL = window.location.href;
    const betaMuster = /(\bhttps?:\/\/)(www\.)?/; // Suchmuster für http(s):// und optional www.
    const betaVorhanden = aktuelleURL.includes("beta.");
    let neueURL;

    if (isBeta()) {
        btn.innerHTML = "beta";
        neueURL = aktuelleURL.replace("beta.", ""); // switch to prod
    } else {
        btn.innerHTML = "prod";
        neueURL = aktuelleURL.replace(betaMuster, "$1beta."); // switch to beta
    }

    window.location.href = neueURL;
};

function isBeta() {
    const aktuelleURL = window.location.href;
    return aktuelleURL.includes("beta.");
}