🏠 Home 

Redirect to Opener

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


安装此脚本?
// ==UserScript==
// @name         Redirect to Opener
// @version      1.0
// @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';
// Retrieve or initialize the website list
const websiteListKey = "websiteList";
let websiteList = GM_getValue(websiteListKey, []);
// Function to add a website to the list
function addWebsite() {
const website = prompt("Enter a website or part of a URL to redirect (e.g., youtube.com):");
if (!website) return;
// Add the website to the list
websiteList.push(website);
GM_setValue(websiteListKey, websiteList);
alert(`Website "${website}" added to the list.`);
}
// Function to view and manage the website list
function manageWebsiteList() {
if (websiteList.length === 0) {
alert("No websites have been added yet.");
return;
}
let listDisplay = "Current websites in the 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!");
}
}
// Register menu commands for adding and managing websites
GM_registerMenuCommand("Add Website to Redirect List", addWebsite);
GM_registerMenuCommand("Manage Website List", manageWebsiteList);
// Redirect logic
const currentURL = window.location.href;
for (const website of websiteList) {
if (currentURL.includes(website)) {
// Construct the deep link with the encoded current URL
const encodedURL = encodeURIComponent(currentURL);
const openerURL = `opener://x-callback-url/show-options?url=${encodedURL}`;
// Redirect to the constructed URL
window.location.href = openerURL;
break;
}
}
})();