【问题标题】:Tampermonkey doesn't load on github until refreshedTampermonkey 在刷新之前不会加载到 github
【发布时间】:2018-08-12 14:47:41
【问题描述】:

每个人都说使用waitForKeyElements 实用程序。

// ==UserScript==
// @name         Github raw to cdn to rawgit
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add a CDN button to button group
// @author       You
// @match        https://github.com/*/*/blob/*/*
// @include      https://github.com/*/*/blob/*/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
// ==/UserScript==

waitForKeyElements('a#raw-url', addCDN);

function addCDN(rawURL) {
    var href = rawURL.attr('href');
    var cdn = href.replace('/raw', '');
    var button = '<a href="https://cdn.rawgit.com' + cdn + '" class="btn btn-sm BtnGroup-item" target="_blank">CDN</a>';
    $(button).appendTo($('.BtnGroup'));
}

我尝试转到 github 主页,然后导航到该文件。但它并没有显示脚本在 Tampermonkey 中运行。我刷新了页面然后就没事了!转到主页,然后导航到那里的文件!我再次尝试关闭选项卡并从新选项卡重新打开 github 主页,然后问题又出现了。

我的代码中是否缺少某些内容?我还尝试了$(function() {}); 或准备功能。它不工作。

【问题讨论】:

  • waitForKeyElements,这是 github 的事情?你试过不同的@run-at 选项吗?
  • 我尝试了 document-idle bit 没有任何反应。
  • 现在,我刚刚尝试了所有@run-at 选项,但没有任何反应
  • 好吧,我刚刚安装了你的脚本(因为它在问题中) - 并且 addCDN 在导航到适当的页面时被调用 - 也许 chrome 的工作方式不同(firefox here_
  • 感谢您的尝试。也许我需要一些东西让它适用于 chrome。

标签: javascript jquery github tampermonkey


【解决方案1】:

感谢@wOxxOm 的回答

使用@match https://github.com/* 就是答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 2020-05-10
    • 2020-11-17
    • 2017-01-13
    相关资源
    最近更新 更多