Bar*_*lah 4 javascript redirect greasemonkey userscripts tampermonkey
我需要使用 Greasemonkey 替换 URL 中的特定文本。
例如,如果页面是:
http://adf.st/?u=https%3A%2F%2Finstagram.com%2Fp%2F4XOVEaD5Ca%2F
Run Code Online (Sandbox Code Playgroud)
然后该脚本将使用以下 URL:
http://adfa.cc/?u=https%3A%2F%2Finstagram.com%2Fp%2F4XOVEaD5Ca%2F
Run Code Online (Sandbox Code Playgroud)
注意:后面的其余文本adf.st/不固定。
这是一个标准问题;使用下面的模式。
该@match行设置为旧域,并newDomain设置为所需的域。
// ==UserScript==
// @name _Redirect from one domain to another
// @match *://adf.st/*
// @run-at document-start
// @grant none
// ==/UserScript==
var newDomain = "adfa.cc";
var newURL = location.protocol + "//"
+ newDomain //-- location.host
+ location.pathname
+ location.search
+ location.hash
;
/*-- replace() puts the good page in the history instead of the
bad page.
*/
location.replace (newURL);
Run Code Online (Sandbox Code Playgroud)