您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
126、163和yeah邮箱去除顶部"应用中心"、"网易严选"和"半个电台",去除登陆页与首页广告
当前为
// ==UserScript== // @name 网易邮箱去除广告 // @namespace 126 Mail AdRemover // @version 2021.04.24.1 // @description 126、163和yeah邮箱去除顶部"应用中心"、"网易严选"和"半个电台",去除登陆页与首页广告 // @author PY-DNG // @icon https://mail.126.com/favicon.ico // @include http*://mail.126.com/js6/main.jsp* // @include http*://mail.163.com/js6/main.jsp* // @include http*://mail.yeah.net/js6/main.jsp* // @include http*://mail.126.com/ // @include http*://mail.163.com/ // @include http*://mail.yeah.net/ // @include http*://mail.126.com/index.htm* // @include http*://mail.163.com/index.htm* // @include http*://mail.yeah.net/index.htm* // @include http*://mail.126.com/?* // @include http*://mail.163.com/?* // @include http*://mail.yeah.net/?* // @include http*://mail.126.com/#* // @include http*://mail.163.com/#* // @include http*://mail.yeah.net/#* // @grant none // ==/UserScript== (function () { const NUMBER_STOP_FINDING_AFTER = 40; const NUMBER_LOG_WARNING_AFTER = 14; const NUMBER_TIMEOUT_RETRY_AFTER = 500; /** DoLog相关函数改自 Ocrosoft 的 Pixiv Previewer * [GitHub] Ocrosoft: https://github.com/Ocrosoft/ * [GreasyFork] Ocrosoft: http://greasyfork.icu/zh-CN/users/63073 * [GreasyFork] Pixiv Previewer: http://greasyfork.icu/zh-CN/scripts/30766 * [GitHub] Pixiv Previewer: https://github.com/Ocrosoft/PixivPreviewer **/ let LogLevel = { None: 0, Error: 1, Warning: 2, Success: 3, Info: 4, Elements: 5, }; let g_logCount = 0; let g_logLevel = LogLevel.Success; function DoLog(level, msgOrElement) { if (level <= g_logLevel) { let prefix = '%c'; let param = ''; if (level == LogLevel.Error) { prefix += '[Error]'; param = 'color:#ff0000'; } else if (level == LogLevel.Warning) { prefix += '[Warning]'; param = 'color:#ffa500'; } else if (level == LogLevel.Success) { prefix += '[Success]'; param = 'color:#00aa00'; } else if (level == LogLevel.Info) { prefix += '[Info]'; param = 'color:#888888'; } else if (level == LogLevel.Elements) { prefix += 'Elements'; param = 'color:#000000'; } if (level != LogLevel.Elements) { console.log(prefix + msgOrElement, param); } else { console.log(msgOrElement); } if (++g_logCount > 512) { console.clear(); g_logCount = 0; } } } // 去除登陆页面广告 const loginPageMatch = location.href.match(/https?:\/\/mail\.(126|163|yeah)\.(com|net)\/(index.htm)?(\?.*)?(#.*)?/); if (loginPageMatch && loginPageMatch[0] === location.href) { DoLog(LogLevel.Info, 'This is ' + loginPageMatch[1] + ' login page. '); // 去除广告图 createEleRemoveFunction('#theme>.mailgg>.theme-item', 'adsMain')(); // 去除广告标识和链接 createEleRemoveFunction('#theme>.mailgg>.theme-item>.theme-item-inner', 'adtaglink')(); // 去除广告翻页键 createEleRemoveFunction('.themeCtrl', 'themeCtrl')(); // 去除登陆窗口底部客户端链接 createEleRemoveFunction('#loginBlock>.mailApp', 'mailApp')(); // 登陆板块居中显示 let loginBlock = document.querySelector('#loginBlock'); loginBlock.parentElement.style.position = 'static'; loginBlock.style.height = 'auto'; (function loginBlockCenter() { window.addEventListener('resize', loginBlockCenter); const availWidth = Number(getComputedStyle(document.lastChild).width.replace('px', '')); const blockWidth = Number(getComputedStyle(loginBlock).width.replaceAll('px', '')); loginBlock.style.left = String(Math.round((availWidth - blockWidth) / 2)) + 'px'; }) () return; } DoLog(LogLevel.Info, 'This is mail page. '); // 去广函数 let removeAds = function () { DoLog(LogLevel.Info, 'Searching for ads...'); let advertisement = document.getElementsByClassName('js-component-tab gWel-recommend-title nui-tabs nui-tabs-common ')[0] if (advertisement) { DoLog(LogLevel.Success, 'Ads found. Remove it. '); advertisement.parentElement.parentElement.remove(); return true; } else { DoLog(LogLevel.Info, 'No ads here. '); return false; } } // 去除顶部"应用中心"、"网易严选"和"半个电台",挂接首页自动去广函数 let p = document.querySelector('.js-component-tab[role="tablist"]'); //p - parentNote if (p) { let cs = p.children; //cs- childs:) let i, j = 0, note, targetNotes = new Array(); for (i = 0; i < cs.length; i++) { if (cs[i].title === '应用中心' || cs[i].title === '网易严选' || cs[i].title === '半个电台') { targetNotes[j] = cs[i]; j += 1; } } targetNotes.forEach(function (item, index, array) { p.removeChild(item); }) } // 尝试现在就去除首页广告区域(如果在首页并且广告已经加载) removeAds(); // 循环执行去广函数 setInterval(removeAds, '1000'); function createEleRemoveFunction(cssSelector, EleName='Unamed_Elemnt') { return (function func() { if (func.FindCount === undefined) {func.FindCount = 0;}; if (func.Removed === undefined) {func.Removed = false;}; // 广告标识及广告链接 if (!func.Removed) { const Element = document.querySelector(cssSelector); if (!Element) { func.FindCount++; if (func.FindCount > NUMBER_STOP_FINDING_AFTER) { DoLog(LogLevel.Error, 'Cannot find ' + EleName + '. Stop finding now. Tried for ' + String(func.FindCount) + 'times. '); func.Removed = true; } else { DoLog(func.FindCount > NUMBER_LOG_WARNING_AFTER ? LogLevel.Warning : LogLevel.Info, 'adtaglink not loaded, keep waiting... Tried for ' + String(func.FindCount) + 'times. '); setTimeout(func, NUMBER_TIMEOUT_RETRY_AFTER); } } else { DoLog(LogLevel.Success, EleName + ' found, remove it.'); Element.parentElement.removeChild(Element); func.Removed = true; } } }) } })()