Hi,
I have checks in my GM scripts to see if the GM functions are
available and if they aren't, recreate them. This is for cross-browser
support.
One of the checks I am using stopped working Firefox 4.
GM_setValue.toString
This works in FF3 and returns a string of the function, but FF4 throws
an exception. This is true for all the GM_ functions for FF4. typeof()
for the GM functions still return "function".
This seems to me like a bug in GM with FF4.
My source:
var gvar = new Object();
function GM_ApiBrowserCheck() {
if (typeof(unsafeWindow) == 'undefined') { unsafeWindow=window; }
if (typeof(GM_log) == 'undefined') { GM_log = function(msg) { try
{ unsafeWindow.console.log('GM_log: ' + msg); } catch(e) {} }; }
GM_clog = function(msg) { if (arguments.callee.counter)
{ arguments.callee.counter++; } else { arguments.callee.counter=1; }
GM_log('('+arguments.callee.counter+') '+msg); }
GM_addGlobalStyle = function(css) {
var sel = document.createElement('style');
sel.setAttribute('type','text/css');
sel.appendChild(document.createTextNode(css));
var hel = document.documentElement.firstChild;
while (hel && hel.nodeName != 'HEAD') { hel=hel.nextSibling; }
if (hel && hel.nodeName == 'HEAD') { hel.appendChild(sel); }
else
{ document.body.insertBefore(sel,document.body.firstChild); }
return sel;
}
var needApiUpgrade=false;
if(window.navigator.appName.match(/^opera/i) && typeof(window.opera) !
= 'undefined') {
needApiUpgrade=true; gvar.isOpera=true;
GM_log=window.opera.postError; GM_log('Opera detected...');
}
if(typeof(GM_setValue) != 'undefined') {
var gsv=GM_setValue.toString(); // this throws an exception in
FF4
if (gsv.indexOf('staticArgs') > 0) { gvar.isGreaseMonkey = true;
GM_log('GreaseMonkey Api detected...'); }
else if (gsv.match(/not\s+supported/)) { needApiUpgrade = true;
gvar.isBuggedChrome = true; GM_log('Bugged Chrome GM Api
detected...'); }
} else {
needApiUpgrade=true; GM_log('No GM Api detected...');
}
if(needApiUpgrade) {
GM_log('Try to recreate needed GM Api...');
var ws = null;
try { ws=typeof(unsafeWindow.localStorage);
unsafeWindow.localStorage.length; } catch(e) { ws=null; } // Catch
Security error
if (ws=='object') {
GM_log('Using localStorage for GM Api.');
GM_getValue=function(name,defValue) { var
value=unsafeWindow.localStorage.getItem(GMSTORAGE_PATH+name);
if(value==null) { return defValue; } else { switch(value.substr(0,2))
{ case 'S]': return value.substr(2); case 'N]': return
parseInt(value.substr(2)); case 'B]': return
value.substr(2)=='true'; } } return value; }
GM_setValue=function(name,value) { switch
(typeof(value)) { case
'string': unsafeWindow.localStorage.setItem(GMSTORAGE_PATH
+name,'S]'+value); break; case 'number':
if(value.toString().indexOf('.')<0)
{ unsafeWindow.localStorage.setItem(GMSTORAGE_PATH+name,'N]'+value); }
break; case 'boolean': unsafeWindow.localStorage.setItem(GMSTORAGE_PATH
+name,'B]'+value); break; } }
GM_deleteValue=function(name)
{ unsafeWindow.localStorage.removeItem(GMSTORAGE_PATH+name); }
} else if(!gvar.isOpera || typeof(GM_setValue)=='undefined') {
GM_log('Using temporarilyStorage for GM Api.');
gvar.temporarilyStorage=new Array();
GM_getValue=function(name,defValue)
{ if(typeof(gvar.temporarilyStorage[GMSTORAGE_PATH
+name])=='undefined') { return defValue; } else { return
gvar.temporarilyStorage[GMSTORAGE_PATH+name]; } }
GM_setValue=function(name,value) { switch
(typeof(value)) { case
"string": case "boolean": case "number":
gvar.temporarilyStorage[GMSTORAGE_PATH+name]=value; } }
GM_deleteValue=function(name) { delete
gvar.temporarilyStorage[GMSTORAGE_PATH+name]; };
}
if(typeof(GM_openInTab)=='undefined') {
GM_openInTab=function(url)
{ unsafeWindow.open(url,""); } }
if(typeof(GM_registerMenuCommand)=='undefined')
{ GM_registerMenuCommand=function(name,cmd) { GM_log("Notice:
GM_registerMenuCommand is not supported."); } } // Dummy
if(!gvar.isOpera || typeof(GM_xmlhttpRequest)=='undefined') {
GM_log('Using XMLHttpRequest for GM Api.');
GM_xmlhttpRequest=function(obj) {
var request=new XMLHttpRequest();
request.onreadystatechange=function() {
if(obj.onreadystatechange)
{ obj.onreadystatechange(request); }; if(request.readyState==4 &&
obj.onload) { obj.onload(request); } }
request.onerror=function() { if(obj.onerror)
{ obj.onerror(request); } }
try { request.open(obj.method,obj.url,true); }
catch(e)
{ if(obj.onerror) { obj.onerror( {readyState:
4,responseHeaders:'',responseText:'',responseXML:'',status:
403,statusText:'Forbidden'} ); }; return; }
if(obj.headers) { for(name in obj.headers)
{ request.setRequestHeader(name,obj.headers[name]); } }
request.send(obj.data); return request;
}
}
}
}
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.