Guest User

Untitled

a guest
Feb 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. //
  2. // GreaseKit friendly
  3. //
  4.  
  5. if(typeof GM_xmlhttpRequest === "undefined") {
  6. GM_xmlhttpRequest = function(/* object */ details) {
  7. details.method = details.method.toUpperCase() || "GET";
  8.  
  9. if(!details.url) {
  10. throw("GM_xmlhttpRequest requires an URL.");
  11. return;
  12. }
  13.  
  14. // build XMLHttpRequest object
  15. var oXhr, aAjaxes = [];
  16. if(typeof ActiveXObject !== "undefined") {
  17. var oCls = ActiveXObject;
  18. aAjaxes[aAjaxes.length] = {cls:oCls, arg:"Microsoft.XMLHTTP"};
  19. aAjaxes[aAjaxes.length] = {cls:oCls, arg:"Msxml2.XMLHTTP"};
  20. aAjaxes[aAjaxes.length] = {cls:oCls, arg:"Msxml2.XMLHTTP.3.0"};
  21. }
  22. if(typeof XMLHttpRequest !== "undefined")
  23. aAjaxes[aAjaxes.length] = {cls:XMLHttpRequest, arg:undefined};
  24.  
  25. for(var i=aAjaxes.length; i--; )
  26. try{
  27. oXhr = new aAjaxes[i].cls(aAjaxes[i].arg);
  28. if(oXhr) break;
  29. } catch(e) {}
  30.  
  31. // run it
  32. if(oXhr) {
  33. if("onreadystatechange" in details)
  34. oXhr.onreadystatechange = function() { details.onreadystatechange(oXhr) };
  35. if("onload" in details)
  36. oXhr.onload = function() { details.onload(oXhr) };
  37. if("onerror" in details)
  38. oXhr.onerror = function() { details.onerror(oXhr) };
  39.  
  40. oXhr.open(details.method, details.url, true);
  41.  
  42. if("headers" in details)
  43. for(var header in details.headers)
  44. oXhr.setRequestHeader(header, details.headers[header]);
  45.  
  46. if("data" in details)
  47. oXhr.send(details.data);
  48. else
  49. oXhr.send();
  50. } else
  51. throw ("This Browser is not supported, please upgrade.")
  52. }
  53. }
  54.  
  55. if(typeof GM_addStyle === "undefined") {
  56. function GM_addStyle(/* String */ styles) {
  57. var oStyle = document.createElement("style");
  58. oStyle.setAttribute("type", "text\/css");
  59. oStyle.appendChild(document.createTextNode(styles));
  60. document.getElementsByTagName("head")[0].appendChild(oStyle);
  61. }
  62. }
  63.  
  64. if(typeof GM_log === "undefined") {
  65. function GM_log(log) {
  66. if(console)
  67. console.log(log);
  68. else
  69. alert(log);
  70. }
  71. }
Add Comment
Please, Sign In to add comment