PageSourceSearch

https://realservicesolutions.com/script/js/site-theme.js?v=20260907

js realservicesolutions.com collected 2026-09-24 14:51:42 UTC 2,138 bytes, 51 lines download raw bytes

1/* Shared appearance preference. Load in the head before page styles. */
2(() => {
3    'use strict';
4    const root = document.documentElement;
5    const key = 'rss-theme';
6    const legacyKey = 'templateCustomizer-RealService--Style';
7    const valid = value => ['light', 'dark', 'system'].includes(value);
8    const device = window.matchMedia('(prefers-color-scheme: dark)');
9    let preference = 'system';
10
11    function readPreference() {
12        try {
13            const saved = localStorage.getItem(key);
14            if (valid(saved)) return saved;
15            const legacy = localStorage.getItem(legacyKey);
16            if (valid(legacy)) return legacy;
17        } catch (_) { /* Appearance still works if browser storage is unavailable. */ }
18        return 'system';
19    }
20
21    function apply() {
22        const theme = preference === 'system' ? (device.matches ? 'dark' : 'light') : preference;
23        root.dataset.rssTheme = theme;
24        root.dataset.rssThemePreference = preference;
25        root.style.colorScheme = theme;
26        document.querySelectorAll('[data-rss-theme-choice]').forEach(button => {
27            button.setAttribute('aria-pressed', String(button.dataset.rssThemeChoice === preference));
28        });
29    }
30
31    preference = readPreference();
32    apply();
33    document.addEventListener('DOMContentLoaded', apply, { once: true });
34    document.addEventListener('click', event => {
35        const button = event.target.closest('[data-rss-theme-choice]');
36        if (!button || !valid(button.dataset.rssThemeChoice)) return;
37        preference = button.dataset.rssThemeChoice;
38        try {
39            localStorage.setItem(key, preference);
40            localStorage.setItem(legacyKey, preference);
41        } catch (_) { /* Keep the selected appearance for this page session. */ }
42        apply();
43    });
44    device.addEventListener('change', () => { if (preference === 'system') apply(); });
45    window.addEventListener('storage', event => {
46        if (event.key === key || event.key === legacyKey || event.key === null) {
47            preference = readPreference();
48            apply();
49        }
50    });
51})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.