Google Sheets Dark Mode

12/7/2023, 10:09:32 AM

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Google Sheets Dark Mode
// @namespace   Violentmonkey Scripts
// @match       https://docs.google.com/spreadsheets/*
// @grant       none
// @version     1.1
// @author      Lunula
// @description 12/7/2023, 10:09:32 AM
// @license      GPL-3.0 License

// ==/UserScript==

(function() {
    'use strict';

    // Create a <style> element
    const style = document.createElement('style');
    style.type = 'text/css';

    // CSS styles to change background color of various Google Sheets elements
    const css = `
        /* invert the table, formula bar, cell editor, and navbar and dim transparency to soften */
        #waffle-grid-container,
        #formula-bar-name-box-wrapper,
        #docs-chrome,
        #docs-additional-bars,
        div[role="navigation"],
        .cell-input.editable {
            filter: invert();
            opacity: 0.9;
        }

        /* re-invert colors inside inverted parents to restore them */
        .overlay-container-ltr,
        .formula-content > span:not(.default-formula-text-color),
        .docs-gm .docs-sheet-active-tab .docs-sheet-tab-name,
        .docs-gm .docs-sheet-active-tab .docs-icon {
            filter: invert();
        }

        /* invert selection color manually */
        ::selection {
            background-color: #e58c17 !important;
        }

        /* Misc artifacts */
        .autofill-handle {
            border-color: #333;
        }
        .input-box {
            background: #000 !important;
        }
        .cell-input {
            background: #DDD !important;
        }
        .docs-gm .docs-menubar .goog-control-disabled {
            background-color: transparent !important;
            opacity: 0.5;
        }
    `;

    // Append the CSS styles to the <style> element
    if (style.styleSheet) {
        style.styleSheet.cssText = css;
    } else {
        style.appendChild(document.createTextNode(css));
    }

    // Append the <style> element to the <head> of the document
    document.head.appendChild(style);
})();