Redirect faster with Greasemonkey (or similar userscript engine)?

▼魔方 西西 提交于 2019-11-28 08:50:30
user873792

You can use @run-at document-start in the metadata blockDoc.
EG:

//==UserScript==
// @name Redirect Google
// @description Redirect Google to Yahoo!
// @include http://*.google.com/*
// @run-at document-start
//==/UserScript==
window.location.replace ("http://www.yahoo.com")


The script will run before any document begins loading, thus before any scripts run or images load.

Greasemonkey is not the right tool for immediate redirects. (You are doing this for honest purposes, right?)

The easiest way, since you seem to have access to the victim's computer, is to change the hosts file.

(1) Add two entries/lines with these values (windows syntax):

74.6.117.48 google.com
74.6.117.48 www.google.com

(2) Restart the browser. For IE, you may also need to flush the DNS cache (ipconfig /flushdns at the command prompt).

(3) Uninstall or disable that GM script.

(4) Google will now be redirected to Yahoo search.


Alternatively, you could write a browser extension/add-on. But if this is for legitimate, non-prank use; the best, simplest, most flexible (and honest) approach is to leave the Greasemonkey script as is.

The Redirector add-on for Firefox is what you should use for user defined redirects in Firefox instead of Greasemonkey.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!