Как вызвать функции GM_ от Greasemonkey из кода, который должен выполняться в области целевой страницы?

Я задал вопрос и получил ответ здесь:Как вызвать эту функцию YouTube от Greasemonkey?

Этот код работает и добавляет кнопку на страницу, которая фиксирует время видео.

Но ключевая часть должна выполняться в области целевой страницы - где Greasemonkey'sGM_ функции недоступны.

Я хочу использоватьGM_setValue() для записи видео времени. Как мне позвонитьGM_setValue() от моей кнопкиclick обработчик?

Вот соответствующая частьполный сценарий (щелкните правой кнопкой мыши, чтобы сохранить):

... ...

//-- Only run in the top page, not the various iframes.
if (window.top === window.self) {
    var timeBtn         = document.createElement ('a');
    timeBtn.id          = "gmTimeBtn";
    timeBtn.textContent = "Time";
    //-- Button is styled using CSS, in GM_addStyle, below.

    document.body.appendChild (timeBtn);

    addJS_Node (null, null, activateTimeButton);
}

function activateTimeButton () {
    var timeBtn = document.getElementById ("gmTimeBtn");
    if (timeBtn) {
        timeBtn.addEventListener ('click',
            function () {
                var ytplayer = document.getElementById ("movie_player");
                //-- IMPORTANT:  GM_functions will not work here.

                console.log ("getCurrentTime(): ", ytplayer.getCurrentTime() );
                alert (ytplayer.getCurrentTime() );
            },
            false
        );
    }
    else {
        alert ("Time button not found!");
    }
}

... ...



Спасибо :-)

Ответы на вопрос(1)

Ваш ответ на вопрос