Google Docs blend webapp window decoration/theme color with header

Set theme color based on Google Docs header's background color

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Google Docs blend webapp window decoration/theme color with header
// @namespace    https://greasyfork.org/users/1257389
// @version      1.0.00
// @description  Set theme color based on Google Docs header's background color
// @author       dvirzxc
// @match        https://docs.google.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function getBackgroundColor() {
        const selector = '[class*=docs-grille-]';
        const elementClass = document.querySelector(selector);
        if (elementClass) {
            const element = elementClass.querySelector('#docs-chrome:not(.docs-hub-chrome)');
            if (element) {
                const style = window.getComputedStyle(element);
                return style.backgroundColor;
            }
        }
        return '#ffffff'; // Return white when there's no selector to be found
    }

    // Function to set the meta tag
    function setChromeThemeColor(color) {
        const metaThemeColor = document.createElement('meta');
        metaThemeColor.setAttribute('name', 'theme-color');
        metaThemeColor.setAttribute('content', color);
        document.head.appendChild(metaThemeColor);
    }

    // Run
    const backgroundColor = getBackgroundColor();
    setChromeThemeColor(backgroundColor);
})();