change_style

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

当前为 2022-09-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name change_style
  3. // @namespace https://netoday.cn
  4. // @version 0.1.31
  5. // @description 一些网站的配色方案非常不适合阅读,比如知乎专栏白色背景黑色字体,看一会就非常刺眼,故此写个脚本,方便以后遇到这种网站直接自动修改样式。
  6. // @author crazy_pig
  7. // @match https://zhuanlan.zhihu.com/*
  8. // @match https://www.zhihu.com/*
  9. // @match https://blog.csdn.net/*
  10. // @match https://www.5axxw.com/*
  11. // @match https://www.baidu.com/*
  12. // @match https://m.baidu.com/*
  13. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  14. // @grant none
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. // default urls and style to use this script: 0=url,1=bgcolor,2=font color,3=font family, 4=btn names 2 click, 5=elements 2 remove by class, 6=div 2 maximum by classes(1) or by tag(2)
  19. const _default_font_family = "gitbook-content-font,-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif, 微软雅黑";
  20. const _url_array = [
  21. ["baidu.com", "", "",_default_font_family , "","","", ""],
  22. ["zhuanlan.zhihu.com", "#181C1F", "#EAF2F7",_default_font_family , "Modal-closeButton","css-1ynzxqw Recommendations-Main","Post-RichTextContainer Post-SideActions", "90%"],
  23. ["zhihu.com", "#181C1F", "#EAF2F7",_default_font_family , "Modal-closeButton","Question-sideColumn Question-sideColumn--sticky css-1qyytj7 css-1ynzxqw","List-item Question-mainColumn", "90%"],
  24. ["5axxw.com", "", "",_default_font_family , "","col-xl-auto ad_content_center answer-area bottom-ad","", ""],
  25. ["blog.csdn.net", "", "", "", "","blog_container_aside blog-footer-bottom more-toolbox-new recommend-box template-box recommend-right recommend-nps-box csdn-side-toolbar","main_father main container nodata", "100%"]
  26. ];
  27.  
  28. const URL_INDEX = 0;
  29. const BGCOLOR_INDEX = 1;
  30. const FNTCOLOR_INDEX = 2;
  31. const FNTFML_INDEX = 3;
  32. const BTN_INDEX = 4;
  33. const DELETE_INDEX = 5;
  34. const MAXIMUM_INDEX = 6;
  35. const RESIZE_INDEX = 7;
  36. const OP_MAXIMUM_BY_CLASSES = 1;
  37. const OP_MAXIMUM_BY_TAG = 2;
  38.  
  39. (function() {
  40. 'use strict';
  41.  
  42.  
  43. // get url user visited
  44. var _url = (window.location + "").toLowerCase();
  45.  
  46. // if need active script
  47. var _active_index = -1;
  48. var i;
  49. for (i = 0; i < _url_array.length; i++){
  50. if (_url.indexOf(_url_array[i][URL_INDEX]) > 0){
  51. _active_index = i;
  52. break;
  53. }
  54. }
  55.  
  56. if (_active_index >= 0){
  57. // set color
  58. _recursion_set_color(document.body,
  59. _url_array[_active_index][BGCOLOR_INDEX],
  60. _url_array[_active_index][FNTCOLOR_INDEX],
  61. _url_array[_active_index][FNTFML_INDEX]);
  62. // remove mask div
  63. setInterval(function (){
  64. // BAIDU MOBILE
  65. _baidu_mobile_index(_url);
  66. _baidu_mobile_result(_url);
  67.  
  68. // CSDN
  69. var csdnContentBox = document.getElementsByClassName("blog-content-box")[0];
  70. if (null != csdnContentBox && typeof(csdnContentBox) !== "undefined"){
  71. csdnContentBox.style.background = "#8DA399";
  72. var links = document.getElementsByTagName("a");
  73. for (i = 0; i < links.length; i++){
  74. links[i].style.color = "#0014ff";
  75. }
  76. }
  77. var zhihuContentBox = document.getElementsByClassName("QuestionHeader-title")[1];
  78. if (null != zhihuContentBox && typeof(zhihuContentBox) !== "undefined"){
  79. zhihuContentBox.style.marginTop = "30px";
  80. }
  81. var axxwMaskDiv = document.getElementById("gzh-modal-wrap");
  82. if (null != axxwMaskDiv && typeof(axxwMaskDiv)!=="undefined"){
  83. axxwMaskDiv.parentNode.style.display = "none";
  84. }
  85.  
  86. // click button
  87. var _element_array = _url_array[_active_index][BTN_INDEX].split(" ");
  88. var m,i,_btns;
  89. for(m=0;m<_element_array.length;m++){
  90. if (""!==_element_array[m].trim()){
  91. _element_array[m] = _element_array[m].trim();
  92. _btns = document.getElementsByClassName(_element_array[m]);
  93. if(typeof(_btns) !== 'undefined'){
  94. for(i=0;i<_btns.length;i++){
  95. if('BUTTON' === _btns[i].tagName){
  96. // click the `close` button to close the mask div
  97. _btns[i].click();
  98. }
  99. }
  100. }
  101. }
  102. }
  103. _btns = document.getElementById("passportbox");
  104. if(null !== _btns && typeof(_btns) !== 'undefined' && _btns.children.length > 0){
  105. _btns.children[1].click();
  106. }
  107.  
  108.  
  109. // remove elements by class name
  110. _element_array = _url_array[_active_index][DELETE_INDEX].split(" ");
  111. for(m=0;m<_element_array.length;m++){
  112. if (""!==_element_array[m].trim()){
  113. _element_array[m] = _element_array[m].trim();
  114. _btns = document.getElementsByClassName(_element_array[m]);
  115. if(typeof(_btns) !== 'undefined'){
  116. for(i=0;i<_btns.length;i++){
  117. _btns[i].style.display = "none";
  118. }
  119. }
  120. }
  121. }
  122.  
  123. // resize divs
  124. _resize_div(_url_array[_active_index][MAXIMUM_INDEX].split(" "), OP_MAXIMUM_BY_CLASSES, _url_array[_active_index][RESIZE_INDEX]);
  125. _resize_div(_url_array[_active_index][MAXIMUM_INDEX].split(" "), OP_MAXIMUM_BY_TAG, _url_array[_active_index][RESIZE_INDEX]);
  126.  
  127. // open hidden divs
  128. var hiddenDivArray = document.getElementsByClassName("hide-preCode-bt");
  129. if (typeof(hiddenDivArray) !== "undefined" && hiddenDivArray.length > 0){
  130. for (i = 0; i < hiddenDivArray.length; i++){
  131. hiddenDivArray[i].click();
  132. }
  133. }
  134. }, 500);
  135. }
  136.  
  137. })();
  138.  
  139. function _baidu_mobile_result(_url){
  140. var i;
  141. if(_url.indexOf("baidu.com") < 0){
  142. return;
  143. }
  144.  
  145. document.body.style.background = "#181C1F";
  146. var controller = document.getElementById("page-controller");
  147. if(null != controller && typeof(controller)!=="undefined"){
  148. controller.style.color = "#EAF2F7";
  149. }
  150. //修改底部logo颜色
  151. var logoArray = document.querySelector("i.icon-logo");
  152. if (null !== logoArray &&
  153. typeof(logoArray) !== "undefined"){
  154. logoArray.style.color = "#EAF2F7";
  155. }
  156.  
  157. //修改底部logo翻页箭头颜色
  158. logoArray = document.querySelector("i.icon-nextpage");
  159. if (null !== logoArray &&
  160. typeof(logoArray) !== "undefined"){
  161. logoArray.style.color = "#EAF2F7";
  162. }
  163.  
  164. //修改底部导航栏背景色
  165. var pagenavArray = document.querySelector("div.new-pagenav");
  166. if (null !== pagenavArray &&
  167. typeof(pagenavArray) !== "undefined"){
  168. pagenavArray.style.background = "#181C1F";
  169. }
  170.  
  171. //干掉底部搜索
  172. var pageFoot = document.getElementById("page-ft");
  173. if (null !== pageFoot &&
  174. typeof(pageFoot) !== "undefined"){
  175. pageFoot.style.display = "none";
  176. }
  177.  
  178. //干掉搜索结果中的广告
  179. var advArray = document.querySelector("div.ec_wise_ad");
  180. if (null !== advArray &&
  181. typeof(advArray) !== "undefined"){
  182. advArray.style.display = "none";
  183. }
  184.  
  185. //干掉搜索结果中的悬浮窗广告
  186. advArray = document.querySelector("div.se-async-js");
  187. if (null !== advArray &&
  188. typeof(advArray) !== "undefined"){
  189. advArray.style.display = "none";
  190. }
  191.  
  192. //干掉搜索结果中的推荐(搜索结果列表中的)
  193. var resultsDiv = document.querySelector("div.results");
  194. var resultArray = resultsDiv.getElementsByClassName("c-result");
  195. if (null !== resultArray &&
  196. typeof(resultArray) !== "undefined" &&
  197. resultArray.length > 0){
  198.  
  199. for(i=0; i<resultArray.length; i++){
  200. if(resultArray[i].innerText.indexOf("大家还在搜") >= 0 ||
  201. resultArray[i].getAttribute('tpl') === "jy_rota_wenshu"|| // 不要百度文库的广告
  202. resultArray[i].getAttribute('tpl') === "image_strong_normal"|| // 不要百度图片
  203. resultArray[i].getAttribute('tpl') === "image_normal_tag"|| // 不要百度图片
  204. resultArray[i].getAttribute('tpl').indexOf("video") >= 0|| // 排除视频结果
  205. resultArray[i].getAttribute('tpl') === "sp_purc_atom" ){ // 不要百度商城推销
  206. resultArray[i].style.display = "none";
  207. resultArray[i].innerText="";
  208. }
  209. }
  210. }
  211.  
  212. //修改每个搜索结果框的背景色
  213. var containerArray = resultsDiv.getElementsByClassName("c-container");
  214. if (null !== containerArray &&
  215. typeof(containerArray) !== "undefined" &&
  216. containerArray.length > 0){
  217.  
  218. for(i=0; i<containerArray.length; i++){
  219. //修改每个搜索结果框的背景色
  220. containerArray[i].style.backgroundColor = "rgb(200 200 200)";
  221.  
  222. var span = containerArray[i].querySelector("span.c-color-source");
  223. if(null != span && span.innerText.indexOf("百度文库") >= 0){
  224. // 不要百度文库的结果,和S一样的东西
  225. containerArray[i].style.display = "none";
  226. span.innerText="";
  227. }else{
  228. //修改每个搜索结果框作者链接的字体颜色
  229. if (null !== containerArray[i].querySelector("div.single-text")){
  230. containerArray[i].querySelector("div.single-text").style.color = "#224d9d";
  231. }
  232. }
  233. }
  234. }
  235.  
  236. //修改搜索条部分的背景色和字体颜色
  237. var headTablink = document.querySelector("div.se-head-tablink");
  238. if (null !== headTablink &&
  239. typeof(headTablink) !== "undefined"){
  240. headTablink.style.backgroundColor = "#181C1F";
  241. headTablink.style.color = "#EAF2F7";
  242. }
  243.  
  244. //修改搜索条部分的背景色和字体颜色(移动版)
  245. headTablink = document.querySelector("se-head-tab-link");
  246. if (null !== headTablink &&
  247. typeof(headTablink) !== "undefined"){
  248. _recursion_set_color(headTablink,"#181C1F", "#EAF2F7");
  249. }
  250.  
  251. //修改搜索条下方百度产品列表部分的字体颜色
  252. var tabitemArray = document.querySelector("div.se-tab-lists").getElementsByTagName("a");
  253. if (null !== tabitemArray &&
  254. typeof(tabitemArray) !== "undefined" &&
  255. tabitemArray.length > 0){
  256.  
  257. for(i=0; i<tabitemArray.length; i++){
  258. tabitemArray[i].style.color = "#EAF2F7";
  259. span = null;
  260. span = tabitemArray[i].querySelector("span.se-tab-cur")
  261. if (null !== span){
  262. span.style.color = "red";
  263. }
  264. }
  265. }
  266.  
  267. //干掉相关搜索推荐(结尾处)
  268. var pageRelativeDiv = document.getElementById("page-relative");
  269. if (null !== pageRelativeDiv &&
  270. typeof(pageRelativeDiv) !== "undefined"){
  271. pageRelativeDiv.style.display = "none";
  272. }
  273.  
  274. //干掉广告(结尾版权处悬浮窗广告)
  275. var copyRightDiv = document.getElementById("page-copyright");
  276. if (null !== copyRightDiv &&
  277. typeof(copyRightDiv) !== "undefined"){
  278. copyRightDiv.style.display = "none";
  279. }
  280.  
  281. //修改搜索结果背景色
  282. var pageBdDiv = document.getElementById("page-bd");
  283. if (null !== pageBdDiv &&
  284. typeof(pageBdDiv) !== "undefined"){
  285. pageBdDiv.style.backgroundColor = "#181C1F";
  286. }
  287.  
  288. //修改搜索div头部背景色
  289. var pageHdDiv = document.getElementById("page-hd");
  290. if (null !== pageHdDiv &&
  291. typeof(pageHdDiv) !== "undefined"){
  292. pageHdDiv.style.backgroundColor = "#181C1F";
  293. }
  294. }
  295.  
  296. function _baidu_mobile_index(_url){
  297. if(_url !== "https://www.baidu.com" &&
  298. _url !== "https://www.baidu.com/" &&
  299. _url !== "https://m.baidu.com" &&
  300. _url !== "https://m.baidu.com/"){
  301. return;
  302. }
  303. var i;
  304.  
  305. // delete elements by class
  306. var underSearchboxTips = $(".under-searchbox-tips");
  307. if (null !== underSearchboxTips &&
  308. typeof(underSearchboxTips) !== "undefined" &&
  309. underSearchboxTips.length > 0){
  310.  
  311. for(i=0; i<underSearchboxTips.length; i++){
  312. underSearchboxTips[i].style.display = "none";
  313. }
  314. }
  315.  
  316. // delete elements by id
  317. var hotsearchWrapper = $("#s-hotsearch-wrapper");
  318. if (null !== hotsearchWrapper &&
  319. typeof(hotsearchWrapper) !== "undefined"){
  320. hotsearchWrapper.style.display = "none";
  321. }
  322. var hotsearchData = $("#hotsearch_data");
  323. if (null !== hotsearchData &&
  324. typeof(hotsearchData) !== "undefined"){
  325. hotsearchData.style.display = "none";
  326. }
  327.  
  328. // process baidu.com for mobile
  329. // header div
  330. setInterval(function(){
  331. var navIndex = -1;
  332. var headerDiv = document.getElementById("header");
  333. if (null != headerDiv && null != headerDiv){
  334. headerDiv.style.height = $(window).height()+"px";
  335. headerDiv.style.backgroundColor = "#181C1F";
  336. var headerChildrenArray = headerDiv.childNodes;
  337. if (null !== headerChildrenArray &&
  338. typeof(headerChildrenArray) !== "undefined"){
  339. for(i=0; i<headerChildrenArray.length; i++){
  340. if (null !== headerChildrenArray[i] &&
  341. typeof(headerChildrenArray[i]) !== "undefined"){
  342. if(headerChildrenArray[i].id === "navs"){
  343. navIndex = i;
  344. continue;
  345. }
  346. if(navIndex >= 0){
  347. headerChildrenArray[i].style.visibility = "hidden";
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }, 500);
  354. var indexForm = document.getElementById("index-form");
  355. var indexBtn = document.getElementById("index-bn");
  356. if (null != indexForm && null != indexForm){
  357. indexForm.style.borderColor = "rgb(116 116 116)";
  358. indexBtn.style.backgroundColor = "rgb(116 116 116)";
  359. $("#center-content-1").hide();
  360. $("#bottom").hide();
  361. $("#login-wraps").hide();
  362. $("#logo").hide();
  363. }
  364. }
  365.  
  366. function _resize_div(_div_names, _op, _resize_rate){
  367. var i,j;
  368. if(typeof(_div_names) !== 'undefined'){
  369. for(i=0;i<_div_names.length;i++){
  370. if(""!==_div_names[i]){
  371. var _elements;
  372. if (_op == 1){
  373. _elements = document.getElementsByClassName(_div_names[i]);
  374. }else{
  375. _elements = document.getElementsByTagName(_div_names[i]);
  376. }
  377. if(typeof(_elements) !== 'undefined'){
  378. for(j=0;j<_elements.length;j++){
  379. _elements[j].style.width = _resize_rate;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. }
  386.  
  387. /**
  388. * set font \ background-color \ font-family
  389. */
  390. function _recursion_set_color(parent, _bg_color, _fnt_color, _fnt_family){
  391. if (typeof(parent.children) !== 'undefined'){
  392. if (parent.children.length > 0){
  393. var i;
  394. for(i=0;i<parent.children.length;i++){
  395. _recursion_set_color(parent.children[i], _bg_color, _fnt_color, _fnt_family);
  396. }
  397. }
  398. if (""!==_bg_color){
  399. parent.style.backgroundColor = _bg_color;
  400. }
  401. if (""!==_fnt_color){
  402. parent.style.color = _fnt_color;
  403. }
  404. if (""!==_fnt_family){
  405. parent.style.fontFamily = _fnt_family;
  406. }
  407. }
  408. }

QingJ © 2025

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