change_style

一些网站的配色方案非常不适合阅读,比如知乎专栏白色背景黑色字体,看一会就非常刺眼,故此写个脚本,方便以后遇到这种网站直接自动修改样式。

目前為 2022-09-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name         change_style
// @namespace    https://netoday.cn
// @version      0.1.1
// @description  一些网站的配色方案非常不适合阅读,比如知乎专栏白色背景黑色字体,看一会就非常刺眼,故此写个脚本,方便以后遇到这种网站直接自动修改样式。
// @author       crazy_pig
// @match        https://*/*
// @match        http://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license MIT
// ==/UserScript==

// default urls and style to use this script: 0=url,1=bgcolor,2=font color,3=font family, 4=mask btn class
var _url_array = [
    ["zhuanlan.zhihu.com", "#181C1F", "#EAF2F7", "gitbook-content-font,-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif, 微软雅黑", "Modal-closeButton"]
];

(function() {
    'use strict';

    var URL_INDEX = 0;
    var BGCOLOR_INDEX = 1;
    var FNTCOLOR_INDEX = 2;
    var FNTFML_INDEX = 3;
    var MASK_INDEX = 4;

    // get url user visited
    var _url = (window.location + "").toLowerCase();

    // if need active script
    var _active_index = -1;
    var i;
    for (i = 0; i < _url_array.length; i++){
        if (_url.indexOf(_url_array[i][URL_INDEX]) > 0){
            _active_index = i;
            break;
        }
    }

    if (_active_index >= 0){
        recursion(document.body,
                  _url_array[_active_index][BGCOLOR_INDEX],
                  _url_array[_active_index][FNTCOLOR_INDEX],
                  _url_array[_active_index][FNTFML_INDEX]);

        // remove mask div
        setTimeout(function (){
            var _mask_btns = document.getElementsByClassName(_url_array[_active_index][MASK_INDEX]);
            if(typeof(_mask_btns) !== 'undefined'){
                var i;
                for(i=0;i<_mask_btns.length;i++){
                    // click the `close` button to close the mask div
                    _mask_btns[i].click();
                }
            }
        },1000);
    }

})();

function remove_mask(){

}

function recursion(parent, _bg_color, _fnt_color, _fnt_family){
    if (typeof(parent.children) !== 'undefined'){
        if (parent.children.length > 0){
            var i;
            for(i=0;i<parent.children.length;i++){
                recursion(parent.children[i], _bg_color, _fnt_color, _fnt_family);
            }
        }
        parent.style.backgroundColor = _bg_color;
        parent.style.color = _fnt_color;
        parent.style.fontFamily = _fnt_family;
    }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址