Clean CNN

Minimizes distractions in favor of trending top news only.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name            Clean CNN
// @description     Minimizes distractions in favor of trending top news only.
// @version         0.7
// @namespace       https://github.com/sm18lr88
// @match           *://www.cnn.com/*
// @run-at          document-start
// @grant           none
// @license         MIT
// ==/UserScript==

(function () {
  'use strict';

  const zoneSelectors = Array.from({ length: 20 }, (_, i) => [
    `.zone-${i + 3}-observer.zone--t-light.zone`,
    `.zone-${i + 3}-observer.zone--t-dark.zone`,
    `.product-zone-${i + 3}-observer.product-zone--t-light.product-zone`,
    `.product-zone-${i + 3}-observer.product-zone--t-dark.product-zone`
  ]).flat();

  const additionalSelectors = [
    '.header__wrapper-outer',
    '.layout-homepage__bottom.layout__bottom',
    '.social-share',
    '.container_list-headlines-with-images.container',
    '.video-resource > .ad-feedback-link-container',
    '.layout-with-rail__rail.layout__rail',
    '.layout-with-rail__bottom.layout__bottom',
    '.layout-no-rail__bottom.layout__bottom',
    '.product-zone--t-light.product-zone',
    ...Array.from({ length: 10 }, (_, i) => `div.related-content--article.related-content:nth-of-type(${i + 1})`),
  ];

  const allSelectors = [
    ...zoneSelectors,
    ...additionalSelectors,
  ];

  function removeElements() {
    allSelectors.forEach(selector => {
      const elements = document.querySelectorAll(selector);
      elements.forEach(element => element.remove());
    });
  }

  // Observe changes in the document body
  const observer = new MutationObserver(removeElements);
  window.addEventListener('DOMContentLoaded', () => {
    observer.observe(document.body, { childList: true, subtree: true });
    removeElements();
  });
})();