// ==UserScript== // @name Crunchyroll Quiz OneTrust Fix // @namespace https://git.ponywave.de/Akamaru/Userscripts // @version 1.0 // @description Zeigt einen Button zum Setzen der OneTrust-Cookies, wenn Crunchyroll News Quizzes durch Cookie-Blocker nicht angezeigt werden. // @author Akamaru // @match https://www.crunchyroll.com/news/quizzes/* // @match https://www.crunchyroll.com/*/news/quizzes/* // @icon https://www.google.com/s2/favicons?domain=crunchyroll.com&sz=32 // @grant none // @updateURL https://git.ponywave.de/Akamaru/Userscripts/raw/branch/master/crunchyroll-quiz-onetrust-fix.user.js // @downloadURL https://git.ponywave.de/Akamaru/Userscripts/raw/branch/master/crunchyroll-quiz-onetrust-fix.user.js // ==/UserScript== (function() { 'use strict'; console.log('[Crunchyroll Quiz Fix] Script loaded'); // Wartezeit bevor der Button angezeigt wird (in Millisekunden) const DETECTION_DELAY = 1000; // Placeholder-Text, der erscheint, wenn OneTrust blockiert wird const PLACEHOLDER_TEXT = 'This content is provided by third-party services'; // Funktion zum Setzen der OneTrust-Cookies function setOneTrustCookies() { const timestamp = new Date().toISOString(); const consentDate = encodeURIComponent(timestamp); // Generiere eine eindeutige Consent-ID const consentId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); // OneTrust Consent Cookie - alle Kategorien akzeptiert const optanonConsent = `isGpcEnabled=0&datestamp=${consentDate}&version=202409.1.0&browserGpcFlag=0&isIABGlobal=false&hosts=&consentId=${consentId}&interactionCount=1&landingPath=NotLandingPage&groups=C0001:1,C0002:1,C0003:1,C0004:1&AwaitingReconsent=false`; // Cookie-Ablaufdatum auf 1 Jahr setzen const expires = new Date(); expires.setFullYear(expires.getFullYear() + 1); // Cookies setzen document.cookie = `OptanonConsent=${optanonConsent}; path=/; domain=.crunchyroll.com; expires=${expires.toUTCString()}; SameSite=Lax`; document.cookie = `OptanonAlertBoxClosed=${timestamp}; path=/; domain=.crunchyroll.com; expires=${expires.toUTCString()}; SameSite=Lax`; console.log('[Crunchyroll Quiz Fix] OneTrust cookies set successfully'); } // Funktion zum Erstellen und Anzeigen des Buttons function showConsentButton(container) { console.log('[Crunchyroll Quiz Fix] Replacing placeholder with consent button'); // Erstelle den Button-Container mit Styling container.innerHTML = `

Quiz wird blockiert

Eine Browser-Extension oder dein Ad-Blocker
blockiert das benötigte Cookie-Consent-Script.

Klicke auf den Button, um die notwendigen Cookies zu setzen
und das Quiz zu laden.

Alternative: Deaktiviere Cookie-Blocker-Extensions
für diese Seite und lade sie neu.

`; // Button-Click-Handler const button = document.getElementById('cr-quiz-consent-btn'); if (button) { button.addEventListener('click', () => { console.log('[Crunchyroll Quiz Fix] User clicked consent button'); // Zeige Lade-Animation button.textContent = '⏳ Cookies werden gesetzt...'; button.disabled = true; button.style.opacity = '0.7'; button.style.cursor = 'wait'; // Setze Cookies setOneTrustCookies(); // Kurz warten, dann Seite neu laden setTimeout(() => { button.textContent = '✓ Seite wird neu geladen...'; setTimeout(() => { location.reload(); }, 500); }, 500); }); } } // Funktion zum Überprüfen und Ersetzen des Placeholders function checkAndReplacePlaceholder() { const riddleContainer = document.querySelector('.riddleembed_riddleembed__7dckr'); if (!riddleContainer) { console.log('[Crunchyroll Quiz Fix] No quiz container found on this page'); return; } // Prüfe, ob der Placeholder-Text vorhanden ist if (riddleContainer.textContent.includes(PLACEHOLDER_TEXT)) { console.log('[Crunchyroll Quiz Fix] Placeholder detected, showing consent button'); showConsentButton(riddleContainer); } else { console.log('[Crunchyroll Quiz Fix] Quiz loaded correctly or different content'); } } // Observer für dynamische Inhaltsänderungen function setupMutationObserver() { const observer = new MutationObserver(() => { checkAndReplacePlaceholder(); }); // Warte auf das Body-Element if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); console.log('[Crunchyroll Quiz Fix] MutationObserver started'); } } // Initialisierung function init() { // Warte kurz, damit die Seite laden kann setTimeout(() => { checkAndReplacePlaceholder(); setupMutationObserver(); }, DETECTION_DELAY); } // Starte das Script, wenn DOM bereit ist if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } console.log('[Crunchyroll Quiz Fix] Initialization complete'); })();