Greasy Fork镜像 支持简体中文。

change_style

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

目前為 2022-09-29 提交的版本,檢視 最新版本

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

QingJ © 2025

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