相关疑难解决方法(0)

如何从必须在目标页面范围内运行的代码调用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
查看次数

在脚本之外访问 GM_getValue

基本上就是问题标题。这将使我受益匪浅。我希望能够访问GM_getValue用户脚本之外的内容以进行调试,或者至少访问值和名称本身。

我在 Windows 10 上使用 Chrome。

tampermonkey

2
推荐指数
1
解决办法
2247
查看次数