MCPcopy Create free account
hub / github.com/ChinaGodMan/UserScripts / addCustomCSS

Function addCustomCSS

chatgpt-code-styling/chatgpt-code-styling.user.js:89–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87// ==/UserScript==
88
89function 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
122addCustomCSS()

Callers 1

Calls 1

applyStylesFunction · 0.70

Tested by

no test coverage detected