change_style

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

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

QingJ © 2025

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