The Guardian Cleaner

Cleans The Guardian of any distractions, ads, and nags

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         The Guardian Cleaner
// @description  Cleans The Guardian of any distractions, ads, and nags
// @license      MIT
// @namespace    http://tampermonkey.net/
// @version      2025-12-26_04
// @match        https://www.theguardian.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=theguardian.com
// @grant        none
// @run-at       document-start
// ==/UserScript==

(() => {
  'use strict';

  // Remove nags, thank you to "The Guardian Nag Nullifier" for the idea
  let raf = 0;
  const zap = () => {
    raf = 0;
    document.querySelector('[id^="sp_message_container_"]')?.remove();
    document.querySelector('#sign-in-gate')?.remove();
    document.documentElement.classList.remove('sp-message-open');
  };
  const schedule = () => raf || (raf = requestAnimationFrame(zap));

  new MutationObserver(schedule).observe(document, { childList: true, subtree: true });
  schedule();

  // Custom CSS (inject once)
  if (!document.getElementById('tm-guardian-clean')) {
    const style = document.createElement('style');
    style.id = 'tm-guardian-clean';
    style.textContent = `
/* Hide anything that isn't news related */
#trending-topics,
[data-spacefinder-type="model.dotcomrendering.pageElements.GuideAtomBlockElement"],
[name=GuideAtomWrapper],
[name="CommentCount"],
aside:has(div#comments),
[name=ShareButton],
section:has([data-link-name="keywords"]),
[name=SubNav],
[href="/email-newsletters"],
[data-gu-name="body"] [data-print-layout="hide"],
[data-gu-name="body"] svg[stroke="var(--straight-lines)"],
[name=SlotBodyEnd],
[name=FooterReaderRevenueLinks],
#slot-body-end,
[name=EmailSignUpWrapper],
.ad-slot-container,
.top-fronts-banner-ad-container,
[name=ScrollableHighlights],
[data-testid=contributions-liveblog-epic],
[name=LiveblogGutterAskWrapper],
div:has(> [data-link-name*=newsletter]),
footer,
#secure-messaging,
[name=StickyBottomBanner] { display: none !important; }

/* Hide all but the my account button at the top */
[name=TopBar] > div > div { height: 1em !important; }
[name=TopBar] > div > div > :not(:last-child) { display: none !important; }
[name=TopBar] > div > div > :last-child::before { border: 0 !important; }
[name=TopBar] > div > div > :last-child svg { display: none !important; }
[name=TopBar] > div > div > :last-child button { font-size: xx-small !important; }
`.trim();

    (document.head || document.documentElement).appendChild(style);
  }
})();