【发布时间】:2010-04-21 18:33:17
【问题描述】:
我需要帮助让带有 JQuery 脚本的 Grease Monkey 在损坏的站点上运行。
我正在尝试运行以下 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
进度:
我同意 @mkoryak 的观点,这是 GM 无法解决的问题。所以我放弃它并改用 Firefox 扩展(希望它不会遇到同样的问题)。
我将按照我在 OS 上的另一篇文章中看到的示例进行操作: How to use jQuery in Firefox Extension
我能够让它工作,但对所示示例稍作修改:
(顺便说一句,我使用Firefox Extension Wizard 轻松快速地获得了扩展设置的基本框架)。
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);
【问题讨论】:
-
你能给我举个例子来说明如何用 GM 做到这一点。我没有直接访问该文件的权限。
标签: jquery firefox greasemonkey