()
| 87 | // ==/UserScript== |
| 88 | |
| 89 | function addCustomCSS() { |
| 90 | const css = ` |
| 91 | pre code { |
| 92 | font-size: 12px !important; /* 设置字体大小为12px */ |
| 93 | white-space: pre-wrap !important; /* 设置自动换行 */ |
| 94 | word-break: break-word !important; /* 设置单词断行 */ |
| 95 | } |
| 96 | pre { |
| 97 | overflow-x: auto !important; /* 允许水平滚动 */ |
| 98 | } |
| 99 | ` |
| 100 | |
| 101 | function applyStyles() { |
| 102 | let styleNode = document.createElement('style') |
| 103 | styleNode.appendChild(document.createTextNode(css)); |
| 104 | (document.querySelector('head') || document.documentElement).appendChild(styleNode) |
| 105 | } |
| 106 | |
| 107 | // 初次应用样式 |
| 108 | applyStyles() |
| 109 | |
| 110 | setInterval(() => { |
| 111 | // 检查样式是否仍在<head>中 |
| 112 | const styles = document.querySelectorAll('style') |
| 113 | const styleExists = Array.from(styles).some(style => style.textContent.includes(css)) |
| 114 | |
| 115 | if (!styleExists) { |
| 116 | applyStyles() // 如果样式不存在,则重新应用 |
| 117 | } |
| 118 | }, 300) |
| 119 | } |
| 120 | |
| 121 | // 调用函数以添加自定义CSS |
| 122 | addCustomCSS() |
no test coverage detected