如何解决Greasemonkey - 浏览器重定向
所以我已经有一段时间没有使用 Greasemonkey 脚本了,我可能忘记了做一些基本的事情,但是...
我想做的是当我导航到 here 而不是将我重定向到 https://beta.crunchyroll.com 时,我认为我当前的代码应该这样做,但不是出于某种原因。
// ==UserScript==
// @name Crunchyroll Redirect
// @version 1
// @grant none
// @include http://*.crunchyroll.*/*
// @include https://*.crunchyroll.*/*
// ==/UserScript==
var current_location = content.document.location;
if(current_location == "https://beta.crunchyroll.com"){
window.location.replace("https://beta.crunchyroll.com/simulcasts/seasons/spring-2021")
}
那么我在哪里搞砸了?
解决方法
您可以简化逻辑。
- 由于您只需要在
https://beta.crunchyroll.com
上运行它,因此在其他页面上运行它是没有意义的 -
@match
比@include
更健壮
- 使用
@run-at
尽早运行
这是一个例子:
// ==UserScript==
// @name Crunchyroll Redirect
// @match *://beta.crunchyroll.com/*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
window.stop(); // stop loading
location.replace('https://beta.crunchyroll.com/simulcasts/seasons/spring-2021');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。