我正在使用Greasemonkey将某些URL重定向到另一个URL,但我想在重定向加载的URL之前重定向.
目前我正在使用这个简单的脚本:
//==UserScript==
// @name Redirect Google
// @description Redirect Google to Yahoo!
// @include http://*.google.com/*
//==/UserScript==
window.location.replace("http://www.yahoo.com")
Run Code Online (Sandbox Code Playgroud)
在上面,谷歌出现了一秒钟,然后重定向到谷歌.我想马上去雅虎.有可能,怎么样?
我想将URL重定向到其他URL.例如,如果我输入:
google.com
Run Code Online (Sandbox Code Playgroud)
并按Enter键,它应该重定向到:
yahoo.com
Run Code Online (Sandbox Code Playgroud)
我在上一个帖子中找到了一个代码,但不幸的是,它适用于所有URL,我不想要.此外,一旦重定向完成(在yahoo.com上),页面将重新加载,无休止地循环.
编辑:当前代码:
// ==UserScript==
// @name Google to Yahoo
// @description Redirects Google to Yahoo
// @include http://*.google.*/*
// @version 1
// ==/UserScript==
if(content.document.location == "http://google.com"){
window.location.replace("http://yahoo.com")
}
Run Code Online (Sandbox Code Playgroud)