T3Chat Auto Boring Theme

Automatically sets light mode to boring theme and disables boring theme for dark mode

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

Advertisement:

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

Advertisement:

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         T3Chat Auto Boring Theme
// @namespace    https://wearifulpoet.com
// @version      0.1.0
// @description  Automatically sets light mode to boring theme and disables boring theme for dark mode
// @match        https://t3.chat/*
// @run-at       document-idle
// @grant        none
// @license      MIT
// ==/UserScript==

(() => {
  'use strict';

  const THEME_KEY = 'theme';
  const THEME = {
    LIGHT: 'light',
    DARK: 'dark',
    BORING_LIGHT: 'boring-light',
    BORING_DARK: 'boring-dark',
    BORING_SYSTEM: 'boring-system'
  };

  const getCurrentTheme = () => {
    try {
      return localStorage.getItem(THEME_KEY) || 'system';
    } catch {
      return null;
    }
  };

  const setTheme = (theme) => {
    try {
      localStorage.setItem(THEME_KEY, theme);
      window.dispatchEvent(
        new StorageEvent('storage', {
          key: THEME_KEY,
          newValue: theme,
          storageArea: localStorage
        })
      );
      return true;
    } catch {
      return false;
    }
  };

  const applyBoringLogic = () => {
    const current = getCurrentTheme();
    if (!current) return;

    let next = null;

    if (current === THEME.LIGHT) {
      next = THEME.BORING_LIGHT;
    } else if (current === THEME.BORING_DARK || current === THEME.BORING_SYSTEM) {
      next = THEME.DARK;
    }

    if (next && next !== current && setTheme(next)) {
      setTimeout(() => window.location.reload(), 100);
    }
  };

  const observeThemeChanges = () => {
    window.addEventListener('storage', (e) => {
      if (e.key === THEME_KEY && e.newValue) {
        setTimeout(applyBoringLogic, 50);
      }
    });

    const observer = new MutationObserver(() => {
      setTimeout(applyBoringLogic, 50);
    });

    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ['class']
    });

    return observer;
  };

  const init = () => {
    applyBoringLogic();
    observeThemeChanges();
  };

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  } else {
    init();
  }
})();