rep-dark-mode

Forces dark mode on Repubblica.it

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!)

Advertisement:

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!)

Advertisement:

// ==UserScript==
// @name         rep-dark-mode
// @namespace    http://tampermonkey.net/
// @version      2025-03-20
// @description  Forces dark mode on Repubblica.it
// @author       You
// @include      *://*.repubblica.it*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=repubblica.it
// @grant        none
// @license      GPL-3.0-or-later
// ==/UserScript==

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

// addGlobalStyle('#page { background: #000 !important; }');
addGlobalStyle('.gd-row,body { background-color: rgb(0,0,0); }');
addGlobalStyle('.rep-slim-header { background-color: rgb(0,0,0); }');
addGlobalStyle('.page-header { background-color: rgb(0,0,0); }');
addGlobalStyle('.page-header__bottom .hot-topics { background-color: rgb(0,0,0); }');
addGlobalStyle('.entry__title { color: rgb(255,255,255); }');
addGlobalStyle('.rep-slim-header { color: rgb(255,255,255); }');
addGlobalStyle('.main-navigation__tab { color: rgb(255,255,255); }');
addGlobalStyle('.hot-topics__list li a { color: rgb(255,255,255); }');
addGlobalStyle('.block__overtitle { color: rgb(255,255,255); }');
addGlobalStyle('.story__title { color: white; }');
addGlobalStyle('.story__author { color: white; }');
addGlobalStyle('.story__summary { color: white; }');
addGlobalStyle('.story__text { color: white; }');
addGlobalStyle('.story__date { color: white; }');
addGlobalStyle('.aside-stories { color: white; }');
addGlobalStyle('.liveblog__post__content { background-color: #262626; }');
addGlobalStyle('.liveblog__index { background-color: #262626; }');
addGlobalStyle('.rep-page-header { background-color: rgb(0,0,0); }');
addGlobalStyle('.rep-page-header-nav { background-color: rgb(0,0,0); }');
addGlobalStyle('.rep-page-header__social-follow span { color: white; }');
addGlobalStyle('.rep-page-header-nav__list > li > a { color: white; }');
addGlobalStyle('.rep-page-header__brand-logo { color: white; }');
addGlobalStyle('.main-content { color: white; }');
addGlobalStyle('.block.is-postit:not(.block__layout-O-12):not(.block__layout-D-12) { border-image: conic-gradient(#262626 0 0) 0/0/0 var(--column-gap); }');
addGlobalStyle('.block.is-soft-news:not(.block__layout-O-12):not(.block__layout-D-12) { border-image: conic-gradient(#262626 0 0) 0/0/0 var(--column-gap); }');


document.querySelectorAll('img[src$="logo-repubblica.svg"]').forEach(img => {
        fetch(img.src)
            .then(response => response.text())
            .then(svgText => {
                let parser = new DOMParser();
                let svgDoc = parser.parseFromString(svgText, "image/svg+xml");
                let svgElement = svgDoc.documentElement;

                // Modify the fill color
                svgElement.setAttribute("fill", "white");
             // svgElement.setAttribute("stroke", "grey");

                // Replace <img> with the new inline SVG
                svgElement.style.width = img.width + "px";
                svgElement.style.height = img.height + "px";
                img.replaceWith(svgElement);
            })
            .catch(error => console.error("Error loading SVG:", error));
    });