2014-09-28 2 views
-1

저는 Vk 코멘트 자동화를 위해 greacemonkey userscript를 코딩하고 있습니다.Greasemonkey unsafeWindow Vk

그리고 개체에 액세스 할 수없는 이유를 이해할 수 없습니다.

Vk을 창 (첫번째 자본 낮은 같은 단어지만) 두 개의 서로 다른 작곡가작곡가 개체가 OBJ. unsafeWindow 작곡가는 액세스 가능하지만 소문자 오브젝트 작성자는 정의되지 않은 상태로 돌아갑니다. 직접 브라우저 콘솔에서

composer.addMedia.checkMessageURLs("Comment text<br />http://example.com",true); 

을 실행하면

(function (window, undefined) { 
    ..... 
    some code 
    finding post, openning comment form, pasting text 
    need to call: 
    unsafeWindow.composer.addMedia.checkMessageURLs("Comment text<br />http://example.com",true); 
    ..... 
    console.log(unsafeWindow.Composer); // return object 
    console.log(unsafeWindow.composer); // return undefined 
} 

- 모든 확인.

아이디어가 있으십니까?

답변

1

composer (소문자)은 Greasemonkey 스크립트가 실행 된 후에 오랫동안 필요에 따라 생성됩니다.

스크립트에서 액세스하려면 기다려야합니다. 다음과 같음 :

var composerChkTmr = setInterval (doStuffWith_composer, 222); 

function doStuffWith_composer() { 
    if (typeof unsafeWindow.composer === "undefined") 
     return; 

    clearInterval (composerChkTmr); 

    // DO WHATEVER, WITH unsafeWindow.composer HERE. 
} 
+0

고맙습니다! 그것은 작동합니다! – Dmitry

+0

당신을 진심으로 환영합니다. 기꺼이 도와주세요! –