2014-11-05 94 views
0

我需要的Greasemonkey腳本找到像所有鏈接:的Greasemonkey腳本重寫鏈接

http://legendas.tv/download/545832dfb67eb/American_Dad/American_Dad_S11E02_HDTV_x264_LOL_AFG_FUM_DIMENSION 

和重寫他們這樣的:

http://legendas.tv/downloadarquivo/545832dfb67eb 

這是我的劇本,但它不是加工。

// ==UserScript== 
// @name  LTV 
// @namespace legendas.tv 
// @include  http://legendas.tv 
// @version  1 
// @grant  none 
// ==/UserScript== 

var links = document.getElementsByTagName("*"); //array 
var regex = /^(http:\/\/)(legendas\.tv\/download\/)(.{13})(.*)$/i; 
for (var i=0,imax=links.length; i<imax; i++) { 
    links[i].href = links[i].href.replace(regex,"$1.legendas.tv\/downloadarquivo\/$3\/"); 
} 

回答

2

你應該考慮使用jQuery。

// @include  http://*legendas.tv/ 
// @require  https://code.jquery.com/jquery-2.1.1.min.js 
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js 
// @grant  GM_addStyle 
// ==/UserScript== 

//wait it load 
waitForKeyElements (".film", dlink); 

//change headers links 
$(".item a").each (function() { 

    var jThis = $(this); 
    var href = jThis.prop("href"); 
    var re = /[\w]+[\d]+/; 
    var code = href.match(re)[0]; 
    var nLink = "/downloadarquivo/" + code; 
    jThis.prop("href", nLink); 

}); 

//change download buttons links 
function dlink() { 

    $(".bt_seta_download a").each (function() { 

     var jThis = $(this); 
     var href = jThis.prop("href"); 
     var re = /[\w]+[\d]+/; 
     var code = href.match(re)[0]; 
     var nLink = "/downloadarquivo/" + code; 
     jThis.prop("href", nLink); 

    }); 

}  

加載頁面後頁面加載的一些元素,所以你必須檢查它是否在那裏與他們一起工作。如果你願意,你可以用waitForKeyElements觸發你的代碼,但是我沒有測試它。

0

一切看起來都很好。
有些事情要看:

^$它們匹配的href?

解析雙引號不會從\/

"$1.legendas.tv\/downloadarquivo\/$3" 

更改刪除逃逸的它 - >

"$1.legendas.tv/downloadarquivo/$3"