Making some GM_* functions work again in GreaseKit 1.4

12 views
Skip to first unread message

Nils

unread,
Jun 16, 2008, 5:26:24 AM6/16/08
to GreaseKit Users
Thanks for "greut" at http://userscripts.org/forums/1/topics/1912 for
finding this hint:

if(typeof GM_xmlhttpRequest === "undefined") {
GM_xmlhttpRequest = function(/* object */ details) {
details.method = details.method.toUpperCase() || "GET";

if(!details.url) {
throw("GM_xmlhttpRequest requires an URL.");
return;
}

// build XMLHttpRequest object
var oXhr, aAjaxes = [];
if(typeof ActiveXObject !== "undefined") {
var oCls = ActiveXObject;
aAjaxes[aAjaxes.length] = {cls:oCls, arg:"Microsoft.XMLHTTP"};
aAjaxes[aAjaxes.length] = {cls:oCls, arg:"Msxml2.XMLHTTP"};
aAjaxes[aAjaxes.length] = {cls:oCls, arg:"Msxml2.XMLHTTP.3.0"};
}
if(typeof XMLHttpRequest !== "undefined")
aAjaxes[aAjaxes.length] = {cls:XMLHttpRequest, arg:undefined};

for(var i=aAjaxes.length; i--; )
try{
oXhr = new aAjaxes[i].cls(aAjaxes[i].arg);
if(oXhr) break;
} catch(e) {}

// run it
if(oXhr) {
if("onreadystatechange" in details)
oXhr.onreadystatechange = function()
{ details.onreadystatechange(oXhr) };
if("onload" in details)
oXhr.onload = function() { details.onload(oXhr) };
if("onerror" in details)
oXhr.onerror = function() { details.onerror(oXhr) };

oXhr.open(details.method, details.url, true);

if("headers" in details)
for(var header in details.headers)
oXhr.setRequestHeader(header, details.headers[header]);

if("data" in details)
oXhr.send(details.data);
else
oXhr.send();
} else
throw ("This Browser is not supported, please upgrade.")
}
}

if(typeof GM_addStyle === "undefined") {
function GM_addStyle(/* String */ styles) {
var oStyle = document.createElement("style");
oStyle.setAttribute("type", "text\/css");
oStyle.appendChild(document.createTextNode(styles));
document.getElementsByTagName("head")[0].appendChild(oStyle);
}
}

if(typeof GM_log === "undefined") {
function GM_log(log) {
if(console)
console.log(log);
else
alert(log);
}
}

mr_justin

unread,
Aug 3, 2008, 2:06:43 PM8/3/08
to GreaseKit Users
What about get/set, will we see this again soon or is there a
workaround besides using cookies?

-justin
Reply all
Reply to author
Forward
0 new messages