Link Opener

Öffnet Links im Browser und ermöglicht Whitelisting

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Advertisement:

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Advertisement:

// ==UserScript==
// @name         Link Opener
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Öffnet Links im Browser und ermöglicht Whitelisting
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Whitelist für bestimmte Links
    var whitelist = [
        'https://example.com', // Beispiel-URL für Whitelisting
        'https://google.com',  // Beispiel-URL für Whitelisting
        // Fügen Sie hier weitere URLs hinzu, die Sie in der App öffnen möchten
    ];

    // Funktion, um Links zu modifizieren
    function modifyLinks() {
        // Alle Links auf der Seite finden
        var links = document.querySelectorAll('a');

        // Jeden Link durchgehen
        links.forEach(function(link) {
            // Prüfen, ob der Link in der Whitelist ist
            if (whitelist.includes(link.href)) {
                // Link bleibt unverändert, falls er in der Whitelist ist
                return;
            }

            // Prüfen, ob der Link eine App öffnen würde
            if (link.href.startsWith('https://') || link.href.startsWith('http://')) {
                // Den Link so ändern, dass er im Browser geöffnet wird
                link.target = '_self';
                // Optional: Den Link auf eine bestimmte Weise umleiten
                // link.href = link.href + '?browser=true';
            }
        });
    }

    // Funktion ausführen, wenn die Seite geladen ist
    document.addEventListener('DOMContentLoaded', function() {
        modifyLinks();
    });

    // Optional: Beim Klicken auf einen Link prüfen
    document.addEventListener('click', function(event) {
        if (event.target.tagName === 'A') {
            // Prüfen, ob der Link in der Whitelist ist
            if (whitelist.includes(event.target.href)) {
                return;
            }
            event.preventDefault();
            window.location.href = event.target.href;
        }
    });
})();