Delving into Greasemonkey
I’ve had a problem for awhile with FireFox that I just can’t seem to solve. Flash content just doesn’t seem to want to load. It’s not all Flash either. Some of it loads, some doesn’t, and there doesn’t seem to be any rhyme or reason. My temporary solution was to use IETab to switch to IE’s rendering engine, but that wasn’t a real solution. I even uninstalled and re-installed both Flash and FireFox to no avail.
My main annoyance with this problem was listening to new music on Amie Street. I would load up the player’s page only to find the Flash music player not working. Then I would need to view the source code, copy the Flash URL from the source and paste it in the address bar. Once that loaded up, I was able to listen to the music just fine. However, viewing the source and copying and pasting all the time was annoying.
Today, my thoughts turned to Greasemonkey. I had installed it to use the Popup Alt script (so FireFox would display the image’s ALT attribute like IE does). Why couldn’t I have Greasemonkey detect when I went to an Amie Street music player page and redirect me to the appropriate Flash URL? I had never written a Greasemonkey script before, but I knew that they used JavaScript. I made a new script, and also loaded up the source to the Popup Alt script to use for reference. Within a matter of minutes, I had a simple script written that worked perfectly.
// ==UserScript==
// @name Amie Street Playlist
// @namespace AmieStreet
// @description Redirects from Amie Street player page to actual Flash file
// @include http://amiestreet.com/player.php?*
// ==/UserScript==(function() {
if (!(document.getElementById(’amiePlayer’) == null)) {
document.location = ‘http://www.amiestreet.com/static/swf/amie.swf?siteMode=true&’ + document.location.search.replace(/\?/, ”);
}
})();
This script first looks for an element with an ID of “amiePlayer”. If an element exists, it redirects the page to the SWF file (passing the querystring parameters along). Simple and effective. No, it doesn’t solve the root problem of my mystery FireFox+Flash bug, but it does help reduce the annoyance factor and makes Amie Street usable for me again. I just might have to look into writing other Greasemonkey scripts.

Comment by gavinmroy — October 26, 2006 @ 5:57 pm
Hey, I’ve been developing an app with jHeartbeat (thanks for the cool plugin btw). I was wondering if you planned on releasing it under a license (MIT for example like jQuery). I’m concerned about distributing it in my app without knowing what the license could/would be. Thanks again for a cool plugin.
Comment by jasonlevine — November 6, 2006 @ 11:41 am
jHeartbeat is free to use for any commercial or non-commercial project. I just ask that I be credited somewhere. Doesn’t need to be in huge, bold letters or anything. Just make some small mention of jHeartbeat and my site where ever you feel it is appropriate.
You are right that I should come up with a more formal license, though. I’m looking at the MIT license right now and that looks pretty good. In fact, consider jHeartbeat and my other JQuery plugins/scripts to be “unofficially” covered by the MIT license. (By “unofficially”, I mean that they are under that license now but I probably won’t get to update the documentation for a bit.)
Comment by ray — December 1, 2006 @ 3:19 pm
Hi Jason,
Good work with jHeartbeat!
My question:
———–
You mention that:
“…can use the callback function to manipulate this (returned) data, if needed..”.
Being new to jQuery, could you show a simple “hello world” example for the callback function?
Suggestion:
suppose we’d like to multiply times 2,
the number returned in the DIV by “heartbeat.asp”?
What would the actual samnple code be?
Thanks, Jason!
ray
Comment by jasonlevine — December 28, 2006 @ 8:42 am
ray,
The JHeartbeat page has the generic code. However, a simple “Hello World” application might look like this:
$(document).ready(function() { $.jheartbeat.set({ url: "heartbeat.asp", delay: 3000 }, function () { alert("Hello World!"); }); });A function that might take the number returned and multiply it by 2 would look something like this:
$(document).ready(function() { $.jheartbeat.set({ url: "heartbeat.asp", delay: 3000 }, function () { alert(parseInt($("#HeartBeatDIV").html())*2); }); });I hope this helps.
Comment by bleen18 — January 29, 2007 @ 3:28 pm
jHeartbeat is great, but how do you make it stop beating? I’m using ti to check the status of a slooow script. Once the script is complete though, I want the page to stop checking.
Thanks!
Comment by bleen18 — January 29, 2007 @ 5:33 pm
Regarding my last comment .. I figured it out and thought I’d share:
clearTimeout($.jheartbeat.timeoutobj.id);
With that though, another question: in the “set” function, shouldn’t the first few lines be:
if (this.timeoutobj.id > -1) {
clearTimeout(this.timeoutobj.id);
// note the ‘.id’
}
Comment by howie — February 9, 2007 @ 6:20 am
Is it possible there’s a memory leak in JHeartbeat? I’ve been playing with it for the last couple of days, on something that fetches JSON updates every few seconds from our monitoring system, and uses that to update a UL with entries.
It works nicely now, but I left it running overnight, and came back to a 1GB firefox! Since then, I’ve ripped out ALL of my code, leaving just an empty every-2-seconds heartbeat, and left it going in IE, and I can still watch the memory usage grow every tick…
This is my first go at this kind of stuff, so I’m prepared to believe it’s me. Is there any more scientific instrumentation for looking at this stuff?
Comment by erica — April 12, 2007 @ 11:06 am
I downloaded http://www.jasons-toolbox.com/JTicker/JTicker_With_JQuery.zip, but JTicker doesn’t seem to be working when I view index.html on my machine- neither with your xml file or with my own. All I see fading in and out is “JTicker 0.5 Beta.” Any ideas? This is exactly what I want to implement on my site and I want it to work soooo bad! Also, if you can answer that question, is there any way to display more than one item at a time? So, for instance, four headlines - fade out - the next four headlines - etc.
Comment by peter — April 22, 2007 @ 1:51 am
I would like to suggest a change to jHeartbeat
IE caches, and I saw how you send various HTTP/HTML headers to stop the caching. I would like to suggest adding a counter instead,
which would force IE to request the result from the server and not make anything time dependent:
In the changes, show below, I have added a counter.
If the user has already supplied a url with a parameters, then the extra parameter starts with a & instead of a ?.
options: {
url: “heartbeat_default.asp”,
counter: 0,
delay: 10000
},
beat: function() {
var c = this.options.url.search(/\?/) == -1 ? ‘?’ : ‘&’ ;
var newUrl = this.options.url + c + “counter=” + this.options.counter++ ;
$(”#HeartBeatDIV”).load(newUrl);
this.timeoutobj.id = setTimeout(”$.jheartbeat.beat();”, this.options.delay);
this.beatfunction();
Comment by peter — May 20, 2007 @ 6:25 am
The memory leak as pointed out in comment 7 is really problematic. Is there any way of fixing it?
Thanks
Peter
Comment by jasonlevine — July 24, 2007 @ 6:45 am
howie, It’s possible that there’s a memory leak in there somewhere. When I get some time, I need to update this plugin for the latest version of JQuery.
Comment by eshu — November 12, 2007 @ 5:51 am
thx for a nice plugins…
i have one question regarding JTicker
is it possible to extend somehow support for other character encodings..
for example im using Windows-1250 and can not get some special character..
i know that that is an issue…
its pitty that half of the world can not use that nice technology ;-(
thx
mario