Floatplane System Theme Sync

Sync Floatplane theme with system theme based on system changes and page load

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Floatplane System Theme Sync
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Sync Floatplane theme with system theme based on system changes and page load
// @author       EthanBezz
// @match        https://*.floatplane.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(() => {
    'use strict';

    const systemThemeQuery = window.matchMedia('(prefers-color-scheme: dark');
    const isSystemDark = () => systemThemeQuery.matches;
    const getFloatplaneTheme = () => JSON.parse(localStorage.getItem('fp:theme-preferred'));
    const isThemeMismatched = () => isSystemDark() !== (getFloatplaneTheme() === 'dark');
    const getThemeToggle = () =>
        [...document.querySelectorAll('a._dropdownItem_ouby8_1')]
            .find(menuItem => menuItem.textContent.includes('Mode'));

    new MutationObserver((_, observer) => {
        const themeToggle = getThemeToggle();
        if (themeToggle) {
            isThemeMismatched() && themeToggle.click();
            systemThemeQuery.addEventListener('change', () => isThemeMismatched() && getThemeToggle()?.click());
            observer.disconnect();
        }
    }).observe(document, { subtree: true, childList: true });
})();