Eruda Loader

Load and setup Eruda with DOM plugin

目前为 2021-07-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Eruda Loader
  3. // @description Load and setup Eruda with DOM plugin
  4. // @namespace Eruda
  5. // @author RainSlide
  6. // @match *://*/*
  7. // @exclude-match https://eruda.liriliri.io/*
  8. // @version 1.1
  9. // @grant none
  10. // @run-at document-idle
  11. // @require https://cdn.jsdelivr.net/npm/eruda
  12. // @require https://cdn.jsdelivr.net/npm/eruda-dom
  13. // @noframes
  14. // ==/UserScript==
  15.  
  16. "use strict";
  17.  
  18. const getType = _ =>
  19. Object.prototype.toString.call(_)
  20. .slice(8, -1);
  21.  
  22. const error = msg =>
  23. console.error("[Eruda Loader] " + msg);
  24.  
  25. const loadError = (name, type) => {
  26. error(name + " is not an " + type);
  27. return false;
  28. }
  29.  
  30. const isErudaLoaded =
  31. getType(window.eruda) !== "Object"
  32. ? loadError("window.eruda", "Object")
  33. : getType(eruda._isInit) !== "Boolean"
  34. ? loadError("eruda._isInit", "Boolean")
  35. : true;
  36.  
  37. if (
  38. isErudaLoaded &&
  39. eruda._isInit === false
  40. ) {
  41.  
  42. eruda.init();
  43.  
  44. /*
  45. eruda.init({
  46. // container: containerElement,
  47. // tool: [ "toolName1", "toolName2" ],
  48. // useShadowDom: true,
  49. // autoScale: true,
  50. // defaults: {
  51. // transparency: 1,
  52. // displaySize: 80,
  53. // theme: "themeName"
  54. // }
  55. });
  56. */
  57.  
  58. eruda.get("console").config.set(
  59. "maxLogNum", 256
  60. );
  61.  
  62. eruda.add(erudaDom);
  63.  
  64. (() => {
  65.  
  66. eruda._shadowRoot.appendChild(
  67. document.createElement("style")
  68. ).textContent = `
  69. /* use monospace font */
  70. #eruda-console .eruda-logs-container,
  71. #eruda-elements .eruda-parents,
  72. #eruda-elements .eruda-breadcrumb,
  73. #eruda-elements .eruda-children,
  74. #eruda-elements .eruda-table-wrapper,
  75. #eruda-elements .eruda-style-rules,
  76. #eruda-resources table,
  77. #eruda-sources .eruda-code-wrapper,
  78. #eruda-sources .eruda-raw-wrapper {
  79. font-family: monospace;
  80. }
  81.  
  82. /* Circlize the entry button */
  83. .eruda-container .eruda-entry-btn {
  84. border-radius: 50%;
  85. }
  86. /* Centerize its icon */
  87. .eruda-icon-tool {
  88. font-size: 28px;
  89. }
  90. .eruda-icon-tool::before {
  91. vertical-align: middle;
  92. }
  93.  
  94. `.trim();
  95.  
  96. })();
  97.  
  98. }