- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从greasemonkey wiki 页面,有一个使用jQuery 和greasemonkey 的示例。下面列出了代码,页面位置为http://wiki.greasespot.net/Third-Party_Libraries#jQuery
// ==UserScript==
// @name jQuery Example
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
// Append some text to the element with id someText using the jQuery library.
$("#someText").append(" more text.");
此示例脚本直接修改 DOM。我是否需要用 jQuery 函数
包围代码,如下所示:
// ==UserScript==
// @name jQuery Example
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
// Append some text to the element with id someText using the jQuery library.
jQuery(function(){
$("#someText").append(" more text.");
})
我问这个问题是因为我的greasemonkey代码没有在每次刷新页面时执行。关于这个问题有什么想法吗?谢谢。
最佳答案
不,将脚本代码包装在 jQuery()
调用中,或者使用 $(document).ready ()
都是没有意义的。
Greasemonkey 在 DOMContentLoaded
事件(与 jQuery 包装器或就绪事件相同)之后以及加载 GM 版本的 jQuery 之后自动触发。
另请注意,该 wiki 页面已过时。 GM 现在可以很好地使用 jQuery 1.6.2。
您没有显示相关代码,也没有链接到目标页面,但最可能的原因是“Greasemonkey代码并非每次页面都会执行”已刷新”为:
GM 脚本中有错误。
目标内容通过 AJAX 单独加载。
您可以使用此模式中的代码来解决这个问题:
//--- This handles both page-load delays, and AJAX changes.
setInterval (function() { checkForTweetbox (); }, 500);
function checkForTweetbox () {
var tweetbox = document.querySelector ('div.tweet-box textarea');
if (tweetbox) {
if (! tweetbox.weHaveProcessed) {
tweetbox.weHaveProcessed = true;
alert ('New tweet-box found!');
}
}
}
关于javascript - Greasemonkey与jQuery,如何编写greasemonkey脚本来修改页面DOM元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283923/
这个问题在这里已经有了答案: How to call Greasemonkey's GM_ functions from code that must run in the target page s
是否可以使用 Greasemonkey 脚本跨域存储数据?我想允许从使用相同 Greasemonkey 脚本的多个网站访问 Javascript 对象。 最佳答案 是的,这就是 GM_setvalue
我有一个简单的 Greasemonkey 脚本: // ==UserScript== // @name hello // @namespace http://www.webmonkey.com //
我想写一个非常简单的 greasemonkey 脚本,因为我讨厌“你确定吗?”我经常使用的网站上的 javascript 确认。我只是将它用于个人用途,不会发布它或任何东西。经过一番谷歌搜索后,我找到
这是一个有点奇怪的具体问题。 我正在编写一个可以跨十个域运行的 Greasemonkey 脚本。这些网站都具有相同的结构,但每个网站的域名不同。例如,脚本将运行: http://first-domai
我为一个域制作了一个greasemonkey脚本,现在如何让它只运行一次?就像每次访问域时它都会启动一样,我不希望这样。如何使其仅运行一次,然后删除自身或使其处于非事件状态? 谢谢。 最佳答案 如果您
我发现了很多类似的问题,但没有一个是平等的,也没有正确的解决方案。这是一个非常奇怪的问题。 我有一个简单的 Greasemonkey 脚本来测试这个问题: // ==UserScript== // @
我正在写一个 Greasemonkey 脚本,如何实现自动更新? 可以将脚本放入 GitHub 存储库并设置 @version数字? 然后......是一些自动的方式如何做到这一点?或者我必须手动检查
我现在正在研究用户脚本。我知道 Opera 与 Greasemonkey 脚本的许多方面兼容,但与其他方面不兼容。 GM functions emulation script在 Opera 上将需要,
最近在写一个用户脚本时,我发现页面上下文中的变量是可用的。 console.log(window) 在 Tampermonkey 和 Greasemonkey 中都没有导致错误。 我很困惑。全局变量不
看完后Greasemonkey recommends users to install Tampermonkey or Violentmonkey . 我已经安装了 Tampermonkey,现在我正
我在一堆 div 和一个表单中包含了一些输入值。我对 js 的了解有限,想在页面加载时使用油脂猴来设置值。 下面显示了获取值的 div 和表单的顺序。
有没有办法使用用户脚本将一些设置保存到不是 cookie 的本地计算机? 如果设置不是全局的,则很难制作用于多个域的用户脚本。 来自评论: "I am using scriptish " 。 最佳答案
我有一个带有以下元块的油脂猴脚本- // ==UserScript== // @name TDF Improved Dark Skin // @namespace TDF // @incl
我有用于Firefox的Greasemonkey脚本。该脚本包括此元块和一些代码行。 我想在服务器上更新脚本,然后自动更新浏览器的脚本。 requireSecureUpdates选项已关闭。 我究竟做
我正在按照说明将 Greasemonkey 脚本传输到 Tampermonkey:How to Transfer All Greasemonkey userscripts to Tampermonke
This question already has an answer here: My very simple Greasemonkey script is not running? (1个答案)
我需要在公司内部网站上托管用户脚本。我如何构建 href这样 Greasemonkey 会在点击链接时安装用户脚本吗? 我尝试了一个简单的 Install Userscript但是 Chrome 和
例如,在远程网页中,有如下代码片段: function foo(){ this.bar = 0; } 在我的油脂猴子脚本中,我想创建此类的对象: var _foo= unsafeWindow['fo
我想在文档中选择文本后调用函数。以下代码无效 var showSelWin = document.getElementById('innerwindow'); var txt = ' '; if (d
我是一名优秀的程序员,十分优秀!