ruler / Cashback-Optimizer Popup mit Iframe (nach Klick, Whitelist)

// ==UserScript==
// @name         Cashback-Optimizer Popup mit Iframe (nach Klick, Whitelist)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Zeigt ein kleines Popup "💸 Cashback für {SHOPNAME} gefunden" und lädt nach Klick die gefilterte cashback-optimizer.de-Seite im Iframe im Popup (Whitelist)
// @author       Ruler
// @license MIT
// @match        *://*/*
// ==/UserScript==

(function() {
    'use strict';

    // Vollständige Whitelist: Domain (ohne www.) → Shopname für cashback-optimizer.de Filter
    const shopWhitelist = {
  "otto.de": "Otto",
  "otto-office.com": "Otto Office",
  "otto-gourmet.de": "Otto Gourmet",
  "amazon.de": "Amazon",
  "zalando.de": "Zalando",
  "mediamarkt.de": "Media Markt",
  "saturn.de": "Saturn",
  "ikea.com": "Ikea",
  "lidl.de": "Lidl",
  "aldi.de": "Aldi",
  "rewe.de": "Rewe",
  "dm.de": "dm",
  "rossmann.de": "Rossmann",
  "conrad.de": "Conrad",
  "cyberport.de": "Cyberport",
  "notebooksbilliger.de": "Notebooksbilliger",
  "galeria.de": "Galeria",
  "deichmann.com": "Deichmann",
  "bonprix.de": "Bonprix",
  "c-and-a.com": "C&A",
  "hse.de": "HSE",
  "thalia.de": "Thalia",
  "buecher.de": "Bücher.de",
  "mytoys.de": "myToys",
  "aboutyou.de": "About You",
  "sportscheck.com": "Sport Scheck",
  "decathlon.de": "Decathlon",
  "fressnapf.de": "Fressnapf",
  "zooplus.de": "Zooplus",
  "booking.com": "Booking.com",
  "expedia.de": "Expedia",
  "ebay.de": "Ebay",
  "aliexpress.com": "AliExpress",
  "shein.com": "SHEIN",
  "hunkemoller.de": "Hunkemöller",
  "snipes.com": "SNIPES",
  "snocks.com": "Snocks",
  "boohoo.com": "Boohoo",
  "boohooman.com": "BoohooMAN",
  "asos.com": "Asos",
  "hm.com": "H&M",
  "hm.com/home": "H&M Home",
  "zara.com": "Zara",
  "pullandbear.com": "Pull & Bear",
  "bershka.com": "Bershka",
  "stradivarius.com": "Stradivarius",
  "massimodutti.com": "Massimo Dutti",
  "uniqlo.com": "UNIQLO",
  "primark.com": "Primark",
  "jackjones.com": "Jack & Jones",
  "only.com": "Only",
  "veromoda.com": "Vero Moda",
  "s.oliver.com": "s.Oliver",
  "tom-tailor.eu": "Tom Tailor",
  "tommy.com": "Tommy Hilfiger",
  "levis.com": "Levis",
  "nike.com": "Nike",
  "adidas.de": "Adidas",
  "puma.com": "Puma",
  "reebok.de": "Reebok",
  "newbalance.de": "New Balance",
  "underarmour.de": "Under Armour",
  "footlocker.de": "Foot Locker",
  "jd-sports.de": "JD Sports",
  "depot-online.com": "Depot",
  "home24.de": "Home24",
  "wayfair.de": "Wayfair",
  "xxxlutz.de": "XXXLutz",
  "moemax.de": "mömax",
  "apple.com": "Apple",
  "samsung.com": "Samsung",
  "huawei.com": "Huawei",
  "lenovo.com": "Lenovo",
  "dell.com": "Dell",
  "hp.com": "HP",
  "acer.com": "Acer",
  "asus.com": "ASUS",
  "msi.com": "MSI",
  "bueromarkt-ag.de": "Bueromarkt AG",
  "buerostuhl24.com": "Buerostuhl24",
  "office-discount.de": "Office Discount",
  "office-partner.de": "Office Partner",
  "bestchoice-gutschein.de": "BestChoice",
  "wunschgutschein.de": "Wunschgutschein",
  "payback.de": "Payback",
  "deutschlandcard.de": "DeutschlandCard",
  "shoop.de": "Shoop",
  "igraal.de": "iGraal",
  "mycashbacks.de": "mycashbacks",
  "shopbuddies.de": "Shopbuddies",
  "shopmate.de": "Shopmate",
  "zave.it": "Zave.it",
  "web.cent.de": "WEB.Cent",
  "dealwise.de": "Dealwise (ING)",
  "topcashback.de": "TopCashback",
  "wondercashback.de": "Wondercashback",
  "benefit-buddy.de": "Benefit Buddy",
  "hanseatic-vorteilswelt.de": "Hanseatic Vorteilswelt",
  "o2priority.de": "O2 Priority",
  "mitarbeitervorteile.de": "Mitarbeitervorteile (MIVO)",
  "bsw.de": "BSW",
  "geschenkkartenwelt.de": "Geschenkkartenwelt.de",
  "gutscheingold.de": "Gutscheingold",
  "gutscheingold-b2b.de": "Gutscheingold B2B",
  "gutscheingold-beauty.de": "Gutscheingold Beauty",
  "gutscheingold-fashion.de": "Gutscheingold Fashion",
  "gutscheingold-grusskarten.de": "Gutscheingold Grußkarten",
  "gutscheingold-homeandgarden.de": "Gutscheingold Home&Garden",
  "gutscheingold-kids.de": "Gutscheingold Kids",
  "gutscheingold-mitarbeiter.de": "Gutscheingold Mitarbeiter",
  "marktkauf-kartenwelt.de": "Marktkauf Kartenwelt",
  "netto-kartenwelt.de": "Netto Kartenwelt",
  "penny-kartenwelt.de": "Penny Kartenwelt",
  "rewe-kartenwelt.de": "REWE Kartenwelt",
  "miles-and-more.de": "Miles & More",
  "corporate-benefits.de": "Corporate Benefits",
  "meinmagenta.de": "MeinMagenta",
  "samsungmembers.de": "Samsung Members",
  "studentbeans.com": "Studentbeans",
  "unidays.com": "Unidays",
  "primebenefits.de": "Prime Benefits",
  "incent.de": "Incent",
  "sovendus.com": "Sovendus",
  "allianz-vorteilswelt.de": "Allianz Vorteilswelt",
  "benefits.me": "benefits.me",
  "cadooz.com": "Cadooz",
  "cadooz.mydealz.de": "Cadooz (MyDealz)",
  "cadooz.sparwelt.de": "Cadooz (Sparwelt)"
}


    // Domains, auf denen das Popup nicht erscheinen soll
    const ignoreDomains = [
        'cashback-optimizer.de',
        'google.',
        'bing.',
        'yahoo.',
        'duckduckgo.',
        'facebook.',
        'twitter.',
        'instagram.',
        'youtube.',
        'tiktok.',
        'linkedin.',
        'wikipedia.',
        'amazonaws.com',
        'localhost',
        '127.0.0.1'
    ];

    function getDomain(hostname) {
        return hostname.replace(/^www\./, '').toLowerCase();
    }

    const host = window.location.hostname;
    const domain = getDomain(host);

    if (ignoreDomains.some(domainPart => host.includes(domainPart))) return;
    if (!(domain in shopWhitelist)) return;

    const shopName = shopWhitelist[domain];
    const filterUrl = `https://www.cashback-optimizer.de/?filter=${encodeURIComponent(shopName)}`;

    if (document.getElementById('cashback-optimizer-hinweis')) return;

    // CSS für das Popup
    const style = document.createElement('style');
    style.innerHTML = `
    #cashback-optimizer-hinweis {
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: #fffbe7;
        border-radius: 14px;
        box-shadow: 0 2px 12px 0 rgba(31,38,135,0.10);
        border: 1px solid #e0c200;
        z-index: 99999;
        font-family: 'Segoe UI', 'Arial', sans-serif;
        font-size: 15px;
        padding: 0;
        margin: 0;
        min-width: 0;
        max-width: 340px;
        display: flex;
        align-items: center;
        animation: cashback-fadein 0.3s;
        transition: max-width 0.3s, max-height 0.3s, width 0.3s, height 0.3s;
    }
    #cashback-optimizer-hinweis.expanded {
        max-width: 900px !important;
        max-height: 90vh !important;
        min-width: 400px !important;
        min-height: 400px !important;
        width: 70vw !important;
        height: 70vh !important;
        background: #fff;
        flex-direction: column;
        align-items: stretch;
    }
    @keyframes cashback-fadein {
        from { opacity: 0; transform: translateY(20px);}
        to   { opacity: 1; transform: translateY(0);}
    }
    #cashback-optimizer-link {
        display: block;
        padding: 8px 16px 8px 16px;
        color: #b1a100;
        text-decoration: underline;
        font-weight: 600;
        border-radius: 14px;
        transition: text-decoration 0.15s, color 0.15s;
        cursor: pointer;
        white-space: nowrap;
        background: none;
    }
    #cashback-optimizer-link:hover {
        text-decoration: underline;
        color: #7a6700;
        background: none;
    }
    #cashback-optimizer-close {
        margin-left: 2px;
        margin-right: 8px;
        cursor: pointer;
        font-size: 1.2em;
        color: #b1a100;
        background: none;
        border: none;
        border-radius: 50%;
        width: 24px;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.15s;
    }
    #cashback-optimizer-close:hover {
        background: #ffe066;
        color: #fff;
    }
    #cashback-optimizer-iframe {
        display: none;
        width: 100%;
        height: 100%;
        border: none;
        flex: 1 1 auto;
        min-height: 400px;
        background: #fff;
    }
    #cashback-optimizer-hinweis.expanded #cashback-optimizer-iframe {
        display: block;
    }
    #cashback-optimizer-hinweis.expanded #cashback-optimizer-link {
        display: none;
    }
    `;
    document.head.appendChild(style);

    // Popup-HTML
    const div = document.createElement('div');
    div.id = 'cashback-optimizer-hinweis';
    div.innerHTML = `
        <a id="cashback-optimizer-link" href="#" title="Cashback anzeigen">
            💸 Cashback für ${shopName} gefunden
        </a>
        <button id="cashback-optimizer-close" title="Schließen" aria-label="Schließen">&times;</button>
        <iframe id="cashback-optimizer-iframe" src="" allowfullscreen></iframe>
    `;
    div.querySelector('#cashback-optimizer-close').onclick = function() {
        div.remove();
    };
    div.querySelector('#cashback-optimizer-link').onclick = function(e) {
        e.preventDefault();
        div.classList.add('expanded');
        div.querySelector('#cashback-optimizer-iframe').src = filterUrl;
    };
    document.body.appendChild(div);
})();