您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Lädt alle Seiten, expandiert Antworten und exportiert Kommentare mit Fortschrittsanzeige in Prozent
当前为
// ==UserScript== // @name MyDealz | Kommentar-Export über alle Seiten // @namespace violentmonkey // @version 1.1 // @description Lädt alle Seiten, expandiert Antworten und exportiert Kommentare mit Fortschrittsanzeige in Prozent // @match https://www.mydealz.de/deals/* // @match https://www.mydealz.de/diskussion/* // @match https://www.mydealz.de/gutscheine/* // @icon https://www.mydealz.de/assets/img/emojis/cool_b7b27.svg // @grant none // ==/UserScript== (function () { 'use strict'; const REPLY_BTN_SELECTOR = 'button[data-t="moreReplies"]:not([disabled])'; const NEXT_PAGE_SELECTOR = 'button[aria-label="Nächste Seite"]:not([disabled])'; const CURRENT_PAGE_SELECTOR = 'button[aria-label="Aktuelle Seite"]'; const LAST_PAGE_SELECTOR = 'button[aria-label="Letzte Seite"]'; const CHECK_INTERVAL = 500; const CLICK_DELAY = 200; const PAGE_DELAY = 2000; let collectedTexts = []; let totalComments = 0; let exportButton = null; async function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } function getCurrentPage() { const current = document.querySelector(CURRENT_PAGE_SELECTOR); if (!current) return null; const text = current.textContent.match(/\d+/); return text ? parseInt(text[0], 10) : null; } function getLastPage() { const last = document.querySelector(LAST_PAGE_SELECTOR); if (!last) return null; const text = last.textContent.match(/\d+/); return text ? parseInt(text[0], 10) : null; } function getTotalCommentCount() { const commentLink = document.querySelector('a[href*="#comments"]'); if (!commentLink) return 0; const text = commentLink.textContent.match(/\d+/); return text ? parseInt(text[0], 10) : 0; } async function expandAllReplies() { let checks = 0; while (checks < 5) { const btn = document.querySelector(REPLY_BTN_SELECTOR); if (btn && btn.offsetParent !== null) { btn.click(); checks = 0; await sleep(CLICK_DELAY); } else { checks++; await sleep(CHECK_INTERVAL); } } } function collectCommentBodies() { const nodes = document.querySelectorAll('.comment-body .userHtml-content'); const texts = Array.from(nodes).map(el => el.textContent.trim().replace(/\s+/g, ' ') ); collectedTexts.push(...texts); // Fortschritt anzeigen if (totalComments > 0 && exportButton) { const percent = Math.min(100, Math.round((collectedTexts.length / totalComments) * 100)); exportButton.textContent = `💬 ${percent}% geladen…`; } } async function goToNextPage() { const btn = document.querySelector(NEXT_PAGE_SELECTOR); if (btn) { btn.click(); await sleep(PAGE_DELAY); } } function openExportWindow(text) { const w = window.open('', '_blank', 'width=800,height=600'); if (!w) return alert('Popup blockiert'); w.document.title = 'MyDealz Kommentar-Export'; w.document.head.innerHTML = ` <style> body { font-family: sans-serif; margin: 20px; } #copyBtn { display: inline-flex; align-items: center; padding: 10px 16px; background: #d32f2f; color: #fff; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; margin-bottom: 12px; } #copyBtn:active { background: #b71c1c; } #copiedMsg { display: inline-block; margin-left: 12px; color: #4caf50; font-weight: bold; opacity: 0; transition: opacity 0.3s; } pre { white-space: pre-wrap; word-wrap: break-word; border: 1px solid #ccc; padding: 12px; border-radius: 4px; max-height: 80vh; overflow: auto; } </style> `; w.document.body.innerHTML = ` <button id="copyBtn" title="In Zwischenablage kopieren"> 📋 Copy All </button> <span id="copiedMsg">Copied!</span> <pre id="exportText"></pre> `; const pre = w.document.getElementById('exportText'); pre.textContent = text; const btn = w.document.getElementById('copyBtn'); const msg = w.document.getElementById('copiedMsg'); btn.addEventListener('click', () => { w.navigator.clipboard.writeText(text).then(() => { msg.style.opacity = '1'; setTimeout(() => { msg.style.opacity = '0'; }, 2000); }); }); } async function runFullExport() { totalComments = getTotalCommentCount(); console.log(`📊 Kommentar-Gesamtzahl: ${totalComments}`); while (true) { console.log(`🛠️ Seite ${getCurrentPage()} wird bearbeitet...`); await expandAllReplies(); collectCommentBodies(); const current = getCurrentPage(); const last = getLastPage(); if (current === null || last === null || current >= last) break; await goToNextPage(); } const fullText = collectedTexts.join('\n\n'); openExportWindow(fullText); } function injectStartButton() { exportButton = document.createElement('button'); exportButton.textContent = '💬 Kommentare exportieren'; Object.assign(exportButton.style, { position: 'fixed', top: '20px', right: '20px', padding: '10px 16px', background: '#d32f2f', color: '#fff', border: 'none', borderRadius: '4px', fontSize: '14px', cursor: 'pointer', zIndex: '9999' }); exportButton.addEventListener('click', () => { exportButton.disabled = true; exportButton.textContent = '⏳ Läuft…'; runFullExport().then(() => { exportButton.textContent = '✅ Fertig!'; }); }); document.body.appendChild(exportButton); } function ensureStartOnPageOne() { const url = new URL(window.location.href); const isCommentPage = url.hash.includes('#comments'); const pageParam = url.searchParams.get('page'); if ((pageParam && pageParam !== '1') || !isCommentPage) { url.searchParams.set('page', '1'); url.hash = '#comments'; window.location.href = url.toString(); } else { injectStartButton(); } } if (document.readyState === 'complete') { ensureStartOnPageOne(); } else { window.addEventListener('load', ensureStartOnPageOne); } })();