Domain‑specific CSS Injector

Inject custom CSS per domain – works on iOS, iPadOS and desktop browsers.

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         Domain‑specific CSS Injector
// @namespace    https://example.com/
// @version      1.0
// @description  Inject custom CSS per domain – works on iOS, iPadOS and desktop browsers.
// @author       Nick Bakaka
// @match        *://*/*                     // Apply to every page
// @grant        none
// @license      CC-ND-NA
// ==/UserScript==

(function () {
    'use strict';

    /* ------------------------------------------------------------------
     *  Configuration: Add your domain‑specific CSS here.
     *
     *  The key is a regular expression that matches the hostname of the
     *  target website.  The value is one or more CSS rules separated by newlines.
     *  You may use `@media`, `!important` etc. as you wish.
     * ------------------------------------------------------------------ */
    const domainCssMap = [
        {
            // Matches example.com and any sub‑domain
            hostRegex: /^(?:www\.)?example\.com$/i,
            css: `
                body { background-color: #f0f8ff !important; }
                h1, h2, h3 { color: #0044cc !important; }
            `
        },
        {
            // Matches any sub‑domain of mysite.org
            hostRegex: /^(?:.*\.)?mysite\.org$/i,
            css: `
                .navbar { display:none !important; }
                footer { font-size: 0.8rem !important; }
            `
        },
        {
            // Matches any site that contains "blog" in the hostname
            hostRegex: /blog/i,
            css: `
                .post-content img { max-width:100% !important; height:auto !important; }
            `
        }
        // Add more entries as needed...
    ];

    /* ------------------------------------------------------------------
     *  Helper: Inject a style element into the document head.
     * ------------------------------------------------------------------ */
    function injectCss(cssText) {
        if (!cssText.trim()) return;
        const style = document.createElement('style');
        style.type = 'text/css';
        style.textContent = cssText;
        // Append to <head> or <html> if head is missing
        (document.head || document.documentElement).appendChild(style);
    }

    /* ------------------------------------------------------------------
     *  Main logic: Find matching rule for current hostname and inject CSS.
     * ------------------------------------------------------------------ */
    const hostname = window.location.hostname;

    for (const { hostRegex, css } of domainCssMap) {
        if (hostRegex.test(hostname)) {
            // If multiple rules match we inject all of them
            injectCss(css);
        }
    }

})();