网易邮箱去除广告

126、163和yeah邮箱去除顶部"应用中心"、"网易严选"和"半个电台",去除登陆页与首页广告

  1. // ==UserScript==
  2. // @name 网易邮箱去除广告
  3. // @namespace 126 Mail AdRemover
  4. // @version 2022.11.22.1
  5. // @description 126、163和yeah邮箱去除顶部"应用中心"、"网易严选"和"半个电台",去除登陆页与首页广告
  6. // @author PY-DNG
  7. // @license WTFPL http://www.wtfpl.net/about/
  8. // @icon https://mail.126.com/favicon.ico
  9. // @match http*://mail.126.com/js6/main.jsp*
  10. // @match http*://mail.163.com/js6/main.jsp*
  11. // @match http*://mail.yeah.net/js6/main.jsp*
  12. // @match http*://www.yeah.net/js6/main.jsp*
  13. // @match http*://mail.126.com/
  14. // @match http*://mail.163.com/
  15. // @match http*://mail.yeah.net/
  16. // @match http*://www.yeah.net/
  17. // @match http*://mail.126.com/index.htm*
  18. // @match http*://mail.163.com/index.htm*
  19. // @match http*://mail.yeah.net/index.htm*
  20. // @match http*://www.yeah.net/index.htm*
  21. // @match http*://mail.126.com/?*
  22. // @match http*://mail.163.com/?*
  23. // @match http*://mail.yeah.net/?*
  24. // @match http*://www.yeah.net/?*
  25. // @match http*://mail.126.com/#*
  26. // @match http*://mail.163.com/#*
  27. // @match http*://mail.yeah.net/#*
  28. // @match http*://www.yeah.net/#*
  29. // @match http*://hw.mail.126.com/js6/main.jsp*
  30. // @match http*://hw.mail.163.com/js6/main.jsp*
  31. // @match http*://hw.mail.yeah.net/js6/main.jsp*
  32. // @match http*://hw.www.yeah.net/js6/main.jsp*
  33. // @match http*://hw.mail.126.com/
  34. // @match http*://hw.mail.163.com/
  35. // @match http*://hw.mail.yeah.net/
  36. // @match http*://hw.www.yeah.net/
  37. // @match http*://hw.mail.126.com/index.htm*
  38. // @match http*://hw.mail.163.com/index.htm*
  39. // @match http*://hw.mail.yeah.net/index.htm*
  40. // @match http*://hw.www.yeah.net/index.htm*
  41. // @match http*://hw.mail.126.com/?*
  42. // @match http*://hw.mail.163.com/?*
  43. // @match http*://hw.mail.yeah.net/?*
  44. // @match http*://hw.www.yeah.net/?*
  45. // @match http*://hw.mail.126.com/#*
  46. // @match http*://hw.mail.163.com/#*
  47. // @match http*://hw.mail.yeah.net/#*
  48. // @match http*://hw.www.yeah.net/#*
  49. // @grant none
  50. // ==/UserScript==
  51.  
  52. (function () {
  53. // ==== ==== ==== 想要去除的标签页,直接写在这里就好 ==== ==== ====
  54. const AD_TABS = ['应用中心', '网易严选', '半个电台', '企业邮箱', '跨境收款'];
  55. // 后面的就不用改了
  56.  
  57. const NUMBER_STOP_FINDING_AFTER = 40;
  58. const NUMBER_LOG_WARNING_AFTER = 14;
  59. const NUMBER_TIMEOUT_RETRY_AFTER = 500;
  60.  
  61. const TEXT_TITLE_WINDOW_LOGIN = '{NAME} 邮箱登录(不可用)';
  62.  
  63. /** DoLog相关函数改自 Ocrosoft 的 Pixiv Previewer
  64. * [GitHub] Ocrosoft: https://github.com/Ocrosoft/
  65. * [GreasyFork] Ocrosoft: https://gf.qytechs.cn/zh-CN/users/63073
  66. * [GreasyFork] Pixiv Previewer: https://gf.qytechs.cn/zh-CN/scripts/30766
  67. * [GitHub] Pixiv Previewer: https://github.com/Ocrosoft/PixivPreviewer
  68. **/
  69. let LogLevel = {
  70. None: 0,
  71. Error: 1,
  72. Success: 2,
  73. Warning: 3,
  74. Info: 4,
  75. Elements: 5,
  76. };
  77. let g_logCount = 0;
  78. let g_logLevel = LogLevel.Warning;
  79.  
  80. function DoLog(level, msgOrElement) {
  81. if (level <= g_logLevel) {
  82. let prefix = '%c';
  83. let param = '';
  84.  
  85. if (level == LogLevel.Error) {
  86. prefix += '[Error]';
  87. param = 'color:#ff0000';
  88. } else if (level == LogLevel.Success) {
  89. prefix += '[Success]';
  90. param = 'color:#00aa00';
  91. } else if (level == LogLevel.Warning) {
  92. prefix += '[Warning]';
  93. param = 'color:#ffa500';
  94. } else if (level == LogLevel.Info) {
  95. prefix += '[Info]';
  96. param = 'color:#888888';
  97. } else if (level == LogLevel.Elements) {
  98. prefix += 'Elements';
  99. param = 'color:#000000';
  100. }
  101.  
  102. if (level != LogLevel.Elements) {
  103. console.log(prefix + msgOrElement, param);
  104. } else {
  105. console.log(msgOrElement);
  106. }
  107.  
  108. if (++g_logCount > 512) {
  109. console.clear();
  110. g_logCount = 0;
  111. }
  112. }
  113. }
  114.  
  115. // 去除登陆页面广告
  116. const loginPageMatch = location.href.match(/https?:\/\/(hw\.)?(mail|www)\.(126|163|yeah)\.(com|net)\/(index.htm)?(\?.*)?(#.*)?/);
  117. if (loginPageMatch && loginPageMatch[0] === location.href) {
  118. const domin = loginPageMatch[2];
  119. document.title = TEXT_TITLE_WINDOW_LOGIN.replaceAll('{NAME}', domin);
  120. DoLog(LogLevel.Info, 'This is ' + domin + ' login page. ');
  121.  
  122. // 去除广告图、广告标识和链接
  123. createEleRemoveFunction('#theme', 'adsMain', false)();
  124. // 去除广告翻页键
  125. createEleRemoveFunction('.themeCtrl', 'themeCtrl', true)();
  126. // 去除登陆窗口底部客户端链接
  127. //createEleRemoveFunction('#loginBlock>.mailApp', 'mailApp', false)();
  128.  
  129. // 登陆板块居中显示
  130. addStyle('html {overflow: hidden;}.main-login-wrap {z-index: 1;}#footer {z-index: 2;}.main-login-wrap {position: fixed;display:flex;align-items: center;justify-content: center;padding: 0;width: 100vw;height: 100vh;background-color: #CCCCCC;}#loginBlock {position: relative;background-color: #FFFFFF;padding: 20px;box-shadow: 5px 5px 5px #888888;border-radius: 4px;}.main-inner-wrap,.main-login-wrap,#loginBlock {border: 0;margin: 0;top: 0;right: 0;left: 0;bottom: 0;}');
  131. return;
  132. }
  133.  
  134. DoLog(LogLevel.Info, 'This is mail page. ');
  135.  
  136. // 去广函数
  137. let removeAds = function () {
  138. DoLog(LogLevel.Info, 'Searching for ads...');
  139. let advertisement = document.getElementsByClassName('js-component-tab gWel-recommend-title nui-tabs nui-tabs-common ')[0]
  140. if (advertisement) {
  141. DoLog(LogLevel.Success, 'Ads found. Remove it. ');
  142. advertisement.parentElement.parentElement.remove();
  143. return true;
  144. } else {
  145. DoLog(LogLevel.Info, 'No ads here. ');
  146. return false;
  147. }
  148. }
  149.  
  150. // 去除顶部"应用中心"、"网易严选"和"半个电台",挂接首页自动去广函数
  151. let p = document.querySelector('.js-component-tab[role="tablist"]'); //p - parentNote
  152. if (p) {
  153. let cs = p.children; //cs- childs:)
  154. let i, j = 0,
  155. note, targetNotes = new Array();
  156. for (i = 0; i < cs.length; i++) {
  157. if (AD_TABS.includes(cs[i].title)) {
  158. targetNotes[j] = cs[i];
  159. j += 1;
  160. }
  161. }
  162. targetNotes.forEach(function (item, index, array) {
  163. p.removeChild(item);
  164. })
  165. }
  166.  
  167. // 尝试现在就去除首页广告区域(如果在首页并且广告已经加载)
  168. removeAds();
  169.  
  170. // 循环执行去广函数
  171. setInterval(removeAds, '1000');
  172.  
  173. function createEleRemoveFunction(cssSelector, EleName='Unamed_Element', ignorable=false) {
  174. return (function func() {
  175. if (func.FindCount === undefined) {func.FindCount = 0;};
  176. if (func.Removed === undefined) {func.Removed = false;};
  177.  
  178. // 广告标识及广告链接
  179. if (!func.Removed) {
  180. const Element = document.querySelector(cssSelector);
  181. if (!Element) {
  182. func.FindCount++;
  183. if (func.FindCount >= NUMBER_STOP_FINDING_AFTER) {
  184. const level = ignorable ? LogLevel.Success : LogLevel.Error;
  185. const text = ignorable ?
  186. 'No ' + EleName + ' found here. ' :
  187. 'Cannot find ' + EleName + '. Stop finding now. Tried for ' + String(func.FindCount) + 'times. ';
  188. DoLog(level, text);
  189. func.Removed = true;
  190. } else {
  191. const level = func.FindCount >= NUMBER_LOG_WARNING_AFTER && !ignorable ? LogLevel.Warning : LogLevel.Info;
  192. const text = EleName + ' not loaded, keep waiting... Tried for ' + String(func.FindCount) + 'times. '
  193. DoLog(level, text);
  194. setTimeout(func, NUMBER_TIMEOUT_RETRY_AFTER);
  195. }
  196. } else {
  197. DoLog(LogLevel.Success, EleName + ' found, remove it.');
  198. Element.parentElement.removeChild(Element);
  199. func.Removed = true;
  200. }
  201. }
  202. })
  203. }
  204.  
  205. // Append a style text to document(<head>) with a <style> element
  206. function addStyle(css, id) {
  207. const style = document.createElement("style");
  208. id && (style.id = id);
  209. style.textContent = css;
  210. for (const elm of document.querySelectorAll('#'+id)) {
  211. elm.parentElement && elm.parentElement.removeChild(elm);
  212. }
  213. document.head.appendChild(style);
  214. }
  215. })()

QingJ © 2025

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