File: theme-setter.js

package info (click to toggle)
nvidia-cuda-toolkit 12.4.1-2
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, trixie
  • size: 18,505,836 kB
  • sloc: ansic: 203,477; cpp: 64,769; python: 34,699; javascript: 22,006; xml: 13,410; makefile: 3,085; sh: 2,343; perl: 352
file content (50 lines) | stat: -rw-r--r-- 1,713 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
 *
 * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
 * property and proprietary rights in and to this material, related
 * documentation and any modifications thereto. Any use, reproduction,
 * disclosure or distribution of this material and related documentation
 * without an express license agreement from NVIDIA CORPORATION or
 * its affiliates is strictly prohibited.
 */

const isThemeDark = () => {
    var isDark = false;
    if (sessionStorage.getItem('repo-docs-theme')) {
        isDark = sessionStorage.getItem('repo-docs-theme') === 'dark';
    }
    else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
        isDark = true;
    }
    return isDark;
};

const createThemeSwitcher = () => {
    let btn = document.createElement('BUTTON');
    btn.className = 'theme-switcher';
    btn.id = 'theme-switcher';
    btn.onclick = function () {
        const newTheme = isThemeDark() ? 'light' : 'dark';

        sessionStorage.setItem('repo-docs-theme', newTheme);
        document.documentElement.setAttribute('data-theme', newTheme);

        setThemeIcon(this);
        initMermaid(isThemeDark());
    };
    document.body.appendChild(btn);
    setThemeIcon(btn);
};

const setThemeIcon = (element) => {
    const icon = isThemeDark() ? 'sun' : 'moon';
    element.innerHTML = `<i class='fa fa-${icon}-o'></i>`;
};

document.addEventListener('DOMContentLoaded', () => {
    createThemeSwitcher();
}, false);

document.documentElement.setAttribute('data-theme', isThemeDark() ? 'dark' : 'light');