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: http://stackoverflow.com/questions/491490/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);