change_style

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

Versione datata 19/09/2022. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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;
    }
}