ChatGPT Mail 去广告优化

隐藏 mail.chatgpt.org.uk 上的广告区域(header、google-auto-placed、grippy-host、aswift_3_host、aswift_4_host)

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ChatGPT Mail 去广告优化
// @namespace    https://mail.chatgpt.org.uk/
// @version      1.0.0
// @description  隐藏 mail.chatgpt.org.uk 上的广告区域(header、google-auto-placed、grippy-host、aswift_3_host、aswift_4_host)
// @author       h7ml<[email protected]>
// @match        https://mail.chatgpt.org.uk/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 所有需要隐藏的元素选择器
    const selectors = [
        'div.header',
        'div.google-auto-placed',
        'div.grippy-host',
        '#aswift_3_host',
        '#aswift_4_host'
    ];

    // 隐藏函数
    function hideAds() {
        selectors.forEach(sel => {
            document.querySelectorAll(sel).forEach(el => {
                el.style.display = 'none';
                el.style.visibility = 'hidden';
                el.style.height = '0';
                el.style.margin = '0';
                el.style.padding = '0';
            });
        });
    }

    // 初次执行
    hideAds();

    // 监听页面变化(广告异步加载时也能屏蔽)
    const observer = new MutationObserver(() => hideAds());
    observer.observe(document.body, { childList: true, subtree: true });
})();