Go.dev Code Highlight

Golang code highlighter

当前为 2023-12-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Go.dev Code Highlight
  3. // @namespace GolangDevNamespace
  4. // @version 1.0.2
  5. // @description Golang code highlighter
  6. // @author Anton Vi
  7. // @match https://*.go.dev/*
  8. // @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/go.min.js
  10. // @grant none
  11. // @license GNU GPLv3
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. start();
  18.  
  19.  
  20. })();
  21.  
  22.  
  23. function start() {
  24.  
  25. let css = `
  26. pre {
  27. padding: 0;
  28. }
  29.  
  30. pre code.hljs {
  31. display: block;
  32. overflow-x: auto;
  33. padding: 1em
  34. }
  35.  
  36. code.hljs {
  37. padding: 3px 5px
  38. }
  39.  
  40. .hljs {
  41. color: #abb2bf !important;
  42. background: #282c34
  43. }
  44.  
  45. .hljs-comment,
  46. .hljs-quote {
  47. color: #5c6370;
  48. font-style: italic
  49. }
  50.  
  51. .hljs-doctag,
  52. .hljs-formula,
  53. .hljs-keyword {
  54. color: #c678dd
  55. }
  56.  
  57. .hljs-deletion,
  58. .hljs-name,
  59. .hljs-section,
  60. .hljs-selector-tag,
  61. .hljs-subst {
  62. color: #e06c75
  63. }
  64.  
  65. .hljs-literal {
  66. color: #56b6c2
  67. }
  68.  
  69. .hljs-addition,
  70. .hljs-attribute,
  71. .hljs-meta .hljs-string,
  72. .hljs-regexp,
  73. .hljs-string {
  74. color: #98c379
  75. }
  76.  
  77. .hljs-attr,
  78. .hljs-number,
  79. .hljs-selector-attr,
  80. .hljs-selector-class,
  81. .hljs-selector-pseudo,
  82. .hljs-template-variable,
  83. .hljs-type,
  84. .hljs-variable {
  85. color: #d19a66
  86. }
  87.  
  88. .hljs-bullet,
  89. .hljs-link,
  90. .hljs-meta,
  91. .hljs-selector-id,
  92. .hljs-symbol,
  93. .hljs-title {
  94. color: #61aeee
  95. }
  96.  
  97. .hljs-built_in,
  98. .hljs-class .hljs-title,
  99. .hljs-title.class_ {
  100. color: #e6c07b
  101. }
  102.  
  103. .hljs-emphasis {
  104. font-style: italic
  105. }
  106.  
  107. .hljs-strong {
  108. font-weight: 700
  109. }
  110.  
  111. .hljs-link {
  112. text-decoration: underline
  113. }
  114. `;
  115.  
  116. let style = document.createElement('style');
  117. let cssText = document.createTextNode(css);
  118. style.appendChild(cssText);
  119. document.head.appendChild(style);
  120.  
  121. // loop pre-s
  122. let pre_s = document.getElementsByTagName('pre');
  123. for (let el of pre_s) {
  124. let text = el.innerHTML;
  125.  
  126. el.innerHTML = '';
  127.  
  128. let code = document.createElement('code');
  129. code.className = 'language-go';
  130. code.innerHTML = text;
  131. el.appendChild(code);
  132. }
  133.  
  134.  
  135. // load scripts with timeout
  136. setTimeout(() => {
  137. hljs.highlightAll();
  138. }, 100)
  139. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址