🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Redirect to Opener

Allow you to redirect customizable urls to the iOS Opener app.

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!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

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!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Redirect to Opener
// @version      1.1
// @description  Allow you to redirect customizable urls to the iOS Opener app.
// @author       yodaluca23
// @license      GNU GPLv3
// @match        *://*/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @namespace https://greasyfork.org/users/1315976
// ==/UserScript==

(function() {
    'use strict';

    // Keys for stored lists
    const websiteListKey = "websiteList";
    const exclusionListKey = "exclusionList";

    // Retrieve or initialize the lists
    let websiteList = GM_getValue(websiteListKey, []);
    let exclusionList = GM_getValue(exclusionListKey, []);

    // Function to add a website to the redirect list
    function addWebsite() {
        const website = prompt("Enter a website or part of a URL to redirect (e.g., youtube.com):");
        if (!website) return;

        websiteList.push(website);
        GM_setValue(websiteListKey, websiteList);
        alert(`Website "${website}" added to the redirect list.`);
    }

    // Function to manage the redirect list
    function manageWebsiteList() {
        if (websiteList.length === 0) {
            alert("No websites have been added yet.");
            return;
        }

        let listDisplay = "Current websites in the redirect list:\n\n";
        websiteList.forEach((item, index) => {
            listDisplay += `${index + 1}. ${item}\n`;
        });
        listDisplay += "\nEnter the number of the website to delete, or press Cancel to exit.";

        const choice = prompt(listDisplay);
        const index = parseInt(choice, 10) - 1;

        if (!isNaN(index) && index >= 0 && index < websiteList.length) {
            websiteList.splice(index, 1);
            GM_setValue(websiteListKey, websiteList);
            alert("Website removed successfully!");
        }
    }

    // Function to add a website to the exclusion list
    function addExclusion() {
        const exclusion = prompt("Enter a URL part to exclude from redirection (e.g., login.google.com):");
        if (!exclusion) return;

        exclusionList.push(exclusion);
        GM_setValue(exclusionListKey, exclusionList);
        alert(`Exclusion "${exclusion}" added to the list.`);
    }

    // Function to manage the exclusion list
    function manageExclusionList() {
        if (exclusionList.length === 0) {
            alert("No exclusions have been added yet.");
            return;
        }

        let listDisplay = "Current exclusions:\n\n";
        exclusionList.forEach((item, index) => {
            listDisplay += `${index + 1}. ${item}\n`;
        });
        listDisplay += "\nEnter the number of the exclusion to delete, or press Cancel to exit.";

        const choice = prompt(listDisplay);
        const index = parseInt(choice, 10) - 1;

        if (!isNaN(index) && index >= 0 && index < exclusionList.length) {
            exclusionList.splice(index, 1);
            GM_setValue(exclusionListKey, exclusionList);
            alert("Exclusion removed successfully!");
        }
    }

    // Register menu commands
    GM_registerMenuCommand("Add Website to Redirect List", addWebsite);
    GM_registerMenuCommand("Manage Redirect List", manageWebsiteList);
    GM_registerMenuCommand("Add Exclusion", addExclusion);
    GM_registerMenuCommand("Manage Exclusion List", manageExclusionList);

    // Redirect logic
    const currentURL = window.location.href;

    // Check if the URL matches any exclusion before redirecting
    for (const exclusion of exclusionList) {
        if (currentURL.includes(exclusion)) {
            console.log(`Redirection prevented: URL contains excluded term "${exclusion}".`);
            return; // Stop execution if an exclusion is found
        }
    }

    // Check if the URL matches any redirect condition
    for (const website of websiteList) {
        if (currentURL.includes(website)) {
            const encodedURL = encodeURIComponent(currentURL);
            const openerURL = `opener://x-callback-url/show-options?url=${encodedURL}`;

            // Redirect to the constructed URL
            window.location.href = openerURL;
            break;
        }
    }
})();