ModifiedMacros: Safari & Greasekit, anyone for Opera?

27 views
Skip to first unread message

sewpafly

unread,
Aug 15, 2008, 2:04:40 PM8/15/08
to GMail Power Users
I'm reposting a comment from userscripts ModifiedMacros comment area
because I would like some discussion and ideas for the best way to
handle the script between browsers. I would love to be able to test
the following changes and make them work, but unfortunately I don't
have a Mac on which to test this (how come no greasekit for windows
safari?). I started trying to get it to work on Opera at one point,
and gave up after a half an hour, anybody else have any luck? Does
anyone care?

/** BEGIN COMMENT **/

Hi, I'm using Safari and GreaseKit and I was able to make your script
work (kind of). All I had to do was replace the addEventListener part
at the beggining for this:

window.addEventListener('load', function() {
var gmailapi = typeof unsafeWindow != "undefined" &&
unsafeWindow.gmonkey || (frames.js ? frames.js.gmonkey : null)
gmailapi.load('1.0', init)
}, true);

Also I had to add the following function:

function Iterator(o) {
var r = [];
for (x in o) {
r.push(x);
}
return r;
}

There are several issues while using it in safari such as:
- you're unable to save mappings because GM_* functions don't appear
to exist in GreaseKit
- transparency doesn't work
- probably many more issues since I just started trying it

I don't really care about transparency and mappings I can fix it by
modifying the defaults in the script.

