一些网站的配色方案非常不适合阅读,比如知乎专栏白色背景黑色字体,看一会就非常刺眼,故此写个脚本,方便以后遇到这种网站直接自动修改样式。
目前為
// ==UserScript==
// @name change_style
// @namespace https://netoday.cn
// @version 0.1
// @description 一些网站的配色方案非常不适合阅读,比如知乎专栏白色背景黑色字体,看一会就非常刺眼,故此写个脚本,方便以后遇到这种网站直接自动修改样式。
// @author crazy_pig
// @match https://*/*
// @match http://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
var URL_INDEX = 0;
var BGCOLOR_INDEX = 1;
var FNTCOLOR_INDEX = 2;
// default urls and style to use this script: 0=url,1=bgcolor,2=font color
var _url_array = [
["zhuanlan.zhihu.com", "#000000", "#10ff00"]
];
// 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]);
}
})();
function recursion(parent, _bg_color, _fnt_color){
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);
}
}
parent.style.backgroundColor = _bg_color;
parent.style.color = _fnt_color;
}
}