如何使用用户脚本将页面切换到不同的域?
How do I switch a page to a different domain using a userscript?
我需要使用 Greasemonkey 替换 URL 中的特定文本。
例如,如果页面是:
http://adf.st/?u=https%3A%2F%2Finstagram.com%2Fp%2F4XOVEaD5Ca%2F
然后脚本将使用以下 URL:
http://adfa.cc/?u=https%3A%2F%2Finstagram.com%2Fp%2F4XOVEaD5Ca%2F
注: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);
我需要使用 Greasemonkey 替换 URL 中的特定文本。
例如,如果页面是:
http://adf.st/?u=https%3A%2F%2Finstagram.com%2Fp%2F4XOVEaD5Ca%2F
然后脚本将使用以下 URL:
http://adfa.cc/?u=https%3A%2F%2Finstagram.com%2Fp%2F4XOVEaD5Ca%2F
注: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);