Auto Dark Mode for Shlink Web Client

Automatically switch the theme between light and dark, based on the browser’s color scheme preference.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name               Auto Dark Mode for Shlink Web Client
// @name:zh-TW         Shlink 網頁客戶端自動黑暗模式
// @description        Automatically switch the theme between light and dark, based on the browser’s color scheme preference.
// @description:zh-TW  根據瀏覽器的佈景主題設定,自動從明亮和黑暗模式間切換。
// @icon               https://icons.duckduckgo.com/ip3/app.shlink.io.ico
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            1.0.0
// @license            MIT
// @match              https://app.shlink.io/*
// @run-at             document-end
// @grant              none
// @supportURL         https://greasyfork.org/scripts/491886/feedback
// ==/UserScript==

const settings = JSON.parse(localStorage.getItem("shlink.settings") ?? "null");
if (settings)
{
    delete settings.ui.theme;
    localStorage.setItem("shlink.settings", JSON.stringify(settings));
}

const query = matchMedia("(prefers-color-scheme: dark)");
query.addEventListener("change", updateTheme);

function isDarkTheme()
{
    return (document.documentElement.dataset.theme === "dark");
}

function updateTheme({ matches: isDarkMode })
{
    if (isDarkTheme() !== isDarkMode)
    {
        document.documentElement.dataset.theme = isDarkMode ? "dark" : "light";
    }
}