有没有办法用 Grease Monkey 禁用除我自己的 Java 脚本之外的所有其他 Java 脚本
我需要帮助让 Grease Monkey 与 JQuery 脚本在损坏的网站上运行。
我正在尝试运行以下 GM 脚本,但我希望它运行的页面有 JS 错误,并且我的 JS 没有被执行。
// ==UserScript==
// @name BILL INFO PAGE ALTER
// @namespace http://jenkinslaw.org
// @description Alter the web page in order to pretty print
// @include http://www.legis.state.pa.us/cfdocs/billinfo/bill_history.cfm?*
// @require http://code.jquery.com/jquery-1.4.2.min.js
// ==/UserScript==
*/
(function() {
//Make a copy of the bill table
var bill_table = $('.main_table').clone();
//empty the whole lot
$(body).empty();
//append the bill back to the dom.
$(body).append(bill_table);
}());
谢谢!
D
Progress:
我同意 @mkoryak 的观点,这是 GM 无法解决的问题。所以我放弃它并使用 Firefox 扩展(希望它不会遇到同样的问题)。
我将遵循我在操作系统的另一篇文章中看到的示例: 如何在 Firefox 扩展中使用 jQuery
我能够使其正常工作,但对所示示例稍作修改:
(顺便说一句,我使用了 Firefox 扩展向导,轻松快速地获得扩展设置的基本框架)。
jQuery.noConflict();
(function($){
billinfo = new function(){};
billinfo.log = function(){ Firebug.Console.logFormatted(arguments,null,"log"); };
billinfo.run = function(doc,aEvent) {
// Check for website
if(!doc.location.href.match(/^http:\/\/(.*\.)?legis\.state\.pa\.us\/cfdocs\/billinfo\/bill_history\.cfm\?(.*)?$/i)) return;
// Check if already loaded
if(doc.getElementById("plugin-billinfo")) return;
// Setup
this.win = aEvent.target.defaultView.wrappedJSObject;
this.doc = doc;
//Make a copy of the bill table
bill_table = $('.main_table', doc).clone();
//empty the whole lot
$('body', doc).empty();
//append the bill back to the dom.
$('body', doc).append(bill_table);
};
// Bind Plugin
var delay = function(aEvent){ var doc = aEvent.originalTarget; setTimeout(function(){ billinfo.run(doc,aEvent); },1); };
var load = function(){ gBrowser.addEventListener("DOMContentLoaded", delay, true); };
window.addEventListener("pageshow", load, false)
})(jQuery);
I need help getting a Grease Monkey with JQuery Script to run on a broken site.
I'm trying to get the following GM script to run, but the page I want it to work on has a JS error and my JS does not get executed.
// ==UserScript==
// @name BILL INFO PAGE ALTER
// @namespace http://jenkinslaw.org
// @description Alter the web page in order to pretty print
// @include http://www.legis.state.pa.us/cfdocs/billinfo/bill_history.cfm?*
// @require http://code.jquery.com/jquery-1.4.2.min.js
// ==/UserScript==
*/
(function() {
//Make a copy of the bill table
var bill_table = $('.main_table').clone();
//empty the whole lot
$(body).empty();
//append the bill back to the dom.
$(body).append(bill_table);
}());
Thanks!
D
Progress:
I agree with @mkoryak this is an impossible problem to solve with GM. So I'm dropping it and using a Firefox extension instead (hopefully it wont run into the same issue).
I'll be following the example I saw on another post here on OS:
How to use jQuery in Firefox Extension
I was able to get it working but with a slight modification from the example shown:
(As an aside, I used the Firefox Extension Wizard to get a basic framework of the extension set-up easily and quickly).
jQuery.noConflict();
(function($){
billinfo = new function(){};
billinfo.log = function(){ Firebug.Console.logFormatted(arguments,null,"log"); };
billinfo.run = function(doc,aEvent) {
// Check for website
if(!doc.location.href.match(/^http:\/\/(.*\.)?legis\.state\.pa\.us\/cfdocs\/billinfo\/bill_history\.cfm\?(.*)?$/i)) return;
// Check if already loaded
if(doc.getElementById("plugin-billinfo")) return;
// Setup
this.win = aEvent.target.defaultView.wrappedJSObject;
this.doc = doc;
//Make a copy of the bill table
bill_table = $('.main_table', doc).clone();
//empty the whole lot
$('body', doc).empty();
//append the bill back to the dom.
$('body', doc).append(bill_table);
};
// Bind Plugin
var delay = function(aEvent){ var doc = aEvent.originalTarget; setTimeout(function(){ billinfo.run(doc,aEvent); },1); };
var load = function(){ gBrowser.addEventListener("DOMContentLoaded", delay, true); };
window.addEventListener("pageshow", load, false)
})(jQuery);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你做不到。
如果存在 JavaScript 错误,您的代码(最后执行的)将永远不会执行。
我已经广泛寻找解决方案,但从未找到它。
You cant do it.
If there is a javascript error, your code (which executes last) will never execute.
I have looked far and wide for a solution for this, but was never able to find it.
由于
eventSupported
函数中的错误,GM 和 jQuery 1.4.* 目前无法共存。因此,您可以使用 1.3.* jQuery 或直接在脚本中包含修改后的 1.4.2 版本,例如建议的 此处。
既然您选择了扩展路径,这与您无关,但我仍然将其发布给其他有类似问题的人,他们将来可能会偶然发现这一点。
GM and jQuery 1.4.* currently fail to co-exist due to an error in the
eventSupported
function.Therefore, you can use the 1.3.* jQuery or include a modified 1.4.2 version directly in your script, such as the one suggested here.
Since you have chosen to take the extension path, this is irrelevant to you, but I still post this for others with similar issues who might stumble upon this in the future.