change_style

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

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

  1. // ==UserScript==
  2. // @name change_style
  3. // @namespace https://netoday.cn
  4. // @version 0.1.26
  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.remove();
  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].remove();
  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.  
  147. //干掉搜索结果中的广告
  148. var advArray = document.getElementsByClassName("ec_wise_ad");
  149. if (null !== advArray &&
  150. typeof(advArray) !== "undefined" &&
  151. advArray.length > 0){
  152.  
  153. for(i=0; i<advArray.length; i++){
  154. if(advArray[i].tagName === "DIV"){
  155. advArray[i].remove();
  156. }
  157. }
  158. }
  159.  
  160. //干掉搜索结果中的悬浮窗广告
  161. advArray = document.getElementsByClassName("se-async-js");
  162. if (null !== advArray &&
  163. typeof(advArray) !== "undefined" &&
  164. advArray.length > 0){
  165.  
  166. for(i=0; i<advArray.length; i++){
  167. advArray[i].remove();
  168. }
  169. }
  170.  
  171. //干掉搜索结果中的推荐(搜索结果列表中的)
  172. var resultArray = document.getElementsByClassName("c-result");
  173. if (null !== resultArray &&
  174. typeof(resultArray) !== "undefined" &&
  175. resultArray.length > 0){
  176.  
  177. for(i=0; i<resultArray.length; i++){
  178. if(resultArray[i].innerText.indexOf("大家还在搜") >= 0 ||
  179. resultArray[i].getAttribute('tpl') === "jy_rota_wenshu"|| // 不要百度文库的广告
  180. resultArray[i].getAttribute('tpl') === "image_strong_normal"|| // 不要百度图片
  181. resultArray[i].getAttribute('tpl').indexOf("video") >= 0|| // 排除视频结果
  182. resultArray[i].getAttribute('tpl') === "sp_purc_atom" ){ // 不要百度商城推销
  183. resultArray[i].remove();
  184. }
  185. }
  186. }
  187.  
  188. //干掉搜索结果中的推荐(结尾处的)
  189. var otherArray = document.getElementsByClassName("c-result-content");
  190. if (null !== otherArray &&
  191. typeof(otherArray) !== "undefined" &&
  192. otherArray.length > 0){
  193.  
  194. for(i=0; i<otherArray.length; i++){
  195. if(otherArray[i].innerText.indexOf("大家还在搜") >= 0){
  196. otherArray[i].remove();
  197. }
  198. }
  199. }
  200.  
  201. //修改每个搜索结果框的背景色
  202. var containerArray = document.getElementsByClassName("c-container");
  203. if (null !== containerArray &&
  204. typeof(containerArray) !== "undefined" &&
  205. containerArray.length > 0){
  206.  
  207. for(i=0; i<containerArray.length; i++){
  208. containerArray[i].style.backgroundColor = "rgb(200 200 200)";
  209. if(containerArray[i].innerText.indexOf("大家还在搜") >= 0){
  210. containerArray[i].remove();
  211. }
  212. }
  213. }
  214.  
  215. //修改每个搜索结果框作者链接的字体颜色
  216. var authorArray = document.getElementsByClassName("c-color-source");
  217. if (null !== authorArray &&
  218. typeof(authorArray) !== "undefined" &&
  219. authorArray.length > 0){
  220.  
  221. for(i=0; i<authorArray.length; i++){
  222. if(authorArray[i].innerText.indexOf("百度文库") >= 0){
  223. authorArray[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.remove(); // 不要百度文库的结果,和S一样的东西
  224. }else{
  225. authorArray[i].style.color = "#224d9d";
  226. }
  227. }
  228. }
  229.  
  230. //修改搜索条部分的背景色和字体颜色
  231. var headTablinkArray = document.getElementsByClassName("se-head-tablink");
  232. if (null !== headTablinkArray &&
  233. typeof(headTablinkArray) !== "undefined" &&
  234. headTablinkArray.length > 0){
  235.  
  236. for(i=0; i<headTablinkArray.length; i++){
  237. headTablinkArray[i].style.backgroundColor = "#181C1F";
  238. headTablinkArray[i].style.color = "#EAF2F7";
  239. }
  240. }
  241.  
  242. //修改搜索条部分的背景色和字体颜色(移动版)
  243. headTablinkArray = document.getElementsByClassName("se-head-tab-link");
  244. if (null !== headTablinkArray &&
  245. typeof(headTablinkArray) !== "undefined" &&
  246. headTablinkArray.length > 0){
  247.  
  248. for(i=0; i<headTablinkArray.length; i++){
  249. _recursion_set_color(headTablinkArray[i],"#181C1F", "#EAF2F7");
  250. }
  251. }
  252.  
  253. //修改搜索条下方百度产品列表部分的字体颜色
  254. var tabitemArray = document.getElementsByClassName("se-tabitem");
  255. if (null !== tabitemArray &&
  256. typeof(tabitemArray) !== "undefined" &&
  257. tabitemArray.length > 0){
  258.  
  259. for(i=0; i<tabitemArray.length; i++){
  260. tabitemArray[i].style.color = "#EAF2F7";
  261. }
  262. }
  263.  
  264. //修改搜索条下方百度产品列表部分当前选中页签的字体颜色
  265. var currentSelectArray = document.getElementsByClassName("se-tab-cur");
  266. if (null !== currentSelectArray &&
  267. typeof(currentSelectArray) !== "undefined" &&
  268. currentSelectArray.length > 0){
  269.  
  270. for(i=0; i<currentSelectArray.length; i++){
  271. currentSelectArray[i].style.color = "#EAF2F7";
  272. }
  273. }
  274.  
  275. //干掉相关搜索推荐(结尾处)
  276. var pageRelativeDiv = document.getElementById("page-relative");
  277. if (null !== pageRelativeDiv &&
  278. typeof(pageRelativeDiv) !== "undefined"){
  279. pageRelativeDiv.remove();
  280. }
  281.  
  282. //干掉广告(结尾版权处悬浮窗广告)
  283. var copyRightDiv = document.getElementById("page-copyright");
  284. if (null !== copyRightDiv &&
  285. typeof(copyRightDiv) !== "undefined"){
  286. copyRightDiv.remove();
  287. }
  288.  
  289. //修改搜索结果背景色
  290. var pageBdDiv = document.getElementById("page-bd");
  291. if (null !== pageBdDiv &&
  292. typeof(pageBdDiv) !== "undefined"){
  293. pageBdDiv.style.backgroundColor = "#181C1F";
  294. }
  295.  
  296. //修改搜索div头部背景色
  297. var pageHdDiv = document.getElementById("page-hd");
  298. if (null !== pageHdDiv &&
  299. typeof(pageHdDiv) !== "undefined"){
  300. pageHdDiv.style.backgroundColor = "#181C1F";
  301. }
  302. }
  303.  
  304. function _baidu_mobile_index(_url){
  305. if(_url !== "https://www.baidu.com" &&
  306. _url !== "https://www.baidu.com/" &&
  307. _url !== "https://m.baidu.com" &&
  308. _url !== "https://m.baidu.com/"){
  309. return;
  310. }
  311. var i;
  312.  
  313. // delete elements by class
  314. var underSearchboxTips = $(".under-searchbox-tips");
  315. if (null !== underSearchboxTips &&
  316. typeof(underSearchboxTips) !== "undefined" &&
  317. underSearchboxTips.length > 0){
  318.  
  319. for(i=0; i<underSearchboxTips.length; i++){
  320. underSearchboxTips[i].remove();
  321. }
  322. }
  323.  
  324. // delete elements by id
  325. var hotsearchWrapper = $("#s-hotsearch-wrapper");
  326. if (null !== hotsearchWrapper &&
  327. typeof(hotsearchWrapper) !== "undefined"){
  328. hotsearchWrapper.remove();
  329. }
  330. var hotsearchData = $("#hotsearch_data");
  331. if (null !== hotsearchData &&
  332. typeof(hotsearchData) !== "undefined"){
  333. hotsearchData.remove();
  334. }
  335.  
  336. // process baidu.com for mobile
  337. // header div
  338. setInterval(function(){
  339. var navIndex = -1;
  340. var headerDiv = document.getElementById("header");
  341. if (null != headerDiv && null != headerDiv){
  342. headerDiv.style.height = $(window).height()+"px";
  343. headerDiv.style.backgroundColor = "#181C1F";
  344. var headerChildrenArray = headerDiv.childNodes;
  345. if (null !== headerChildrenArray &&
  346. typeof(headerChildrenArray) !== "undefined"){
  347. for(i=0; i<headerChildrenArray.length; i++){
  348. if (null !== headerChildrenArray[i] &&
  349. typeof(headerChildrenArray[i]) !== "undefined"){
  350. if(headerChildrenArray[i].id === "navs"){
  351. navIndex = i;
  352. continue;
  353. }
  354. if(navIndex >= 0){
  355. headerChildrenArray[i].style.visibility = "hidden";
  356. }
  357. }
  358. }
  359. }
  360. }
  361. }, 500);
  362. var indexForm = document.getElementById("index-form");
  363. var indexBtn = document.getElementById("index-bn");
  364. if (null != indexForm && null != indexForm){
  365. indexForm.style.borderColor = "rgb(116 116 116)";
  366. indexBtn.style.backgroundColor = "rgb(116 116 116)";
  367. $("#center-content-1").hide();
  368. $("#bottom").hide();
  369. $("#login-wraps").hide();
  370. $("#logo").hide();
  371. }
  372. }
  373.  
  374. function _resize_div(_div_names, _op, _resize_rate){
  375. var i,j;
  376. if(typeof(_div_names) !== 'undefined'){
  377. for(i=0;i<_div_names.length;i++){
  378. if(""!==_div_names[i]){
  379. var _elements;
  380. if (_op == 1){
  381. _elements = document.getElementsByClassName(_div_names[i]);
  382. }else{
  383. _elements = document.getElementsByTagName(_div_names[i]);
  384. }
  385. if(typeof(_elements) !== 'undefined'){
  386. for(j=0;j<_elements.length;j++){
  387. _elements[j].style.width = _resize_rate;
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394.  
  395. /**
  396. * set font \ background-color \ font-family
  397. */
  398. function _recursion_set_color(parent, _bg_color, _fnt_color, _fnt_family){
  399. if (typeof(parent.children) !== 'undefined'){
  400. if (parent.children.length > 0){
  401. var i;
  402. for(i=0;i<parent.children.length;i++){
  403. _recursion_set_color(parent.children[i], _bg_color, _fnt_color, _fnt_family);
  404. }
  405. }
  406. if (""!==_bg_color){
  407. parent.style.backgroundColor = _bg_color;
  408. }
  409. if (""!==_fnt_color){
  410. parent.style.color = _fnt_color;
  411. }
  412. if (""!==_fnt_family){
  413. parent.style.fontFamily = _fnt_family;
  414. }
  415. }
  416. }

QingJ © 2025

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