小编Rom*_*ric的帖子

如何从必须在目标页面范围内运行的代码调用Greasemonkey的GM_函数?

我问了一个问题并在这里得到了答案:如何从Greasemonkey调用此YouTube功能?

该代码可以工作并向页面添加一个按钮,用于捕获视频时间.
但是,关键部分必须在目标页面范围内运行 - 其中Greasemonkey的GM_功能不可用.

我想用来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 …
Run Code Online (Sandbox Code Playgroud)

javascript youtube greasemonkey youtube-api

5
推荐指数
1
解决办法
3498
查看次数

标签 统计

greasemonkey ×1

javascript ×1

youtube ×1

youtube-api ×1