如何将全标签颜色添加到Google表格中?

时间:2019-06-19 08:21:50

标签: css google-sheets userscripts

我刚刚开始了解Google Apps脚本,发现一个脚本为整个选项卡着色,而不是下面的细线。我将代码复制/粘贴到新的脚本文件中,单击“保存”,并刷新了工作表,但它没有更改选项卡的外观。如何将该脚本添加到现有工作表并将其应用于所有选项卡?

https://userstyles.org/styles/110436上,代码既可以作为用户脚本又可以作为CSS来使用

谢谢!

// ==UserScript==
// @name          Full-Color Tabs for Google Sheets/Spreadsheets
// @namespace     http://userstyles.org
// @description   Google's new Sheets allows you to change the tab colors, but the color is just a narrow stripe—not enough of a visual cue to immediately identify tabs by their color. This stylesheet causes your selected colors to fill the whole tab, similar to the way Excel does it. It also includes optional increased rounding of the bottom corners of each tab to further help distinguish one tab from the next. The rounding styles can be deleted. 3/23/15 update makes the active tab title bold, making it easier to confirm which tab is active. These styles can be deleted.
// @author        Bunnyslippers
// @homepage      https://userstyles.org/styles/110436
// @include       http://docs.google.com/spreadsheets*
// @include       https://docs.google.com/spreadsheets*
// @run-at        document-start
// @version       0.20150323072833
// ==/UserScript==

(function() {var css = [
    ".docs-sheet-tab-color {",
    "  height: 31px;",
    "  margin: -23px -20px 0 -5px;",
    "  position: relative;",
    "  z-index: -1;",
    "}",
    "",
    "/* Optional rounded bottom tab corners. Corners can be made more or less round by increasing or decreasing the last two values (10px). Delete the rule entirely to use Google\'s default 2px radius */",
    "",
    ".docs-sheet-tab, .docs-sheet-tab-color {",
    "  border-radius: 0 0 10px 10px",
    "}",
    "",
    "/* Optional: Darken tab borders. This style can be deleted. */",
    ".docs-sheet-tab {",
    "  border-color: rgb(164, 164, 164);",
    "  border-top-color: rgb(170, 170, 170);",
    "  }",
    "",
    "",
    "/* Optional: Make active tab title bold for easy identification. This style can be deleted. */",
    ".docs-sheet-active-tab {",
    "    font-weight: 700 !important;",
    "  }"
].join("\n");
if (typeof GM_addStyle != "undefined") {
    GM_addStyle(css);
} else if (typeof PRO_addStyle != "undefined") {
    PRO_addStyle(css);
} else if (typeof addStyle != "undefined") {
    addStyle(css);
} else {
    var node = document.createElement("style");
    node.type = "text/css";
    node.appendChild(document.createTextNode(css));
    var heads = document.getElementsByTagName("head");
    if (heads.length > 0) {
        heads[0].appendChild(node);
    } else {
        // no head yet, stick it whereever
        document.documentElement.appendChild(node);
    }
}
})();

1 个答案:

答案 0 :(得分:0)

您忘记在标题中添加@grant GM_addStyle

// ==UserScript==
// @name         Google Shets
// @include      https://*docs.google.*/spreadsheets/*
// for change CSS
// @grant    GM_addStyle       
// ==/UserScript==


GM_addStyle(`


    .docs-sheet-tab-color {
          height: 31px  !important;
          margin: -23px -20px 0 -5px  !important;
          position: relative  !important;
          z-index: -1  !important;
        }

    /* Optional rounded bottom tab corners. Corners can be made more or less round by increasing or decreasing the last two values (10px). Delete the rule entirely to use Google\'s default 2px radius */

    .docs-sheet-tab .docs-sheet-tab-color {
          border-radius: 0 0 10px 10px  !important;
        }

    /* Optional: Darken tab borders. This style can be deleted. */
    .docs-sheet-tab {
          border-color: rgb(164 164 164)  !important;
          border-top-color: rgb(170 170 170)  !important;
          }


    /* Optional: Make active tab title bold for easy identification. This style can be deleted. */
    .docs-sheet-active-tab {
            font-weight: 700 !important;

          }



    `);