新浪邮箱广告去除器

可以去除新浪邮箱网页版里的广告

  1. // ==UserScript==
  2. // @name 新浪邮箱广告去除器
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 可以去除新浪邮箱网页版里的广告
  6. // @author Firepup6500
  7. // @match http://*/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. (() => {
  16. let oldPushState = history.pushState;
  17. history.pushState = function pushState() {
  18. let ret = oldPushState.apply(this, arguments);
  19. window.dispatchEvent(new Event('pushstate'));
  20. window.dispatchEvent(new Event('locationchange'));
  21. return ret;
  22. };
  23.  
  24. let oldReplaceState = history.replaceState;
  25. history.replaceState = function replaceState() {
  26. let ret = oldReplaceState.apply(this, arguments);
  27. window.dispatchEvent(new Event('replacestate'));
  28. window.dispatchEvent(new Event('locationchange'));
  29. return ret;
  30. };
  31.  
  32. window.addEventListener('popstate', () => {
  33. window.dispatchEvent(new Event('locationchange'));
  34. });
  35. })();
  36. let sites = {
  37. /*
  38. 'example.com': { // website domain, can be regex.
  39. remove: ['.some-class','#some-element'], // Hide these elements (used for ads) - (DOES NOT REMOVE THEM, JUST HIDES THEM)
  40. click: ['.class','#element'], // Click these elements (used for cookie consent)
  41. interaction: true, // Move mouse cursor to trigger `onmousemove` ads
  42. timeout: 2000, // In MS, how long to wait before doing anything
  43. interval: 0, // In MS, how long to wait before redoing everything (Ignored if 0 or missing) (used if ads are added onscroll or timeout)
  44. onChange: true, // Redo everything once page changes, but no refresh/reload occurs (IE: Discourse)
  45. antiVignette: true, // Auto fix google vignette based issues
  46. trueRemove: true // Actually remove elements instead of hiding them (WARNING: Might trigger adblock detection!)
  47. background: '#ffffff' // Set a background-color, overflow:scroll, and position (used for custom fullpage ads)
  48. },
  49. */
  50. '.*\.?mail.sina\.com': {
  51. remove: ['#sinaadToolkitBox0', '.extendAd', 'div.extendAd','.top-ads-container','.bottom-ads-container','#WikiaBar','.notifications-placeholder','.gpt-ad'],
  52. interaction: true,
  53. timeout: 5000,
  54. interval: 2000,
  55. trueRemove: true
  56. },
  57. }
  58.  
  59. let interval = null;
  60.  
  61. let hostname = document.location.hostname;
  62.  
  63. let loaded = false;
  64.  
  65. function cleanup() {
  66. console.log("Running cleanup...");
  67. if(sites[hostname].interaction) {
  68. document.body.dispatchEvent(new MouseEvent('mousemove'));
  69. }
  70.  
  71. if(sites[hostname].remove) {
  72. let selectors = sites[hostname].remove;
  73.  
  74. selectors.forEach(function(selector) {
  75. let elements = document.querySelectorAll(selector);
  76.  
  77. console.log(selector, elements);
  78.  
  79. elements.forEach(function(elem) {
  80. if (!sites[hostname].trueRemove) {
  81. elem.style.visibility = 'hidden';
  82. elem.style.width = '1px';
  83. elem.style.height = '1px';
  84. elem.style.overflow = 'hidden';
  85. elem.style.opacity = 0;
  86. } else {
  87. elem.remove();
  88. }
  89. });
  90. });
  91. }
  92.  
  93. if(sites[hostname].background) {
  94. document.body.style.background = sites[hostname].background;
  95. document.body.style.overflow = 'scroll';
  96. document.body.style.position = 'static';
  97. }
  98.  
  99. if(sites[hostname].click) {
  100. let selectors = sites[hostname].click;
  101.  
  102. selectors.forEach(function(selector) {
  103. let element = document.querySelector(selector);
  104.  
  105. if(!!element) {
  106. element.click();
  107. }
  108. });
  109. }
  110.  
  111. if(sites[hostname].antiVignette && window.location.hash && window.location.hash == "#google_vignette") {
  112. window.location.href = window.location.href.split("#")[0]
  113. }
  114. }
  115.  
  116. if (!Object.keys(sites).indexOf(hostname) >= 0) {
  117. for (const site in sites) {
  118. const regex = new RegExp(site, "i");
  119. if(regex.test(hostname)) {
  120. hostname = site;
  121. }
  122. }
  123. }
  124.  
  125. if(Object.keys(sites).indexOf(hostname) >= 0) {
  126.  
  127. let timeout = 0;
  128. if(sites[hostname].timeout) {
  129. timeout = sites[hostname].timeout;
  130. }
  131.  
  132. window.setTimeout(function(){
  133. cleanup();
  134. }, timeout);
  135.  
  136. if(sites[hostname].interval && !interval) {
  137. interval = window.setInterval(function(){
  138. cleanup();
  139. }, sites[hostname].interval);
  140. }
  141.  
  142. if(sites[hostname].onChange && !loaded) {
  143. loaded = true;
  144. window.addEventListener('locationchange', function () {
  145. window.setTimeout(function(){
  146. cleanup();
  147. }, timeout);
  148. });
  149. }
  150. }
  151. })();

QingJ © 2025

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