Reputation: 33537
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
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);
Upvotes: 0
Views: 551
Reputation: 16478
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.
Upvotes: 1
Reputation: 57938
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.
Upvotes: 2