// ==UserScript== // @name Mydealz Comment-Preview // @namespace https://mydealz.de/ // @version 1.1.2 // @description Zeigt verlinkte Kommentare beim Klick in einem Popup an // @match https://www.mydealz.de/* // @license MIT // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Popup erstellen const popup = document.createElement('div'); popup.id = 'commentPopup'; popup.style.position = 'fixed'; popup.style.backgroundColor = '#fff'; popup.style.padding = '12px'; popup.style.border = '1px solid #ccc'; popup.style.borderRadius = '6px'; popup.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)'; popup.style.zIndex = '999999'; popup.style.maxWidth = '600px'; popup.style.maxHeight = '400px'; popup.style.overflow = 'auto'; popup.style.display = 'none'; document.body.appendChild(popup); // GraphQL-Abfrage für einen Kommentar async function fetchSingleComment(commentId) { const query = ` query comment($id: ID!) { comment(id: $id) { preparedHtmlContent createdAtTs user { userId username } } } `; const variables = { id: commentId }; const response = await fetch('https://www.mydealz.de/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ query, variables }) }); const data = await response.json(); if (data.errors) { throw new Error(data.errors[0].message); } return data?.data?.comment; } // Click-Handler für Links async function onLinkClick(event) { const link = event.target.closest('a'); if (!link) return; if (!link.closest('.commentList')) return; const fullUrl = link.title || link.href; // Verbesserte RegEx zur Erkennung von Kommentar- und Antwort-Links const commentMatch = fullUrl.match(/(?:\/deals\/|\/diskussion\/|\/feedback\/)(?:.*?-)?(\d+)(?:#comment-|#reply-)(\d+)/i); if (!commentMatch) return; event.preventDefault(); const dealId = commentMatch[1]; const commentId = commentMatch[2]; try { popup.style.display = 'block'; popup.style.left = (event.clientX + 15) + 'px'; popup.style.top = (event.clientY + 15) + 'px'; popup.innerHTML = 'Lade Kommentar...'; const commentData = await fetchSingleComment(commentId); if (!commentData) { popup.innerHTML = 'Kommentar nicht gefunden'; return; } const commentDate = new Date(commentData.createdAtTs * 1000).toLocaleString('de-DE', { year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' }).replace(',', ''); popup.innerHTML = `
@${commentData.user.username} (${commentDate}):
${commentData.preparedHtmlContent}
`; } catch (e) { console.error(e); popup.innerHTML = 'Fehler beim Laden'; } } // Event-Listener für Klicks document.addEventListener('click', onLinkClick); // Popup schließen wenn außerhalb geklickt wird document.addEventListener('click', (event) => { if (!popup.contains(event.target) && event.target.tagName !== 'A') { popup.style.display = 'none'; } }); })();