Hide Outlook ads

Hide embedded ads in Outlook

< Feedback on Hide Outlook ads

Question/comment

Deleted user 127
§
Posted: 2018-10-06
Edited: 2018-10-06

可以去除jQuery依赖

// ==UserScript==
// @name              Hide Outlook ads
// @name:zh-CN        隐藏Outlook广告
// @namespace         https://greasyfork.org/zh-CN/users/42351
// @version           1.2
// @description       Hide embedded ads in Outlook
// @description:zh-CN 隐藏Outlook网页端的各种内嵌广告
// @author            Antecer
// @match             https://outlook.live.com/*
// @grant             none
// @run-at            document-start
// @compatible        chrome 测试通过
// @compatible        firefox 未测试
// @compatible        opera 未测试
// @compatible        safari 未测试
// ==/UserScript==

const addStyle = (css) => {
    const node = document.createElement('style');
    node.type = 'text/css';
    node.appendChild(document.createTextNode(css));
    const heads = document.getElementsByTagName('head');
    if (heads.length > 0) {
        heads[0].appendChild(node);
    } else { // no head yet, stick it whereever
        document.documentElement.appendChild(node);
    }
}
// outlook标准版广告屏蔽css
const cssNomal = `
    ._n_h,
    ._n_15,
    div[style*="height: 40px"][style*="bottom: 0px"],
    [role=listbox]>div>div>div>[style] {
        display: none !important;
    }
    #primaryContainer > div {right: 0px !important; bottom:0 !important;}
    ._n_05 {bottom: 40px !important;}
    div[style*="top: 40px"] > div > div { bottom:0 !important;}`;
// outlook测试版广告屏蔽css
const cssBeta = `
    #app>div>div:last-child>div>div:first-child>div:last-child,
    #app>div>div:last-child>div>div>div:first-child>div>div:last-child>:last-child,
    div[role=listbox]>div>div>div:first-child,
    #app>div>div:last-child>div>div:last-child
    {display: none !important;}`;
// 执行css规则
if (document.querySelectorAll('img').length > 0) {
  addStyle(cssNomal);
}
else {
  addStyle(cssBeta);
}

比较粗暴,没做版本区分。

AntecerAuthor
§
Posted: 2018-10-06

太暴力了,outlook普通模式下把收件箱也给隐藏了。

Deleted user 127
§
Posted: 2018-10-06

@Antecer 说道: 太暴力了,outlook普通模式下把收件箱也给隐藏了。

大概是我用的beta版? 只是懒得看判断逻辑罢了……

Deleted user 127
§
Posted: 2018-10-06

@Antecer 说道: 太暴力了,outlook普通模式下把收件箱也给隐藏了。

更新了下,加入了版本判断——虽然不明白beta版怎么会没有图片的——至少我的版本上是没问题了。 判断的时候测了下,貌似我是nomal版?反正我没有切换按钮。

Deleted user 127
§
Posted: 2018-10-06

@Antecer 说道: 太暴力了,outlook普通模式下把收件箱也给隐藏了。

找了个备用账号还是nomal模式的,没有干掉收件箱啊。 按说我就是改了下css的字符串拼接方式用了ES6,不会干掉新东西。 倒是能不能把beta的推广干掉:

AntecerAuthor
§
Posted: 2018-10-06

@ffwymjbn 说道:

@Antecer 说道: 太暴力了,outlook普通模式下把收件箱也给隐藏了。

找了个备用账号还是nomal模式的,没有干掉收件箱啊。 按说我就是改了下css的字符串拼接方式用了ES6,不会干掉新东西。 倒是能不能把beta的推广干掉:

我这里看不到这个东西,奇怪。

AntecerAuthor
§
Posted: 2018-10-06

你可以尝试找到它的html节点,然后把css选择器添加上。

AntecerAuthor
§
Posted: 2018-10-06

使用join是为了增减规则和添加注释比较方便。

Deleted user 127
§
Posted: 2018-10-06

@Antecer 说道: 使用join是为了增减规则和添加注释比较方便。

我把注释删了只是测试的时候偷懒,当然你要说 // 比 /* */ 方便也没错。 ES6 好理解,个人觉得好维护点,但这不是问题~ thanks

Post reply

Sign in to post a reply.