change_style

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

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

  1. // ==UserScript==
  2. // @name change_style
  3. // @namespace https://netoday.cn
  4. // @version 0.1.17
  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. window.onscroll = function () {
  44. //监听事件内容
  45. if(getScrollHeight() == getWindowHeight() + getDocumentTop()){
  46. //当滚动条到底时,触发自动翻页(百度搜索结果)
  47. console.log("到底了,自动翻页");
  48. var nextPageBtn = document.getElementsByClassName("new-nextpage");
  49. if(null !== nextPageBtn && typeof(nextPageBtn) !== 'undefined' && nextPageBtn.length > 0){
  50. for(i=0;i<nextPageBtn.length;i++){
  51. nextPageBtn[i].click();
  52. }
  53. }
  54. }
  55. }
  56.  
  57.  
  58. // get url user visited
  59. var _url = (window.location + "").toLowerCase();
  60.  
  61. // if need active script
  62. var _active_index = -1;
  63. var i;
  64. for (i = 0; i < _url_array.length; i++){
  65. if (_url.indexOf(_url_array[i][URL_INDEX]) > 0){
  66. _active_index = i;
  67. break;
  68. }
  69. }
  70.  
  71. if (_active_index >= 0){
  72. // set color
  73. _recursion_set_color(document.body,
  74. _url_array[_active_index][BGCOLOR_INDEX],
  75. _url_array[_active_index][FNTCOLOR_INDEX],
  76. _url_array[_active_index][FNTFML_INDEX]);
  77. // remove mask div
  78. setInterval(function (){
  79. // BAIDU MOBILE
  80. _baidu_mobile_index(_url);
  81. _baidu_mobile_result(_url);
  82.  
  83. // CSDN
  84. var csdnContentBox = document.getElementsByClassName("blog-content-box")[0];
  85. if (null != csdnContentBox && typeof(csdnContentBox) !== "undefined"){
  86. csdnContentBox.style.background = "#8DA399";
  87. var links = document.getElementsByTagName("a");
  88. for (i = 0; i < links.length; i++){
  89. links[i].style.color = "#0014ff";
  90. }
  91. }
  92. var zhihuContentBox = document.getElementsByClassName("QuestionHeader-title")[1];
  93. if (null != zhihuContentBox && typeof(zhihuContentBox) !== "undefined"){
  94. zhihuContentBox.style.marginTop = "30px";
  95. }
  96. var axxwMaskDiv = document.getElementById("gzh-modal-wrap");
  97. if (null != axxwMaskDiv && typeof(axxwMaskDiv)!=="undefined"){
  98. axxwMaskDiv.parentNode.remove();
  99. }
  100.  
  101. // click button
  102. var _element_array = _url_array[_active_index][BTN_INDEX].split(" ");
  103. var m,i,_btns;
  104. for(m=0;m<_element_array.length;m++){
  105. if (""!==_element_array[m].trim()){
  106. _element_array[m] = _element_array[m].trim();
  107. _btns = document.getElementsByClassName(_element_array[m]);
  108. if(typeof(_btns) !== 'undefined'){
  109. for(i=0;i<_btns.length;i++){
  110. if('BUTTON' === _btns[i].tagName){
  111. // click the `close` button to close the mask div
  112. _btns[i].click();
  113. }
  114. }
  115. }
  116. }
  117. }
  118. _btns = document.getElementById("passportbox");
  119. if(null !== _btns && typeof(_btns) !== 'undefined' && _btns.children.length > 0){
  120. _btns.children[1].click();
  121. }
  122.  
  123.  
  124. // remove elements by class name
  125. _element_array = _url_array[_active_index][DELETE_INDEX].split(" ");
  126. for(m=0;m<_element_array.length;m++){
  127. if (""!==_element_array[m].trim()){
  128. _element_array[m] = _element_array[m].trim();
  129. _btns = document.getElementsByClassName(_element_array[m]);
  130. if(typeof(_btns) !== 'undefined'){
  131. for(i=0;i<_btns.length;i++){
  132. _btns[i].remove();
  133. }
  134. }
  135. }
  136. }
  137.  
  138. // resize divs
  139. _resize_div(_url_array[_active_index][MAXIMUM_INDEX].split(" "), OP_MAXIMUM_BY_CLASSES, _url_array[_active_index][RESIZE_INDEX]);
  140. _resize_div(_url_array[_active_index][MAXIMUM_INDEX].split(" "), OP_MAXIMUM_BY_TAG, _url_array[_active_index][RESIZE_INDEX]);
  141.  
  142. // open hidden divs
  143. var hiddenDivArray = document.getElementsByClassName("hide-preCode-bt");
  144. if (typeof(hiddenDivArray) !== "undefined" && hiddenDivArray.length > 0){
  145. for (i = 0; i < hiddenDivArray.length; i++){
  146. hiddenDivArray[i].click();
  147. }
  148. }
  149. }, 500);
  150. }
  151.  
  152. })();
  153.  
  154. //文档高度
  155. function getDocumentTop() {
  156. var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
  157. if (document.body) {
  158. bodyScrollTop = document.body.scrollTop;
  159. }
  160. if (document.documentElement) {
  161. documentScrollTop = document.documentElement.scrollTop;
  162. }
  163. scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop; return scrollTop;
  164. }
  165.  
  166. //可视窗口高度
  167. function getWindowHeight() {
  168. var windowHeight = 0;
  169. if (document.compatMode == "CSS1Compat") {
  170. windowHeight = document.documentElement.clientHeight;
  171. } else {
  172. windowHeight = document.body.clientHeight;
  173. }
  174. return windowHeight;
  175. }
  176.  
  177. //滚动条滚动高度
  178. function getScrollHeight() {
  179. var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
  180. if (document.body) {
  181. bodyScrollHeight = document.body.scrollHeight;
  182. }
  183. if (document.documentElement) {
  184. documentScrollHeight = document.documentElement.scrollHeight;
  185. }
  186. scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight; return scrollHeight;
  187. }
  188.  
  189. function _baidu_mobile_result(_url){
  190. var i;
  191. if(_url.indexOf("baidu.com") < 0){
  192. return;
  193. }
  194.  
  195. document.body.style.background = "#181C1F";
  196.  
  197. //干掉搜索结果中的广告
  198. var advArray = document.getElementsByClassName("ec_wise_ad");
  199. if (null !== advArray &&
  200. typeof(advArray) !== "undefined" &&
  201. advArray.length > 0){
  202.  
  203. for(i=0; i<advArray.length; i++){
  204. if(advArray[i].tagName === "DIV"){
  205. advArray[i].remove();
  206. }
  207. }
  208. }
  209.  
  210. //干掉搜索结果中的悬浮窗广告
  211. advArray = document.getElementsByClassName("se-async-js");
  212. if (null !== advArray &&
  213. typeof(advArray) !== "undefined" &&
  214. advArray.length > 0){
  215.  
  216. for(i=0; i<advArray.length; i++){
  217. advArray[i].remove();
  218. }
  219. }
  220.  
  221. //干掉搜索结果中的推荐(搜索结果列表中的)
  222. var resultArray = document.getElementsByClassName("c-result");
  223. if (null !== resultArray &&
  224. typeof(resultArray) !== "undefined" &&
  225. resultArray.length > 0){
  226.  
  227. for(i=0; i<resultArray.length; i++){
  228. if(resultArray[i].innerText.indexOf("大家还在搜") >= 0 ||
  229. resultArray[i].getAttribute('tpl') === "image_strong_normal"|| // 不要百度图片
  230. resultArray[i].getAttribute('tpl').indexOf("video") >= 0|| // 排除视频结果
  231. resultArray[i].getAttribute('tpl') === "sp_purc_atom" ){ // 不要百度商城推销
  232. resultArray[i].remove();
  233. }
  234. }
  235. }
  236.  
  237. //干掉搜索结果中的推荐(结尾处的)
  238. var otherArray = document.getElementsByClassName("c-result-content");
  239. if (null !== otherArray &&
  240. typeof(otherArray) !== "undefined" &&
  241. otherArray.length > 0){
  242.  
  243. for(i=0; i<otherArray.length; i++){
  244. if(otherArray[i].innerText.indexOf("大家还在搜") >= 0){
  245. otherArray[i].remove();
  246. }
  247. }
  248. }
  249.  
  250. //修改每个搜索结果框的背景色
  251. var containerArray = document.getElementsByClassName("c-container");
  252. if (null !== containerArray &&
  253. typeof(containerArray) !== "undefined" &&
  254. containerArray.length > 0){
  255.  
  256. for(i=0; i<containerArray.length; i++){
  257. containerArray[i].style.backgroundColor = "rgb(200 200 200)";
  258. if(containerArray[i].innerText.indexOf("大家还在搜") >= 0){
  259. containerArray[i].remove();
  260. }
  261. }
  262. }
  263.  
  264. //修改每个搜索结果框作者链接的字体颜色
  265. var authorArray = document.getElementsByClassName("c-color-source");
  266. if (null !== authorArray &&
  267. typeof(authorArray) !== "undefined" &&
  268. authorArray.length > 0){
  269.  
  270. for(i=0; i<authorArray.length; i++){
  271. if(authorArray[i].innerText.indexOf() >= 0){
  272. authorArray[i].remove(); // 不要百度文库的结果,和S一样的东西
  273. }else{
  274. authorArray[i].style.color = "#224d9d";
  275. }
  276. }
  277. }
  278.  
  279. //修改搜索条部分的背景色和字体颜色
  280. var headTablinkArray = document.getElementsByClassName("se-head-tablink");
  281. if (null !== headTablinkArray &&
  282. typeof(headTablinkArray) !== "undefined" &&
  283. headTablinkArray.length > 0){
  284.  
  285. for(i=0; i<headTablinkArray.length; i++){
  286. headTablinkArray[i].style.backgroundColor = "#181C1F";
  287. headTablinkArray[i].style.color = "#EAF2F7";
  288. }
  289. }
  290.  
  291. //修改搜索条下方百度产品列表部分的字体颜色
  292. var tabitemArray = document.getElementsByClassName("se-tabitem");
  293. if (null !== tabitemArray &&
  294. typeof(tabitemArray) !== "undefined" &&
  295. tabitemArray.length > 0){
  296.  
  297. for(i=0; i<tabitemArray.length; i++){
  298. tabitemArray[i].style.color = "#EAF2F7";
  299. }
  300. }
  301.  
  302. //修改搜索条下方百度产品列表部分当前选中页签的字体颜色
  303. var currentSelectArray = document.getElementsByClassName("se-tab-cur");
  304. if (null !== currentSelectArray &&
  305. typeof(currentSelectArray) !== "undefined" &&
  306. currentSelectArray.length > 0){
  307.  
  308. for(i=0; i<currentSelectArray.length; i++){
  309. currentSelectArray[i].style.color = "#EAF2F7";
  310. }
  311. }
  312.  
  313. //干掉相关搜索推荐(结尾处)
  314. var pageRelativeDiv = document.getElementById("page-relative");
  315. if (null !== pageRelativeDiv &&
  316. typeof(pageRelativeDiv) !== "undefined"){
  317. pageRelativeDiv.remove();
  318. }
  319.  
  320. //干掉广告(结尾版权处悬浮窗广告)
  321. var copyRightDiv = document.getElementById("page-copyright");
  322. if (null !== copyRightDiv &&
  323. typeof(copyRightDiv) !== "undefined"){
  324. copyRightDiv.remove();
  325. }
  326.  
  327. //修改搜索结果背景色
  328. var pageBdDiv = document.getElementById("page-bd");
  329. if (null !== pageBdDiv &&
  330. typeof(pageBdDiv) !== "undefined"){
  331. pageBdDiv.style.backgroundColor = "#181C1F";
  332. }
  333.  
  334. //修改搜索div头部背景色
  335. var pageHdDiv = document.getElementById("page-hd");
  336. if (null !== pageHdDiv &&
  337. typeof(pageHdDiv) !== "undefined"){
  338. pageHdDiv.style.backgroundColor = "#181C1F";
  339. }
  340. }
  341.  
  342. function _baidu_mobile_index(_url){
  343. if(_url !== "https://www.baidu.com" &&
  344. _url !== "https://www.baidu.com/" &&
  345. _url !== "https://m.baidu.com" &&
  346. _url !== "https://m.baidu.com/"){
  347. return;
  348. }
  349. var i;
  350.  
  351. // delete elements by class
  352. var underSearchboxTips = $(".under-searchbox-tips");
  353. if (null !== underSearchboxTips &&
  354. typeof(underSearchboxTips) !== "undefined" &&
  355. underSearchboxTips.length > 0){
  356.  
  357. for(i=0; i<underSearchboxTips.length; i++){
  358. underSearchboxTips[i].remove();
  359. }
  360. }
  361.  
  362. // delete elements by id
  363. var hotsearchWrapper = $("#s-hotsearch-wrapper");
  364. if (null !== hotsearchWrapper &&
  365. typeof(hotsearchWrapper) !== "undefined"){
  366. hotsearchWrapper.remove();
  367. }
  368. var hotsearchData = $("#hotsearch_data");
  369. if (null !== hotsearchData &&
  370. typeof(hotsearchData) !== "undefined"){
  371. hotsearchData.remove();
  372. }
  373.  
  374. // process baidu.com for mobile
  375. // header div
  376. setInterval(function(){
  377. var navIndex = -1;
  378. var headerDiv = document.getElementById("header");
  379. if (null != headerDiv && null != headerDiv){
  380. headerDiv.style.height = $(window).height()+"px";
  381. headerDiv.style.backgroundColor = "#181C1F";
  382. var headerChildrenArray = headerDiv.childNodes;
  383. if (null !== headerChildrenArray &&
  384. typeof(headerChildrenArray) !== "undefined"){
  385. for(i=0; i<headerChildrenArray.length; i++){
  386. if (null !== headerChildrenArray[i] &&
  387. typeof(headerChildrenArray[i]) !== "undefined"){
  388. if(headerChildrenArray[i].id === "navs"){
  389. navIndex = i;
  390. continue;
  391. }
  392. if(navIndex >= 0){
  393. headerChildrenArray[i].style.visibility = "hidden";
  394. }
  395. }
  396. }
  397. }
  398. }
  399. }, 500);
  400. var indexForm = document.getElementById("index-form");
  401. var indexBtn = document.getElementById("index-bn");
  402. if (null != indexForm && null != indexForm){
  403. indexForm.style.borderColor = "rgb(116 116 116)";
  404. indexBtn.style.backgroundColor = "rgb(116 116 116)";
  405. $("#center-content-1").hide();
  406. $("#bottom").hide();
  407. $("#login-wraps").hide();
  408. $("#logo").hide();
  409. }
  410. }
  411.  
  412. function _resize_div(_div_names, _op, _resize_rate){
  413. var i,j;
  414. if(typeof(_div_names) !== 'undefined'){
  415. for(i=0;i<_div_names.length;i++){
  416. if(""!==_div_names[i]){
  417. var _elements;
  418. if (_op == 1){
  419. _elements = document.getElementsByClassName(_div_names[i]);
  420. }else{
  421. _elements = document.getElementsByTagName(_div_names[i]);
  422. }
  423. if(typeof(_elements) !== 'undefined'){
  424. for(j=0;j<_elements.length;j++){
  425. _elements[j].style.width = _resize_rate;
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432.  
  433. /**
  434. * set font \ background-color \ font-family
  435. */
  436. function _recursion_set_color(parent, _bg_color, _fnt_color, _fnt_family){
  437. if (typeof(parent.children) !== 'undefined'){
  438. if (parent.children.length > 0){
  439. var i;
  440. for(i=0;i<parent.children.length;i++){
  441. _recursion_set_color(parent.children[i], _bg_color, _fnt_color, _fnt_family);
  442. }
  443. }
  444. if (""!==_bg_color){
  445. parent.style.backgroundColor = _bg_color;
  446. }
  447. if (""!==_fnt_color){
  448. parent.style.color = _fnt_color;
  449. }
  450. if (""!==_fnt_family){
  451. parent.style.fontFamily = _fnt_family;
  452. }
  453. }
  454. }

QingJ © 2025

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