No Google Doodle

Get rid of Google Doodle logos and link

当前为 2021-04-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name No Google Doodle
  3. // @namespace https://github.com/Procyon-b
  4. // @version 0.6.1
  5. // @description Get rid of Google Doodle logos and link
  6. // @author Achernar
  7. // @include https://www.google.tld/
  8. // @include https://www.google.tld/?*
  9. // @include https://www.google.tld/webhp*
  10. // @run-at document-start
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. "use strict";
  16.  
  17. var logo, outer=false, fixed=false, style='#replacedDoodle ~ div, #replacedDoodle ~ canvas {display:none;}';
  18.  
  19. var st=document.createElement("style");
  20. st.textContent='#hplogo > *:not(#replacedDoodle), a > img#hplogo {display: none;}'+style;
  21. try{document.head.appendChild(st);}catch(e){}
  22.  
  23. if (document.readyState != 'loading') fix();
  24. else {
  25. document.addEventListener('DOMContentLoaded', function(){
  26. obs.disconnect();
  27. fix();
  28. });
  29.  
  30. const obs = new MutationObserver(function(muts){
  31. for (let mut of muts) {
  32. for (let n of mut.addedNodes) {
  33. if (n.classList && n.classList.contains('o3j99')) {
  34. if (n.querySelector('#hplogo')) {
  35. this.disconnect();
  36. fix();
  37. return;
  38. }
  39. }
  40. }
  41. }
  42. });
  43. obs.observe(document, { attributes: false, childList: true, subtree: true});
  44. }
  45.  
  46. function fix() {
  47. if ( (document.title!='Google') || fixed ) return;
  48. fixed=true;
  49. logo=document.querySelector('div#hplogo');
  50. if (!logo) {
  51. if (logo = document.querySelector('a > img#hplogo')) {
  52. logo=logo.parentNode;
  53. outer=true;
  54. }
  55. }
  56. if (logo) {
  57. let h='<img id="replacedDoodle" style="bottom:0;position:absolute;left:50%;transform:translate(-50%);" src="/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"><style>'+style+'</style>';
  58. if (outer) logo.outerHTML=h;
  59. else logo.innerHTML=h;
  60. setTimeout(function(){
  61. var a=document.querySelectorAll('#replacedDoodle ~ :not(style)');
  62. a.forEach(function(e){ e.remove(); });
  63. }, 300);
  64. }
  65. else {
  66. st.remove();
  67. }
  68. }
  69.  
  70. })();