ajax log gm

ajax log library for GM usage

Този скрипт не може да бъде инсталиран директно. Това е библиотека за други скриптове и може да бъде използвана с мета-директива // @require https://update.greatest.deepsurf.us/scripts/39411/258015/ajax%20log%20gm.js

  1. // ==UserScript==
  2. // @name ajax log gm
  3. // @namespace https://greatest.deepsurf.us/users/174399
  4. // @description ajax log library for GM usage
  5. // @version 0.5.1
  6. // ==/UserScript==
  7.  
  8. window.GM_xmlhttpRequest = window.GM_xmlhttpRequest || function(){
  9. alert("Error: your script doesn't include GM_xmlhttpRequest API!\r\n" +
  10. "In order to script works you should include GM_xmlhttpRequest");
  11. };
  12. (function(){
  13. var _ajaxLog = {},
  14. inited = null,
  15. scriptName = 'ajax log',
  16. scriptVersion = '0.5.1',
  17. url = "https://greatest.deepsurf.us/scripts/39403-ajax-log/code/ajax%20log.js?version=258004",
  18. link;
  19. Object.defineProperties( _ajaxLog, {
  20. 'name': {
  21. get(){return scriptName;},
  22. enumerable: true,
  23. },
  24. 'version': {
  25. get(){return scriptVersion;},
  26. enumerable: true,
  27. },
  28. 'nameVer': {
  29. get(){return scriptName + ' v' + scriptVersion;},
  30. enumerable: true,
  31. },
  32. 'start': {
  33. value: function(){
  34. if( !inited )
  35. startLog();
  36. inited = true;
  37. },
  38. enumerable: true,
  39. },
  40. });
  41. function startLog()
  42. {
  43. console.log('document.readyState: ', document.readyState );
  44. var handleDOMLoad = function handleDOMLoad(){
  45. startLog();
  46. this.removeEventListener('DOMContentLoaded', handleDOMLoad);
  47. };
  48. switch(document.readyState)
  49. {
  50. case 'loading': return document.addEventListener('DOMContentLoaded', handleDOMLoad);
  51. case 'interactive':
  52. case 'complete':
  53. break;
  54. default: return;
  55. }
  56. console.log(_ajaxLog.nameVer + ' start');
  57. var s = new Promise(function(f){
  58. GM_xmlhttpRequest({
  59. url: getLocation(url),
  60. method: 'GET',
  61. headers: {'Referer': getLocation(url, 'origin')},
  62. onload: function(r){f(r.response);},
  63. });
  64. }).then(function(r){
  65. var script = document.createElement('script'),
  66. body = document.body || document.querySelector('body');
  67. script.type = 'text/javascript';
  68. script.innerHTML = r;
  69. body.appendChild(script);
  70. setTimeout(function(){body.removeChild(script);}, 1e4);
  71. });
  72. }
  73. Object.defineProperty(window, 'ajaxLog', {
  74. get(){return _ajaxLog;},
  75. enumerable: true,
  76. });
  77. function getLocation(u, p)
  78. {
  79. link = link || document.createElement('a');
  80. link.href = u;
  81. return link[p||'href'];
  82. }
  83. })();