Dark/Light Mode Toggle

Toggle between dark and light mode on any website with a button on the center right of the screen that auto hides.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Dark/Light Mode Toggle
// @namespace    https://azastudio.net
// @version      1.2
// @description  Toggle between dark and light mode on any website with a button on the center right of the screen that auto hides.
// @author       Nate Thompson
// @license      MIT
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('DOMContentLoaded', function() {
        const toggleButton = document.createElement('button');
        toggleButton.innerHTML = '☼'; // Start with an arrow
        toggleButton.style.position = 'fixed';
        toggleButton.style.top = '50%'; // Vertically center the button
        toggleButton.style.transform = 'translateY(-50%)'; // Adjust for perfect centering
        toggleButton.style.right = '-12px'; // Initially hidden to the right
        toggleButton.style.width = '50px'; // Small width to show just the arrow
        toggleButton.style.height = '50px';
        toggleButton.style.zIndex = '1000';
        toggleButton.style.backgroundColor = 'rgba(50, 50, 50, 0.8)';
        toggleButton.style.color = '#ffffff';
        toggleButton.style.border = 'none';
        toggleButton.style.borderRadius = '5px 0 0 5px'; // Rounded edge on the left side
        toggleButton.style.transition = 'right 0.3s ease, width 0.3s ease'; // Smooth transitions for both right and width
        toggleButton.style.overflow = 'hidden'; // Hide text overflow
        toggleButton.style.whiteSpace = 'nowrap'; // Prevent text wrapping
        toggleButton.style.textAlign = 'center';

        document.body.appendChild(toggleButton);

        let inverted = localStorage.getItem('invertedColors') === 'true';
        setInvertedMode(inverted);

        // Hover effect to slide out the button and reveal text
        toggleButton.addEventListener('mouseenter', () => {
            toggleButton.style.right = '0'; // Slide out
            toggleButton.style.width = '150px'; // Expand to show text
            toggleButton.innerHTML = '☼ Invert Colors'; // Add text next to the arrow
        });

        toggleButton.addEventListener('mouseleave', () => {
            toggleButton.style.right = '-12px'; // Slide back in
            toggleButton.style.width = '50px'; // Shrink back to arrow only
            toggleButton.innerHTML = '☼'; // Show only the arrow
        });

        toggleButton.addEventListener('click', () => {
            inverted = !inverted;
            setInvertedMode(inverted);
            localStorage.setItem('invertedColors', inverted);
        });

        function setInvertedMode(isInverted) {
            if (isInverted) {
                document.documentElement.style.filter = 'invert(1)';
                toggleButton.style.backgroundColor = 'rgba(200, 200, 200, 0.8)'; // Muted light color
                toggleButton.style.color = '#000000'; // Dark text
            } else {
                document.documentElement.style.filter = 'invert(0)';
                toggleButton.style.backgroundColor = 'rgba(50, 50, 50, 0.8)'; // Muted dark color
                toggleButton.style.color = '#ffffff'; // Light text
            }
        }
    });
})();