2013-03-26 4 views
0

에 나는 그래서이 스크립트가 :스크립트는 파이어 폭스 스크래치 패드에서 작동하지만 그리스 몽키

페이지 후 스크래치 패드에서 작동
links = document.getElementsByClassName('thumb'); 
for (var i=links.length-1; i>=0; i--) 
{ 
links[i].href=links[i].href+'/popout'; 
} 

, 내가 수정하려는로드됩니다.

하지만 greasemonkey에 넣으면 페이지가 완전히로드되기 전에 실행되고 mod에 필요한 요소가 없기 때문에 작동하지 않습니다.

// ==UserScript== 
// @name  popout 
// @namespace PylonPants 
// @include  http://*.twitch.tv/directory/* 
// @version  1 

// ==/UserScript== 

//if ('loading' == document.readyState) { 
// alert("This script is running at document-start time."); 
//} else { 
// alert("This script is running with document.readyState: " + document.readyState); 
//} 
// script runs at readyState = interactive and that brakes it 
// do not know how to make it wait till complete 

links = document.getElementsByClassName('thumb'); 
alert(links[0]); // i get "undefined" 
for (var i=links.length-1; i>=0; i--) 
{ 
alert('the script works'); //i never reach here 
alert(links[i].href); // nor here 
links[i].href=links[i].href+'/popout'; 
} 
alert('crazy'); // i get this then the page loads fully. 

답변

1

스크립트가 그 작은 이미지를로드하는 페이지의 자바 스크립트를 기다려야합니다 : 여기

는 GS 스크립트입니다. 가장 간단하고 가장 강력한 방법은 the waitForKeyElements() utility을 사용하는 것입니다.

여기 완전한 스크립트 그 href의 변경 jQuerywaitForKeyElements를 사용 : 답변

// ==UserScript== 
// @name  popout 
// @namespace PylonPants 
// @include  http://*.twitch.tv/directory/* 
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js 
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js 
// @grant  GM_addStyle 
// ==/UserScript== 
/*- The @grant directive is needed to work around a design change 
    introduced in GM 1.0. It restores the sandbox. 
*/ 

waitForKeyElements ("a.thumb", adjustLinkHrefs); 

function adjustLinkHrefs (jNode) { 
    var newAddr = jNode.attr ("href") + '/popout'; 
    jNode.attr ("href", newAddr); 
} 
+0

감사합니다 – user2209850

관련 문제