Tampermonkey / tampermonkey

Tampermonkey is the most popular userscript manager, with over 10 million users. It's available for Chrome, Microsoft Edge, Safari, Opera Next, and Firefox.
GNU General Public License v3.0
4.03k stars 413 forks source link

Tampermonkey cannot load scripts when the website is unresponsive #2087

Open WILDADF opened 4 weeks ago

WILDADF commented 4 weeks ago

When I can connect to the main website, the script works fine When the main website is no respond, the script does not load

Expected Behavior

redirect to mirror sites

Actual Behavior

scripts not load

Specifications

Script

(Please give an example of the script if applicable.)

// ==UserScript==
// @name         萌娘百科跳转镜像网站
// @version      1.0
// @description 在访问主站时自动跳转到镜像网站:'moegirl.uk'
// @match        https://mzh.moegirl.org.cn/*
// @match        https://zh.moegirl.org.cn/*
// @license        MIT
// @grant        none
// @run-at       document-start
// @namespace http://tampermonkey.net/
// @downloadURL https://update.greasyfork.org/scripts/494741/%E8%90%8C%E5%A8%98%E7%99%BE%E7%A7%91%E8%B7%B3%E8%BD%AC%E9%95%9C%E5%83%8F%E7%BD%91%E7%AB%99.user.js
// @updateURL https://update.greasyfork.org/scripts/494741/%E8%90%8C%E5%A8%98%E7%99%BE%E7%A7%91%E8%B7%B3%E8%BD%AC%E9%95%9C%E5%83%8F%E7%BD%91%E7%AB%99.meta.js
// ==/UserScript==
(function() {
    'use strict';
    const targetHost = 'https://moegirl.uk';
    const pathRegex = /moegirl\.org\.cn(.*)$/;
    const match = pathRegex.exec(window.location.href);
    const newPath = match ? match[1] : '';
    window.location.replace(`${targetHost}${newPath}`);
})();
derjanb commented 2 weeks ago

Please try 5.3.6200 (crx|xpi in review)

You might need to set "Content Script API" to "Userscript API Dynamic".