有没有办法用 Grease Monkey 禁用除我自己的 Java 脚本之外的所有其他 Java 脚本

发布于 2024-08-29 13:27:43 字数 2183 浏览 1 评论 0原文

我需要帮助让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断桥再见 2024-09-05 13:27:43

你做不到。

如果存在 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.

枉心 2024-09-05 13:27:43

由于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文