It would be great if you could adapt future versions of the scripts to
at least work in this fashion (if you don't want to define the
Iterator function for GreaseMonkey you probably could put it inside an
"if" checking (typeof unsafeWindow == "undefined").

Oh, by the way, in Safari I can refresh GMail without clearing the
cache or anything and the script continues to work, so I'm guessing
that the problem that shows up in FF with greasemonkey is related to
the GM_* functions. Just in case you're interested in tracking down
that problem (which I find kind of annoying when in linux and using
FF)

/** END COMMENT **/

I'm wondering if Santiago wants to fork off a version for the Mac and
maintain that. Anybody interested?

Santiago Perez

unread,
Aug 15, 2008, 3:11:50 PM8/15/08
to GMail Power Users
Hi, I don't see the need to fork off a version, perhaps we could make
the regular version work in both (or even more) browsers. I wouldn't
have a problem to test new versions and debug when errors show up in
Safari. I would also be willing to suggest and contribute features to
the main version.

JonFrum

unread,
Sep 1, 2008, 2:57:18 PM9/1/08
to GMail Power Users
Well, I for one would be very interested in a Safari compatible
release.

sewpafly

unread,
Sep 2, 2008, 1:55:59 PM9/2/08
to GMail Power Users
I asked Santiago for his edits yesterday and will merge them in after
I get them... Anyone heard anything about a greasekit that works on
windows? It will be interesting to see if the new google browser
(also built off webkit) will have some greasemonkey abilities.

Santiago Perez

unread,
Sep 2, 2008, 2:05:53 PM9/2/08
to gmail-po...@googlegroups.com
Yes, I haven't been with my mac yet, I'll send you the modified script as soon as I get to it.

Joseph Dries

unread,
Sep 8, 2008, 8:43:21 PM9/8/08
to GMail Power Users
*sigh*. I didn't reply all ...

On Aug 15, 2:04 pm, sewpafly <sewpa...@gmail.com> wrote:
> There are several issues while using it in safari such as:
> - you're unable to save mappings because GM_* functions don't appear
> to exist in GreaseKit
> - transparency doesn't work
> - probably many more issues since I just started trying it
>
> I don't really care about transparency and mappings I can fix it by
> modifying the defaults in the script.

You can get transparency working by using webkit* css descriptors in
addition to the Moz* descriptors, like such:

MozBorderRadius = "10px";
webkitBorderRadius = "10px";

MozOpacity = "0.5";
webkitOpacity = "0.5";

and

this.backgroundNode.style.MozOpacity = "0.70";
this.backgroundNode.style.webkitOpacity = "0.70";

You can also get the GM_* convenience functions (mostly) working by
adding the following:

// Add Missing GM_ API functions for GreaseKit
//
if (typeof(GM_addStyle) != 'function') {
function GM_addStyle(css) {
var head = document.getElementsByTagName('head');
if (!!head) {
var style = document.createElement('style');
style.type = 'text/css';
style.textContent = css;
head[0].appendChild(style);
}
}
}
if (typeof(GM_setValue) != 'function' && typeof(GM_getValue) !=
'function') {
function GM_setValue(name, value) {
document.cookie = [
name, '=', escape(value),
';expires=', (new Date(new Date().getTime() + 365 * 1000 * 60 * 60
* 24)).toGMTString()
].join('');
}
function GM_getValue(name, value) {
var r = new RegExp(name + '=([^;]*)'), m;
if (m = document.cookie.match(r)) {
return unescape(m[1]);
}
return value;
}
function GM_delValue(name, value) {
if (GM_getValue(name, false))
document.cookie = name + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
} else {
var GM_delValue = GM_setValue;
}

The only other main bits that are missing are the fixes for
addEventListener (given above) and the use of Iterators (also defined
above).

> I'm wondering if Santiago wants to fork off a version for the Mac and
> maintain that.  Anybody interested?

I'm definitely interested in a single, unified script for both FF and
Safari/Mac so that I do not have to continue to backport features or
maintain multiple scripts.

Best,
~d

Joseph Dries

unread,
Sep 9, 2008, 1:40:34 AM9/9/08
to GMail Power Users
On Aug 15, 2:04 pm, sewpafly <sewpa...@gmail.com> wrote:
> Hi, I'm using Safari and GreaseKit and I was able to make your script
> work (kind of). All I had to do was replace the addEventListener part
> at the beggining for this:
>
> window.addEventListener('load', function() {
>   var gmailapi = typeof unsafeWindow != "undefined" &&
> unsafeWindow.gmonkey || (frames.js ? frames.js.gmonkey : null)
>   gmailapi.load('1.0', init)
> }, true);

Actually, after having installed Google Gears BETA for Safari, this
didn't work for me. Must be some delay in loading all of the
components. With the base assumption that this script will be loaded
using GreaseMonkey or GreaseKit (I did not test on Opera 9.x) and that
unsafeWindow or frames.js.gmonkey would *eventually* be defined, the
addEventListener function should look a little something like this:

window.addEventListener('load', function() {
(function(){
var gmailapi = typeof unsafeWindow != "undefined" &&
unsafeWindow.gmonkey
|| (frames.js ? frames.js.gmonkey : null);
if (gmailapi == null) {
setTimeout(arguments.callee, 0);
return;
}
gmailapi.load('1.0', init);
})();
}, false);

Without this change, gmailapi is always assigned null, and thus the
addEventListener never fires because gmailapi.load throws an TypeError
on evaluation.

Best,
~d

sewpafly

unread,
Sep 9, 2008, 12:19:51 PM9/9/08
to GMail Power Users
Webkit users, heres the compilation of the above changes (thanks to
Mr. Dries) http://gmail-power-users.googlegroups.com/web/modifiedgmailmacros_webkit_beta.user.js

I haven't put this into use with firefox yet, but wanted to let other
people start using it and getting feedback. If someone does try it
with greasemonkey/firefox and sees any problems, let me know.

Also, it does not work with Opera. Are there any opera gurus out
there that know why?

Santiago Perez

unread,
Sep 9, 2008, 10:18:09 PM9/9/08
to gmail-po...@googlegroups.com
Hi, sorry I didn't get back to you about my modified script but I had made several other modifications to the behavior of the script and I have been pretty busy and I didn't get a chance to migrate the changes to an unmodified version of the script. I have been revising the script you sent and it has all of the changes I had made to make it work with greasekit and I also tried it and it effectively solves the transparency issues. So if that version works properly in FF it would be a great if that could became the official version.

Even though you seem to have fixed the GM_{get,set}Value functions, the help screen doesn't work, the links don't open the specific forms so it is still imposible to configure the shortcuts through the UI if I find time to do it I'll try to look into it.

Regards,
Santiago
Reply all
Reply to author
Forward
0 new messages