黑白网页恢复彩色

黑白网页恢复彩色,匹配所有网页,即装即用。

  1. // ==UserScript==
  2. // @name 黑白网页恢复彩色
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.11.5
  5. // @license MIT
  6. // @description 黑白网页恢复彩色,匹配所有网页,即装即用。
  7. // @author https://gf.qytechs.cn/users/574395-frammolz-amanda
  8. // @match *://*/*
  9. // @grant GM_xmlhttpRequest
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. var temp = document.createElement('style');//先添加一个临时的,减少延迟,最后会remove掉
  14. temp.type = 'text/css';
  15. temp.appendChild(document.createTextNode("*{-webkit-filter:none !important;}"));
  16. var tmitv = setInterval(function() {
  17. try{
  18. document.head.appendChild(temp);
  19. document.body.appendChild(temp);
  20. clearInterval(tmitv);
  21. }catch{}
  22. },30);
  23. window.addEventListener("load", function () {
  24. var filter = document.createElement('style');
  25. filter.type = 'text/css';
  26. document.head.appendChild(filter);
  27. var windowUrl = window.location.href;
  28. if(document.getElementById("nv_forum"))document.getElementById("nv_forum").style.setProperty("background-blend-mode","normal");//Discuz论坛通用
  29. if( windowUrl.match(/https:\/\/www.58pic.com\/($|\?)/))filter.appendChild(document.createTextNode("*{-webkit-filter:none !important;}"));
  30. if( windowUrl.match(/https:\/\/www.baidu.com\/($|\?)/)){
  31. document.getElementById("s_lg_img").setAttribute("src","https://www.baidu.com/img/flexible/logo/pc/index.png");
  32. document.getElementById("s_lg_img_new").setAttribute("src","https://www.baidu.com/img/flexible/logo/pc/index.png");
  33. document.getElementById("su").style.setProperty("background-color","#4e6ef2","important");
  34. if (document.getElementsByClassName("index-logo-src").length==1){
  35. document.getElementsByClassName("index-logo-src")[0].setAttribute("src","https://www.baidu.com/img/flexible/logo/pc/result.png");
  36. document.getElementsByClassName("index-logo-peak")[0].setAttribute("src","https://www.baidu.com/img/flexible/logo/pc/result.png");
  37. document.getElementsByClassName("index-logo-srcnew")[0].setAttribute("src","https://www.baidu.com/img/flexible/logo/pc/result.png");
  38. }
  39. }
  40. if( windowUrl.match(/https:\/\/m.baidu.com\/($|\?)/)){
  41. document.getElementById("logo").getElementsByTagName("a")[0].getElementsByTagName("img")[0].setAttribute("src","https://www.baidu.com/img/flexible/logo/logo_web.png");
  42. document.getElementById("index-bn").style.setProperty("background-color","#4e6ef2","important");
  43. }
  44. if( windowUrl.match(/https:\/\/www.bilibili.com\/($|\?)/)){
  45. var source=[["//i0.hdslb.com/bfs/archive/0ac04c23af3b3297bf02dca163474326898d211d.png","//i0.hdslb.com/bfs/archive/583e5db0ffa0c4de4fc88de35e802767a9c93b63.png","//i0.hdslb.com/bfs/archive/ab6b34468bcc179b601541193eda668f2aa6106b.jpg","//i0.hdslb.com/bfs/archive/a421773e566a623fca26e12ae3921bda4a3fd856.png","//i0.hdslb.com/bfs/archive/3329c9f0abfb925ae30441f24d924ad3c19775df.png","//i0.hdslb.com/bfs/archive/57c5ced363be9f08b4cacf1745e221d3bb99d7c5.png"],["//i0.hdslb.com/bfs/archive/bdb288021ff854d3ac618ac8c1eafd300ec9ed9b.png","//i0.hdslb.com/bfs/archive/5d49497b6b7f30950f37c4aff205e7dd1494f3b9.png","//i0.hdslb.com/bfs/archive/bd90aa68aaaaddb1b5421b84298c51f5b90210e0.png","//i0.hdslb.com/bfs/archive/3d30de7942ed74d2515f28ae04eb1444e8d57f40.png","//i0.hdslb.com/bfs/archive/6592e92861e6248205af17702d06ea3f97d81de6.png","//i0.hdslb.com/bfs/archive/58d322146cb4b1685a5775478b9753f96a0c2ff6.png"]]
  46. var index=Math.floor(Math.random()*6);
  47. if(document.getElementsByClassName("v-img banner-img").length){document.getElementsByClassName("v-img banner-img")[0].getElementsByTagName("source")[0].setAttribute("srcset",source[0][index]);document.getElementsByClassName("logo-img")[0].setAttribute("src",source[1][index]);}
  48. else setTimeout(function(){document.getElementsByClassName("bili-banner")[0].style.setProperty("background-image","url(\""+source[0][index]+"\")");document.getElementsByClassName("logo-img")[0].setAttribute("src",source[1][index]);},500);
  49. }
  50. if( windowUrl.match(/https:\/\/weibo.com/)){
  51. var body = document.body;
  52. if(body.classList.length){
  53. document.getElementById("plc_frame").getElementsByTagName("style")[0].remove();
  54. const callback = function(mutationsList, observer) {
  55. for(let mutation of mutationsList){
  56. if (mutation.type === "childList") document.getElementById("plc_frame").getElementsByTagName("style")[0].remove();
  57. }
  58. }
  59. new MutationObserver(callback).observe(body, { childList: true,});
  60. return;
  61. }
  62. }
  63. if( windowUrl.match(/https:\/\/www.ixigua.com/)){
  64. var chd = 0;
  65. replace();
  66. if( windowUrl.match(/https:\/\/www.ixigua.com\/[0-9]+/))obs("projection_recommentWrapper");
  67. else obs("v3-app-layout__content");
  68. function obs(clsname){
  69. const callback = function(mutationsList, observer) {
  70. for(let mutation of mutationsList){
  71. if (mutation.type === 'childList') replace();
  72. }
  73. }
  74. new MutationObserver(callback).observe(document.getElementsByClassName(clsname)[0],{ childList: true, subtree: true});
  75. }
  76. function replace(){
  77. var ob=document.getElementsByClassName("HorizontalFeedCard__coverWrapper disableZoomAnimation");
  78. for( var index=chd;index<Object.keys(ob).length;index++ ){get_pic(ob[index].getAttribute('href').slice(1),index);}
  79. chd=Object.keys(ob).length;
  80. function get_pic(vid,index){
  81. var httpRequest = new XMLHttpRequest();
  82. httpRequest.open("GET", "https://www.ixigua.com/api/public/videov2/brief/details?group_id="+vid, true);
  83. httpRequest.send();
  84. httpRequest.onreadystatechange = function () {
  85. if (httpRequest.readyState == 4 && httpRequest.status == 200) var timer=setInterval(function () {if (ob[index].getElementsByTagName("img")[0].complete){ob[index].getElementsByClassName("tt-img BU-MagicImage tt-img-loaded")[0].setAttribute("src",JSON.parse(httpRequest.responseText).data.posterUrl.slice(5));clearInterval(timer);}},50);
  86. }
  87. }
  88. }
  89. }
  90. if( windowUrl.match(/https:\/\/www.cib.com.cn\/cn\/index.html$/)){
  91. document.body.innerHTML = document.body.innerHTML.replace(/\/cn\/home-gray\/image\//g, '/cn/customer/home/');
  92. document.body.innerHTML = document.body.innerHTML.replace(/\/css\/2015\/gray\//g, '/css/2015/');
  93. document.head.getElementsByTagName("link")[0].setAttribute("href","/cn/resources/css/2015/base.css?v=0705");
  94. }
  95. fir();
  96. function fir(){
  97. let styleSheets=document.styleSheets;//外部css样式表修改
  98. for (const key in styleSheets) {
  99. if (Object.hasOwnProperty.call(styleSheets, key)) {
  100. try{
  101. if(styleSheets[key].href) get_css(styleSheets[key].href);
  102. let cssRules=styleSheets[key].cssRules;
  103. for (const k in cssRules) {
  104. if (Object.hasOwnProperty.call(cssRules, k)) {
  105. if(cssRules[k].cssText.match(/filter.*grayscale/)){
  106. set(cssRules[k].cssText);
  107. }
  108. }
  109. }
  110. }catch{}
  111. }
  112. }
  113. function get_css(url){
  114. GM_xmlhttpRequest({
  115. method: "get",
  116. url: url,
  117. onload: function(r){
  118. var open;
  119. var close;
  120. let css=r.responseText
  121. while ((open = css.indexOf("/*")) !== -1 &&
  122. (close = css.indexOf("*/")) !== -1) {
  123. css = css.substring(0, open) + css.substring(close + 2);
  124. }
  125. for(var em of css.split("}")){
  126. if(em.match(/filter.*grayscale/)){
  127. set(em+"}");
  128. }
  129. }
  130. }
  131. });
  132. }
  133. function set(ele){
  134. try{
  135. ele=ele.replace(/saturate\(.*?\)/g,"saturate(1)");
  136. }catch{}
  137. if(ele.match(/grayscale(.*?)[^;]important/))filter.appendChild(document.createTextNode(ele.replace(/grayscale\(.*?\)/g,"grayscale(0)")));
  138. else{
  139. var text=ele.replace(/grayscale\(.*?\)/g,"grayscale(0)").slice(0,-1);
  140. var csstext=""
  141. for(var st of text.split(";")){
  142. if(st.match(/grayscale\(0\)/)) csstext+=st+"!important;"
  143. else if(st.match(/^\s+$/)){}
  144. else csstext+=st+";"
  145. }
  146. filter.appendChild(document.createTextNode(csstext+"}"));
  147. }
  148. }
  149. let i=0;
  150. var tmitv = setInterval(function(){
  151. var inner=document.querySelector("html").outerHTML.match(/<[^<>]*?filter[^<>]*?grayscale[^<>]*?>/g);//行内样式修改
  152. if(inner){
  153. for(let i=0;i<inner.length;i++){
  154. var tags=document.querySelectorAll(inner[i].split(" ")[0].slice(1))
  155. for(let j=0;j<Object.keys(tags).length;j++){
  156. try{
  157. if(tags[j].getAttribute("style").match(/filter.*?grayscale/)){
  158. tags[j].setAttribute("style",tags[j].getAttribute("style").replace(/grayscale\(.*?\)/g, "grayscale(0)"));
  159. }
  160. }catch{}
  161. }
  162. }
  163. }
  164. var sty=document.getElementsByTagName("style");//块内样式修改
  165. for(let i=0;i<Object.keys(sty).length;i++){
  166. if(sty[i].innerHTML.match(/filter.*grayscale/))sty[i].innerHTML = sty[i].innerHTML.replace(/grayscale\(.*?\)/g, "grayscale(0)");
  167. }
  168. i++;
  169. if(i==3){
  170. clearInterval(tmitv);
  171. temp.remove();
  172. }
  173. },200);
  174. }
  175. })

QingJ © 2025

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