Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="description" content="A better browser console log">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>JS Bin</title>
  8. <style id="jsbin-css">
  9. .console-container {
  10. position: absolute;
  11. background-color: #16a085;
  12. width: 100%;
  13. min-height: 100px;
  14. bottom: 0;
  15. }
  16.  
  17. .console-output {
  18. margin: 1em;
  19. width:94%;
  20. min-height: 100px;
  21. max-height: 200px;
  22. background-color: white;
  23. overflow: auto;
  24. }
  25.  
  26. .console-edit {
  27. margin-top: 1em;
  28. margin-left:1em;
  29. margin-right: 1em;
  30. margin-bottom:0;
  31. height:1.9em;
  32. width: 94%;
  33.  
  34. }
  35.  
  36. .console-output-data {
  37. padding: 0.3em;
  38. border: 1px solid #ecf0f1;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43.  
  44. <script id="jsbin-javascript">
  45. (function (c) {
  46. var olog = c.log.bind(this);
  47.  
  48. if (!c.SHOW_CUSTOM_CONSOLE) return;
  49.  
  50. c.log = function () {
  51. for(var i = 0; i < arguments.length; i++) {
  52. olog(arguments[i]);
  53. log(arguments[i]);
  54. }
  55. }; // log ends
  56.  
  57. function log(data) {
  58. var output = document.getElementById("console-output");
  59. output.insertAdjacentHTML("afterbegin", "<div class='console-output-data'>" + data + "</div>");
  60. }
  61.  
  62. setupConsoleUI();
  63.  
  64. function setupConsoleUI () {
  65. var logPanel = document.createElement('div');
  66. logPanel.setAttribute("id", "console-container");
  67.  
  68. document.body.append(logPanel);
  69. logPanel.classList.add("console-container");
  70.  
  71. document.getElementById('console-container')
  72. .insertAdjacentHTML('beforeend',
  73. '<button title="click to clear console" id="console-btn-clear">X</button>');
  74.  
  75.  
  76. document.getElementById('console-container')
  77. .insertAdjacentHTML('beforeend',
  78. '<textarea placeholder="enter javascript code here..." id="console-edit" class="console-edit"></textarea>');
  79.  
  80. document.getElementById('console-container')
  81. .insertAdjacentHTML('beforeend',
  82. '<div id="console-output" class="console-output"></div>');
  83.  
  84.  
  85. }
  86.  
  87. var consoleInput = document.getElementById("console-edit");
  88. consoleInput.addEventListener("keydown", function () {
  89. if (event.which === 13 && event.ctrlKey) {
  90. console.log(eval(event.target.value));
  91. event.target.value = "";
  92.  
  93. }
  94. });
  95.  
  96. var btnClear = document.getElementById("console-btn-clear");
  97. var consoleOutput = document.getElementById("console-output");
  98. btnClear.addEventListener("click", function () {
  99. consoleOutput.innerHTML = "";
  100. });
  101.  
  102. })(console);
  103.  
  104. console.SHOW_CUSTOM_CONSOLE = true;
  105.  
  106. for(var i = 0; i < 20; i++) {
  107. console.log(i);
  108. }
  109.  
  110. console.log("Will this work!");
  111. </script>
  112.  
  113.  
  114. <script id="jsbin-source-css" type="text/css">.console-container {
  115. position: absolute;
  116. background-color: #16a085;
  117. width: 100%;
  118. min-height: 100px;
  119. bottom: 0;
  120. }
  121.  
  122. .console-output {
  123. margin: 1em;
  124. width:94%;
  125. min-height: 100px;
  126. max-height: 200px;
  127. background-color: white;
  128. overflow: auto;
  129. }
  130.  
  131. .console-edit {
  132. margin-top: 1em;
  133. margin-left:1em;
  134. margin-right: 1em;
  135. margin-bottom:0;
  136. height:1.9em;
  137. width: 94%;
  138.  
  139. }
  140.  
  141. .console-output-data {
  142. padding: 0.3em;
  143. border: 1px solid #ecf0f1;
  144. }</script>
  145.  
  146. <script id="jsbin-source-javascript" type="text/javascript">(function (c) {
  147. var olog = c.log.bind(this);
  148.  
  149. if (!c.SHOW_CUSTOM_CONSOLE) return;
  150.  
  151. c.log = function () {
  152. for(var i = 0; i < arguments.length; i++) {
  153. olog(arguments[i]);
  154. log(arguments[i]);
  155. }
  156. }; // log ends
  157.  
  158. function log(data) {
  159. var output = document.getElementById("console-output");
  160. output.insertAdjacentHTML("afterbegin", "<div class='console-output-data'>" + data + "</div>");
  161. }
  162.  
  163. setupConsoleUI();
  164.  
  165. function setupConsoleUI () {
  166. var logPanel = document.createElement('div');
  167. logPanel.setAttribute("id", "console-container");
  168.  
  169. document.body.append(logPanel);
  170. logPanel.classList.add("console-container");
  171.  
  172. document.getElementById('console-container')
  173. .insertAdjacentHTML('beforeend',
  174. '<button title="click to clear console" id="console-btn-clear">X</button>');
  175.  
  176.  
  177. document.getElementById('console-container')
  178. .insertAdjacentHTML('beforeend',
  179. '<textarea placeholder="enter javascript code here..." id="console-edit" class="console-edit"></textarea>');
  180.  
  181. document.getElementById('console-container')
  182. .insertAdjacentHTML('beforeend',
  183. '<div id="console-output" class="console-output"></div>');
  184.  
  185.  
  186. }
  187.  
  188. var consoleInput = document.getElementById("console-edit");
  189. consoleInput.addEventListener("keydown", function () {
  190. if (event.which === 13 && event.ctrlKey) {
  191. console.log(eval(event.target.value));
  192. event.target.value = "";
  193.  
  194. }
  195. });
  196.  
  197. var btnClear = document.getElementById("console-btn-clear");
  198. var consoleOutput = document.getElementById("console-output");
  199. btnClear.addEventListener("click", function () {
  200. consoleOutput.innerHTML = "";
  201. });
  202.  
  203. })(console);
  204.  
  205. console.SHOW_CUSTOM_CONSOLE = true;
  206.  
  207. for(var i = 0; i < 20; i++) {
  208. console.log(i);
  209. }
  210.  
  211. console.log("Will this work!");</script></body>
  212. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement