Strava - Toggle Virtual Ride

Hides Virtual Ride with the option to switch in the menu

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

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

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         Strava - Toggle Virtual Ride
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Hides Virtual Ride with the option to switch in the menu
// @author       Kamil Gadawski / Gemini
// @match        https://www.strava.com/dashboard*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Default state: hiding is enabled
    let isHidingEnabled = true;

    const hideVirtualRides = () => {
        const labels = document.querySelectorAll('div.B7rQ6');
        labels.forEach(label => {
            if (label.textContent.trim().includes('Virtual Ride')) {
                let container = label;
                for (let i = 0; i < 6; i++) {
                    if (container.parentElement) container = container.parentElement;
                }

                if (container) {
                    container.style.display = isHidingEnabled ? 'none' : '';
                }
            }
        });
    };

    // Function adding a switch to navigation
    const injectToggle = () => {
        const navGroup = document.querySelector('ul.user-nav.nav-group');
        if (!navGroup || document.getElementById('strava-virtual-toggle-li')) return;

        const li = document.createElement('li');
        li.id = 'strava-virtual-toggle-li';
        li.className = 'nav-item upgrade mr-sm';
        li.style.display = 'flex';
        li.style.alignItems = 'center';
        li.style.color = '#333';
        li.style.fontSize = '12px';
        li.style.cursor = 'pointer';
        li.innerHTML = `
            <div style="display: flex; align-items: center; background: #eee; padding: 5px 10px; border-radius: 4px; border: 1px solid #ccc;">
                <input type="checkbox" id="strava-v-toggle" checked style="margin-right: 8px; cursor: pointer;">
                <label for="strava-v-toggle" style="margin: 0; cursor: pointer; font-weight: bold; color: #E34402;">Hide Virtual</label>
            </div>
        `;

        navGroup.prepend(li);

        document.getElementById('strava-v-toggle').addEventListener('change', (e) => {
            isHidingEnabled = e.target.checked;
            if (!isHidingEnabled) {
                const allPosts = document.querySelectorAll('div');
                hideVirtualRides();
            } else {
                hideVirtualRides();
            }
        });
    };
    const observer = new MutationObserver(() => {
        injectToggle();
        hideVirtualRides();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
    injectToggle();
    hideVirtualRides();
})();