【发布时间】: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