Skip to content

Commit b98c50f

Browse files
committed
Add toggleable light/dark print theme
Introduce a toggleable light/dark print theme for the Steam Guide Print userscript. Adds GM_getValue/GM_setValue/GM_registerMenuCommand/GM_unregisterMenuCommand grants, stores preference, and exposes a Tampermonkey menu item to switch themes. Refactors CSS by extracting shared hide rules and moving color-specific rules into separate light/dark style blocks, and bumps script version to 1.1.0. README updated to mention the new toggleable theme.
1 parent cd31024 commit b98c50f

2 files changed

Lines changed: 148 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ Highlight mods that have been updated since your last download
188188
Improves the print layout of Steam Community guides:
189189

190190
- Hides navigation bar, sidebar, breadcrumbs, comments and footer
191-
- Makes guide content full-width on white background
191+
- Makes guide content full-width
192192
- Readable typography with proper page breaks
193193
- Shows link URLs in print
194+
- Toggleable light/dark print theme via Tampermonkey menu (preference saved)
194195

195196
### Steam - Steam Search
196197

user.js/[Steam] Guide Print.user.js

Lines changed: 146 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// @name [Steam] Guide Print
33
// @namespace https://github.com/kevingrillet
44
// @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
66
// @copyright https://github.com/kevingrillet
77
// @license GPL-3.0 License
88
// @tag kevingrillet
99
// @tag steamcommunity.com
10-
// @version 1.0.0
10+
// @version 1.1.0
1111

1212
// @homepageURL https://github.com/kevingrillet/Userscripts/
1313
// @supportURL https://github.com/kevingrillet/Userscripts/issues
@@ -18,6 +18,10 @@
1818
// @match https://steamcommunity.com/sharedfiles/filedetails/*
1919
// @icon https://www.google.com/s2/favicons?sz=64&domain=steamcommunity.com
2020
// @grant GM_addStyle
21+
// @grant GM_getValue
22+
// @grant GM_setValue
23+
// @grant GM_registerMenuCommand
24+
// @grant GM_unregisterMenuCommand
2125
// @run-at document-end
2226
// ==/UserScript==
2327

@@ -27,7 +31,40 @@
2731
// Only apply on guide pages (check for guide-specific elements)
2832
if (!document.querySelector('.guide.subSections, .guideTop')) return;
2933

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 = `
3168
@media print {
3269
/* ===== HIDE UNNECESSARY ELEMENTS ===== */
3370
@@ -96,8 +133,6 @@
96133
.responsive_page_frame,
97134
.responsive_page_content,
98135
.responsive_page_template_content {
99-
background: white !important;
100-
color: black !important;
101136
width: 100% !important;
102137
max-width: 100% !important;
103138
margin: 0 !important;
@@ -132,20 +167,17 @@
132167
133168
.workshopItemTitle {
134169
font-size: 24pt !important;
135-
color: black !important;
136170
margin-bottom: 10px !important;
137171
}
138172
139173
.guideTopDescription {
140-
color: #333 !important;
141174
font-size: 11pt !important;
142175
}
143176
144177
/* Guide sub-sections */
145178
.subSection.detailBox {
146179
background: none !important;
147180
border: none !important;
148-
border-bottom: 1px solid #ccc !important;
149181
padding: 10px 0 !important;
150182
margin: 0 !important;
151183
page-break-inside: avoid;
@@ -154,13 +186,11 @@
154186
.subSectionTitle {
155187
font-size: 16pt !important;
156188
font-weight: bold !important;
157-
color: black !important;
158189
margin-bottom: 8px !important;
159190
}
160191
161192
.subSectionDesc {
162193
font-size: 11pt !important;
163-
color: #222 !important;
164194
line-height: 1.5 !important;
165195
}
166196
@@ -175,7 +205,6 @@
175205
.subSectionDesc a::after {
176206
content: " (" attr(href) ")";
177207
font-size: 9pt;
178-
color: #666;
179208
}
180209
181210
/* Don't show URL for internal Steam links and image links */
@@ -198,7 +227,6 @@
198227
}
199228
200229
.apphub_AppName {
201-
color: black !important;
202230
font-size: 14pt !important;
203231
}
204232
@@ -211,12 +239,117 @@
211239
/* BB code spoiler blocks */
212240
.bb_spoiler {
213241
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 {
214288
border: 1px solid #ccc !important;
215289
}
216290
217291
.bb_spoiler > span {
218292
color: black !important;
219293
}
220294
}
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();
222355
})();

0 commit comments

Comments
 (0)