2

我需要使用Greasemonkey替換URL中的特定文本。如何使用腳本將頁面切換到不同的域?

例如,如果該頁面是:

http://adf.st/?u=https%3A%2F%2Finstagram.com%2Fp%2F4XOVEaD5Ca%2F 

然後腳本將使用以下網址:

http://adfa.cc/?u=https%3A%2F%2Finstagram.com%2Fp%2F4XOVEaD5Ca%2F 

注:文中adf.st/不固定後休息。

+0

你已經試過了什麼? – w35l3y

回答

3

這是一個標準問題;使用下面的模式。

@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); 
+1

我嘗試了很多代碼(超過20個代碼),他們都沒有工作,但你是搖滾樂。它的工作與第二。非常感謝你。我非常開心。你爲我節省了很多時間。 –

+0

不客氣。樂意效勞。 –

相關問題