|
2 | 2 | // @name [Steam] Guide Print |
3 | 3 | // @namespace https://github.com/kevingrillet |
4 | 4 | // @author Kevin GRILLET |
5 | | -// @description Improves the print layout of Steam Community guides by hiding unnecessary elements and making the guide content full-width |
| 5 | +// @description Improves the print layout of Steam Community guides with a toggleable light/dark theme, hiding unnecessary elements and making the guide content full-width |
6 | 6 | // @copyright https://github.com/kevingrillet |
7 | 7 | // @license GPL-3.0 License |
8 | 8 | // @tag kevingrillet |
9 | 9 | // @tag steamcommunity.com |
10 | | -// @version 1.0.0 |
| 10 | +// @version 1.1.0 |
11 | 11 |
|
12 | 12 | // @homepageURL https://github.com/kevingrillet/Userscripts/ |
13 | 13 | // @supportURL https://github.com/kevingrillet/Userscripts/issues |
|
18 | 18 | // @match https://steamcommunity.com/sharedfiles/filedetails/* |
19 | 19 | // @icon https://www.google.com/s2/favicons?sz=64&domain=steamcommunity.com |
20 | 20 | // @grant GM_addStyle |
| 21 | +// @grant GM_getValue |
| 22 | +// @grant GM_setValue |
| 23 | +// @grant GM_registerMenuCommand |
| 24 | +// @grant GM_unregisterMenuCommand |
21 | 25 | // @run-at document-end |
22 | 26 | // ==/UserScript== |
23 | 27 |
|
|
27 | 31 | // Only apply on guide pages (check for guide-specific elements) |
28 | 32 | if (!document.querySelector('.guide.subSections, .guideTop')) return; |
29 | 33 |
|
30 | | - GM_addStyle(` |
| 34 | + // ===== THEME TOGGLE ===== |
| 35 | + const STORAGE_KEY = 'printTheme'; |
| 36 | + let isDark = GM_getValue(STORAGE_KEY, false); |
| 37 | + let styleElement = null; |
| 38 | + let menuCommandId = null; |
| 39 | + |
| 40 | + function getMenuLabel() { |
| 41 | + return isDark ? '🌙 Print: Dark theme (click for Light)' : '☀️ Print: Light theme (click for Dark)'; |
| 42 | + } |
| 43 | + |
| 44 | + function registerMenu() { |
| 45 | + if (menuCommandId !== null) { |
| 46 | + GM_unregisterMenuCommand(menuCommandId); |
| 47 | + } |
| 48 | + menuCommandId = GM_registerMenuCommand(getMenuLabel(), toggleTheme); |
| 49 | + } |
| 50 | + |
| 51 | + function toggleTheme() { |
| 52 | + isDark = !isDark; |
| 53 | + GM_setValue(STORAGE_KEY, isDark); |
| 54 | + applyStyle(); |
| 55 | + registerMenu(); |
| 56 | + } |
| 57 | + |
| 58 | + function applyStyle() { |
| 59 | + if (styleElement) { |
| 60 | + styleElement.remove(); |
| 61 | + styleElement = null; |
| 62 | + } |
| 63 | + styleElement = GM_addStyle(isDark ? darkStyle : lightStyle); |
| 64 | + } |
| 65 | + |
| 66 | + // ===== SHARED HIDE RULES ===== |
| 67 | + const hideRules = ` |
31 | 68 | @media print { |
32 | 69 | /* ===== HIDE UNNECESSARY ELEMENTS ===== */ |
33 | 70 |
|
|
96 | 133 | .responsive_page_frame, |
97 | 134 | .responsive_page_content, |
98 | 135 | .responsive_page_template_content { |
99 | | - background: white !important; |
100 | | - color: black !important; |
101 | 136 | width: 100% !important; |
102 | 137 | max-width: 100% !important; |
103 | 138 | margin: 0 !important; |
|
132 | 167 |
|
133 | 168 | .workshopItemTitle { |
134 | 169 | font-size: 24pt !important; |
135 | | - color: black !important; |
136 | 170 | margin-bottom: 10px !important; |
137 | 171 | } |
138 | 172 |
|
139 | 173 | .guideTopDescription { |
140 | | - color: #333 !important; |
141 | 174 | font-size: 11pt !important; |
142 | 175 | } |
143 | 176 |
|
144 | 177 | /* Guide sub-sections */ |
145 | 178 | .subSection.detailBox { |
146 | 179 | background: none !important; |
147 | 180 | border: none !important; |
148 | | - border-bottom: 1px solid #ccc !important; |
149 | 181 | padding: 10px 0 !important; |
150 | 182 | margin: 0 !important; |
151 | 183 | page-break-inside: avoid; |
|
154 | 186 | .subSectionTitle { |
155 | 187 | font-size: 16pt !important; |
156 | 188 | font-weight: bold !important; |
157 | | - color: black !important; |
158 | 189 | margin-bottom: 8px !important; |
159 | 190 | } |
160 | 191 |
|
161 | 192 | .subSectionDesc { |
162 | 193 | font-size: 11pt !important; |
163 | | - color: #222 !important; |
164 | 194 | line-height: 1.5 !important; |
165 | 195 | } |
166 | 196 |
|
|
175 | 205 | .subSectionDesc a::after { |
176 | 206 | content: " (" attr(href) ")"; |
177 | 207 | font-size: 9pt; |
178 | | - color: #666; |
179 | 208 | } |
180 | 209 |
|
181 | 210 | /* Don't show URL for internal Steam links and image links */ |
|
198 | 227 | } |
199 | 228 |
|
200 | 229 | .apphub_AppName { |
201 | | - color: black !important; |
202 | 230 | font-size: 14pt !important; |
203 | 231 | } |
204 | 232 |
|
|
211 | 239 | /* BB code spoiler blocks */ |
212 | 240 | .bb_spoiler { |
213 | 241 | background: none !important; |
| 242 | + } |
| 243 | + } |
| 244 | + `; |
| 245 | + |
| 246 | + // ===== LIGHT THEME ===== |
| 247 | + const lightStyle = |
| 248 | + hideRules + |
| 249 | + ` |
| 250 | + @media print { |
| 251 | + body, |
| 252 | + .responsive_page_frame, |
| 253 | + .responsive_page_content, |
| 254 | + .responsive_page_template_content { |
| 255 | + background: white !important; |
| 256 | + color: black !important; |
| 257 | + } |
| 258 | +
|
| 259 | + .workshopItemTitle { |
| 260 | + color: black !important; |
| 261 | + } |
| 262 | +
|
| 263 | + .guideTopDescription { |
| 264 | + color: #333 !important; |
| 265 | + } |
| 266 | +
|
| 267 | + .subSection.detailBox { |
| 268 | + border-bottom: 1px solid #ccc !important; |
| 269 | + } |
| 270 | +
|
| 271 | + .subSectionTitle { |
| 272 | + color: black !important; |
| 273 | + } |
| 274 | +
|
| 275 | + .subSectionDesc { |
| 276 | + color: #222 !important; |
| 277 | + } |
| 278 | +
|
| 279 | + .subSectionDesc a::after { |
| 280 | + color: #666; |
| 281 | + } |
| 282 | +
|
| 283 | + .apphub_AppName { |
| 284 | + color: black !important; |
| 285 | + } |
| 286 | +
|
| 287 | + .bb_spoiler { |
214 | 288 | border: 1px solid #ccc !important; |
215 | 289 | } |
216 | 290 |
|
217 | 291 | .bb_spoiler > span { |
218 | 292 | color: black !important; |
219 | 293 | } |
220 | 294 | } |
221 | | - `); |
| 295 | + `; |
| 296 | + |
| 297 | + // ===== DARK THEME ===== |
| 298 | + const darkStyle = |
| 299 | + hideRules + |
| 300 | + ` |
| 301 | + @media print { |
| 302 | + body, |
| 303 | + .responsive_page_frame, |
| 304 | + .responsive_page_content, |
| 305 | + .responsive_page_template_content { |
| 306 | + background: #1e1e1e !important; |
| 307 | + color: #d4d4d4 !important; |
| 308 | + } |
| 309 | +
|
| 310 | + .workshopItemTitle { |
| 311 | + color: #e0e0e0 !important; |
| 312 | + } |
| 313 | +
|
| 314 | + .guideTopDescription { |
| 315 | + color: #b0b0b0 !important; |
| 316 | + } |
| 317 | +
|
| 318 | + .subSection.detailBox { |
| 319 | + border-bottom: 1px solid #444 !important; |
| 320 | + } |
| 321 | +
|
| 322 | + .subSectionTitle { |
| 323 | + color: #e0e0e0 !important; |
| 324 | + } |
| 325 | +
|
| 326 | + .subSectionDesc { |
| 327 | + color: #cccccc !important; |
| 328 | + } |
| 329 | +
|
| 330 | + .subSectionDesc a { |
| 331 | + color: #6db3f2 !important; |
| 332 | + } |
| 333 | +
|
| 334 | + .subSectionDesc a::after { |
| 335 | + color: #888; |
| 336 | + } |
| 337 | +
|
| 338 | + .apphub_AppName { |
| 339 | + color: #e0e0e0 !important; |
| 340 | + } |
| 341 | +
|
| 342 | + .bb_spoiler { |
| 343 | + border: 1px solid #555 !important; |
| 344 | + } |
| 345 | +
|
| 346 | + .bb_spoiler > span { |
| 347 | + color: #d4d4d4 !important; |
| 348 | + } |
| 349 | + } |
| 350 | + `; |
| 351 | + |
| 352 | + // ===== INIT ===== |
| 353 | + applyStyle(); |
| 354 | + registerMenu(); |
222 | 355 | })(); |
0 commit comments