WM Debug Console

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

Bu script direkt olarak kurulamaz. Başka scriptler için bir kütüphanedir ve meta yönergeleri içerir // @require https://update.greatest.deepsurf.us/scripts/408/1285/WM%20Debug%20Console.js

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