Adapting an Opera User Javascript (for RTM) Into a Greasemonkey Script?

Subscribe to Adapting an Opera User Javascript (for RTM) Into a Greasemonkey Script? 12 posts, 5 voices

 
WCityMike Scriptwright

Occurred to me this is the more suitable forum, so I figured I'd post this here instead.

In an Opera forum, a user posted this Javascript to override Remember the Milk's built-in sidebar animation code:

(function(st){
window.setTimeout = function(s,t){
if(/moveDiv\(/.test(s))
arguments[1]=1;
st.apply(this,arguments);
};
})(window.setTimeout);

http://my.opera.com/community/forums/topic.dml?...

I tried to adapt this into a Greasemonkey script, but see no difference on the page in question. Any idea on how one might go about doing this?

Thanks in advance!

 
Henrik N Admin

Try replacing window with unsafeWindow.

 
WCityMike Scriptwright

My script now is quite literally just this (aside from the metadata block):

(function(st){
unsafeWindow.setTimeout = function(s,t){
if(/moveDiv\(/.test(s))
arguments[1]=1;
st.apply(this,arguments);
};
})(unsafeWindow.setTimeout);

I don't see any significant difference in what it's supposed to speed up. I must admit I'm not a heavy scripter; I'm more a splicer than a scriptwright. Any idea what I might be missing?

 
WCityMike Scriptwright

Anyone still checking this poor little thread? ;-)

 
WCityMike Scriptwright

Damn. I was really hoping I could get this set up as a Greasemonkey script. :(

 
WCityMike Scriptwright

Bump. Anyone able to assist me?

 
Michael Devore Scriptwright

Your script revisions work using unsafeWindow, they just doesn't help very much with the animation overhead (e.g. try setting the argument to 1000 instead of 1 and things will slow to a crawl). If it is seriously bothersome, you might consider the approach of driving a stake through the heart of their silly animation code. The following hack places the RTM sidebar without the associated animation; you can use as it is or polish it up. Tested as successful on the http://www.rememberthemilk.com site as a user with basic task list, but only minimally: might be bugs, might be unwanted side-effects, might be incompatible with other pages, definitely isn't elegant or optimal.

(function(st)
{
unsafeWindow.setTimeout = function(s,t)
{
if (/moveDiv\(/.test(s))
{
unsafeWindow.setInterval(function ()
{
var L = document.getElementById("detailsbox");
L.style.top = window.pageYOffset+"px";
unsafeWindow.Autocomplete.handleWindowResize();
}, 50);
}
else
{
st.apply(this, arguments);
}
};
})(unsafeWindow.setTimeout);

 
Michael Devore Scriptwright

Ate my code's indents, guess I should of used PRE. Welp, works with or without it.

 
WCityMike Scriptwright

That's so very, very, very, very wonderful, Michael. Sorry for the delay, but I haven't checked the forum in a few days. I can't believe how fantastic that is! I will update the script accordingly, giving full credit to you ...

 
WCityMike Scriptwright

Updated and now at http://userscripts.org/scripts/show/7825, with full credit to you, Michael. Thanks so very much!

 
Stu Cox User

Hi, I'd like to propose the following revised version of this script, entirely based on the version you pasted on 4th April 2007. Basically, the gripe I had with the script was it was very "jumpy" when scrolling. By making the detailsbox div fixed (using CSS), it doesn't jump when you scroll. You can then use the javascript repositioning to set the appropriate horizontal position, which will act if you resize the window (an action you're likely to do much less often than scrolling, so i felt "jumpiness" was acceptable here).

The one bug I've found which this suffers from (which your version also suffered from) is that the blue dotted line connecting a task to the details box is broken when you move the page - not a massive issue at all really, although maybe someone with more time on their hands would like to look into how to fix that!

I'm certainly not an expert in these things, so if anyone sees a major flaw with my suggestion, please say.

I should probably add that I've only tested this in Firefox so far as I don't currently have Opera installed.

// ------------
var L = unsafeWindow.document.getElementById("detailsbox");
var M = unsafeWindow.document.getElementById("listbox");

L.style.position = "fixed !important";

L.moveDiv = function () {
	var L = unsafeWindow.document.getElementById("detailsbox");
	L.style.left = M.offsetLeft+M.offsetWidth+16+"px";
	unsafeWindow.Autocomplete.handleWindowResize();
};
// ----------------

Regards,

Stu

 
dob Scriptwright

Of course this won't work in Opera since unsafeWindow is a Greasemonkey object.