语雀夜间模式

让语雀的编辑状态显示成夜间模式的配色,保护眼睛。非编辑模式因为是编译式的样式,脚本可能会失效,所以只支持了正文部分的夜间模式,没有支持顶栏和侧边栏。

当前为 2022-02-16 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         语雀夜间模式
// @namespace    https://greasyfork.org/users/670174
// @version      0.1.2
// @description  让语雀的编辑状态显示成夜间模式的配色,保护眼睛。非编辑模式因为是编译式的样式,脚本可能会失效,所以只支持了正文部分的夜间模式,没有支持顶栏和侧边栏。
// @author       CWBeta
// @icon         https://www.google.com/s2/favicons?domain=yuque.com
// @include      *yuque.com*
// @grant        none
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';

    console.log("【语雀夜间模式】运行中!")

    // 可以用户自定义的颜色
    var MAIN_BG_COLOR = "#333333"; //背景色
    var TOOLBAR_BG_COLOR = "#242424"; //顶部工具栏背景色
    var TOOLBAR_BORDER_COLOR = "#000000"; //顶部工具栏描边色
    var FONT_DEFAULT_COLOR = "#ffffff"; //默认正文颜色
    var LINK_COLOR = "#39C5BB"; // 正文链接颜色
    var LIST_COLOR = "#66CCFF"; // 列表记号颜色
    var FONT_SIDEBAR_COLOR = "#727272"; //侧面大纲正文颜色
    var FONT_SIDEBAR_HOVER_COLOR = "#999999"; //侧面大纲鼠标悬停颜色
    var SCROLLBAR_BG_COLOR = "#262626"; //大纲滚动条背景色

 /**
 * 16进制色值获取反色设置方法
 * @param  {String} oldColor 为16进制色值的字符串(例:'#000000')
 * @return {String} 返回反色的色值(例:'#ffffff')
 */
    function ReverseColor(oldColor)
    {
        oldColor = '0x' + oldColor.replace(/#/g, '');
        let str = '000000' + (0xFFFFFF - oldColor).toString(16);
        return '#'+ str.substring(str.length - 6, str.length);
    }
    function Awake()
    {
        var style = document.createElement("style");
        style.type = "text/css";
        var cssString = ".main-wrapper #main, .ne-editor-body,.ne-editor-extra-box,.ne-editor-wrap-box,.ant-input {background-color: "+MAIN_BG_COLOR+" !important;}"+
            ".main-wrapper #article-title, ne-text{color:"+FONT_DEFAULT_COLOR+";}"+
            ".ant-input{color:"+FONT_DEFAULT_COLOR+";}"+
            ".ne-ui{filter: invert(100%); background-color: "+ReverseColor(TOOLBAR_BG_COLOR)+";}"+
            ".ne-ui .ne-ui-toolbar-insert-card,.ne-ui .ant-dropdown,.ne-embed-icon-t-font-color #矩形,.ne-embed-icon-t-bg-color path[fill], .lark-editor-collab-users, #lake-doc-publish-button{filter: invert(100%);}"+
            ".lark-editor-header{filter: invert(100%);background-color: "+ReverseColor(TOOLBAR_BG_COLOR)+";border-bottom: 1px solid "+ReverseColor(TOOLBAR_BORDER_COLOR)+" !important;}"+
            ".lark-editor-header .lark-editor-header-back{border-right: 1px solid "+ReverseColor(TOOLBAR_BORDER_COLOR)+" !important;}"+
            ".ne-toc-sidebar{background-color: transparent !important;}"+
            ".ne-toc-normal-view .ne-toc-content:after{background: "+SCROLLBAR_BG_COLOR+" !important;}"+
            ".ne-toc-normal-view .ne-toc-item a{color: "+FONT_SIDEBAR_COLOR+" !important;}"+
            ".ne-toc-sidebar-hover .ne-toc-view .ne-toc-item a{color: "+FONT_SIDEBAR_HOVER_COLOR+" !important;}"+
            ".ne-toc-view-inner::-webkit-scrollbar{display:none !important;}"+
            ".ne-engine{--link-color:"+LINK_COLOR+" !important;}"+
            "ne-oli-i, ne-uli-i{color:"+LIST_COLOR+" !important;}"+
            "}";
        try
        {
            style.appendChild(document.createTextNode(cssString));
        }
        catch(ex)
        {
            style.styleSheet.cssText = cssString;//针对IE
        }
        var head = document.getElementsByTagName("head")[0];
        head.appendChild(style);
    }

    Awake();
})();