WM Debug Console

Creates a debug console that slides up from the bottom right of the screen

بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @require https://update.greatest.deepsurf.us/scripts/417/1299/WM%20Debug%20Console.js

  1. // ==UserScript==
  2. // @name WM Debug Console
  3. // @namespace MerricksdadDebugConsole
  4. // @description Creates a debug console that slides up from the bottom right of the screen
  5. // @license http://creativecommons.org/licenses/by-nc-nd/3.0/us/
  6. // @version 3.0.0.5
  7. // @copyright Charlie Ewing except where noted
  8. // ==/UserScript==
  9.  
  10. //this script requires some functions in the WM Common Library
  11. //this script needs access to a pre-defined JSON object
  12.  
  13. (function(){
  14. this.debug = {
  15. doDebug: true, //always true until told otherwise after gmconfig loads
  16. debugLevel: 0, //always max until told otherwise in run function
  17. debugMaxComments: 100,
  18. useScrollIntoView: false,
  19. stackRepeats: false,
  20. lastPkg:null,
  21.  
  22. initialized: false,
  23. windowNode: null, //container for created debug window
  24. messageNode: null,
  25.  
  26. init: function(params){try{
  27. params=params||{};
  28.  
  29. if (!($("WM_debugWindow"))) {
  30. addGlobalStyle(""+
  31. "#WM_debugWindow {height:249px; position:fixed; right: 2px; bottom: 2px; z-index: 9999; width: 50%; transition-property:'bottom'; transition-duration:1s; transition-timing-function:ease-in-out;}\n"+
  32. "#WM_debugWindow.tuck {transition-property: 'bottom'; transition-duration:1s; bottom:-220px; transition-timing-function:ease-in-out;}\n"+
  33. "#WM_debugWindow a {color:white;}\n"+
  34. ".errConsoleLine {padding-top: 3px; padding-bottom: 3px; border-bottom:solid #760202 2px;}\n"+
  35. ".errConsoleScript {}\n"+
  36. ".errConsoleFunction {}\n"+
  37. ".errConsoleMessages {height:220px;overflow: scroll;color: #FFCA5E; background-color: #CA0704; background-image: -moz-linear-gradient(top, #CA0704, #9C0505); font-weight: bold; font-size: 12px; border-radius: 0px 5px 5px 5px; border:solid #760202 3px;padding-left: 6px; padding-right: 6px;}\n"+
  38. ".errConsoleLineNum {}\n"+
  39. ".errConsoleErrNum {}\n"+
  40. ".errConsoleMessage {}\n"+
  41. ".errConsoleComment {}\n"+
  42. ".errConsoleButtonBorder {border-radius: 5px 5px 0px 0px; border:solid #760202 2px; border-bottom:0px;}\n"+
  43. ".errConsoleCloseButton {background-color: #9F0A0C; background-image: -moz-linear-gradient(top, #FFDDBA, #9F0A0C);font-size: 12px; font-weight: bold; color: white; border-radius: 5px 5px 0px 0px; border:solid #BE1A11 2px;border-bottom:0px;padding: 6px;display:inline-block;}\n"+
  44. ""
  45. ,"styleDebug");
  46. document.body.appendChild(
  47. debug.windowNode = createElement("div",{id:"WM_debugWindow",className:"tuck"},[
  48. //createElement("div",{className:"errConsoleButtonBorder"},[]),
  49. createElement("a",{href:jsVoid,className:"errConsoleCloseButton",textContent:"Debug",onclick:debug.toggle}),
  50. debug.messageNode=createElement("div",{href:jsVoid,className:"errConsoleMessages"})
  51.  
  52. ])
  53. );
  54. }
  55. debug.initialized = true;
  56. }catch(e){log("debug.init: "+e);}},
  57.  
  58. print: function(msg, params){try{
  59. if (!debug.doDebug) return;
  60. params=params||{};
  61.  
  62. if (!debug.initialized) debug.init();
  63. if (!debug.initialized) return;
  64.  
  65. //confirm(params.level);
  66. var level=params["level"]||6; //default to top level status
  67. if (level<debug.debugLevel) return; //dont show unwanted level warnings and errors
  68.  
  69. var line=params["lineNumber"]||"";
  70. var script=params["scriptName"]||"";
  71. var func=params["functionName"]||"";
  72. var errnum=params["errorNumber"]||"";
  73. var comment=params["comment"]||"";
  74. var type=params["type"]||"";
  75. var pkg={};
  76. if (debug.messageNode) {
  77. pkg.container=createElement("div",{className:"errConsoleLine "+type},[
  78. pkg.scriptName=createElement("span",{className:"errConsoleScript",textContent:script}),
  79. pkg.functionName=createElement("span",{className:"errConsoleFunction",textContent:func}),
  80. pkg.lineNumber=createElement("span",{className:"errConsoleLineNum",textContent:line}),
  81. pkg.errorNumber=createElement("span",{className:"errConsoleErrNum",textContent:errnum}),
  82. pkg.msg=createElement("span",{className:"errConsoleMessage",innerHTML:msg}),
  83. pkg.comment=createElement("span",{className:"errConsoleComment",textContent:comment}),
  84. pkg.counter=createElement("span",{className:"errConsoleCounter",textContent:""}),
  85. ])
  86. if (!debug.stackRepeats || pkg!=(debug.lastPkg||null)) {
  87. var node = debug.messageNode.appendChild(pkg.container)
  88. if (debug.useScrollIntoView) node.scrollIntoView();
  89. debug.lastPkg=pkg;
  90. } else {
  91. //stack duplicates
  92. if (debug.lastPkg||null) {
  93. var counterNode=debug.lastPkg.counter;
  94. counterNode.textContent = (parseInt(counterNode.textContent)||0)+1;
  95. }
  96. }
  97. }
  98.  
  99. debug.cleanComments();
  100. return pkg;
  101.  
  102. //debug.show();
  103. }catch(e){GM_log("debug.print: "+e);}},
  104.  
  105. cleanComments: function(){try{
  106. if (!debug.messageNode) return;
  107. if (debug.debugMaxComments==0) return;
  108. var comments = selectNodes(".//div[contains(@class,'errConsoleLine')]",{node:debug.messageNode});
  109. if (comments.snapshotItem) {
  110. var count = comments.snapshotLength-debug.debugMaxComments;
  111. if (count>0) {
  112. for (var i=0;i<count;i++){
  113. var node=comments.snapshotItem(i);
  114. node.parentNode.removeChild(node);
  115. node=null;
  116. }
  117. }
  118. }
  119. comments=null;
  120. }catch(e){log("debug.cleanComments: "+e);}},
  121.  
  122. show: function(){try{
  123. if (!debug.initialized) debug.init();
  124. if (!debug.initialized) return;
  125.  
  126. if (debug.windowNode) debug.windowNode.style.display="";
  127. }catch(e){log("debug.show: "+e);}},
  128.  
  129. hide: function(){try{
  130. if (!debug.initialized) debug.init();
  131. if (!debug.initialized) return;
  132.  
  133. if (debug.windowNode) debug.windowNode.style.display="none";
  134. }catch(e){log("debug.hide: "+e);}},
  135.  
  136. toggle: function(){try{
  137. if (!debug.initialized) debug.init();
  138. if (!debug.initialized) return;
  139.  
  140. if (debug.windowNode) {
  141. //var isClosed = parseInt(debug.windowNode.style.bottom)<0;
  142. //slide(debug.windowNode,0,0,0,(isClosed)?220:-220,1);
  143. debug.windowNode.className = debug.windowNode.className.toggleWord("tuck");
  144. }
  145. }catch(e){log("debug.toggle: "+e);}},
  146. };
  147. })();