此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.cloud/scripts/528796/1560680/MyDealz%20Comment%20Viewer%20%28GraphQL%29.js
您需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
您需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
您需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
您需要先安装一款用户样式管理器扩展后才能安装此样式。
您需要先安装一款用户样式管理器扩展后才能安装此样式。
您需要先安装一款用户样式管理器扩展后才能安装此样式。
(我已经安装了用户样式管理器,让我安装!)
// ==UserScript==
// @name MyDealz Comment Viewer (GraphQL)
// @namespace http://tampermonkey.net/
// @version 2.0
// @description Zeigt die letzten Kommentare eines Benutzers an
// @author MD928835
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// Globale Funktion definieren
window.viewUserComments = async function(username) {
// Funktion zum Abrufen des Dealtitels über GraphQL
async function fetchDealTitle(threadId) {
const query = `
query getThread($filter: IDFilter!) {
thread(threadId: $filter) {
title
}
}`;
try {
const response = await fetch("https://www.mydealz.de/graphql", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query,
variables: { filter: { eq: threadId } }
})
});
const result = await response.json();
if (result.errors) {
console.error("Fehler bei der GraphQL-Abfrage:", result.errors);
return null;
}
return result.data.thread.title || null;
} catch (error) {
console.error("Fehler bei der Abfrage:", error);
return null;
}
}
// Abrufen der Kommentare des Benutzers
try {
const response = await fetch(`https://www.mydealz.de/profile/${username}?page=1`);
if (!response.ok) throw new Error(`HTTP Fehler! Status: ${response.status}`);
const html = await response.text();
const pattern = /href=https:\/\/www\.mydealz\.de\/.*?-(\d+)#(?:comment|reply)-(\d+)/g;
const matches_raw = [...html.matchAll(pattern)];
const pageResults = [];
for (const match of matches_raw) {
const threadId = match[1];
const commentId = match[2];
// Titel des Deals abrufen
const dealTitle = await fetchDealTitle(threadId);
// Kommentarinhalt abrufen
const commentResponse = await fetch("https://www.mydealz.de/graphql", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: `query comment($id: ID!) { comment(id: $id) { preparedHtmlContent createdAt createdAtTs } }`,
variables: { id: commentId }
})
});
const commentData = await commentResponse.json();
if (commentData?.data?.comment) {
const comment = commentData.data.comment.preparedHtmlContent.replace(/<img[^>]*>/g, '');
const date = new Date(commentData.data.comment.createdAtTs * 1000)
.toLocaleString('de-DE', {
day: '2-digit',
month: '2-digit',
year: '2-digit',
hour: '2-digit',
minute: '2-digit'
})
.replace(',', '');
pageResults.push({
html: `<div class="comment-card" style="background-color:white;padding:1rem;margin:0.75rem 0;border-radius:8px;box-shadow:0 2px 4px rgba(0,0,0,0.1);"><span title="${date}">${commentData.data.comment.createdAt}</span> <b>${dealTitle || "Titel nicht verfügbar"}</b><br>${comment}<br><svg width="15px" height="16px" class="icon icon--comment" style="vertical-align: middle"><use xlink:href="/assets/img/ico_632f5.svg#comment"></use></svg> <a href='${match[0].replace('href=', '')}' target='_blank'>Zum Kommentar</a></div>`,
title: dealTitle || "Titel nicht verfügbar",
comment: comment,
dealId: threadId,
commentId: commentId
});
}
}
// Ergebnisse im sessionStorage speichern
sessionStorage.setItem('mydealz_comments', JSON.stringify(pageResults));
// Popup generieren
const resultWindow = window.open("", "Results", "width=1000,height=700,location=no,menubar=no,toolbar=no,status=no,titlebar=no");
if (resultWindow) {
resultWindow.document.write(`
<html>
<head>
<title>${username}s letzte Kommentare</title>
<style>
body { margin: 0; padding: 0; background: #f5f5f5; font-family: Arial, sans-serif; }
.header { background: #005293; height: 56px; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px; position: relative; }
.logo { height: 40px; position: absolute; left: 20px; }
.sort-options { text-align: center; padding: 10px; }
.comments-container { margin: 20px; }
.comment-card { background-color: white; padding: 1rem; margin: 0.75rem 0; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
</style>
<script>
function sortComments(type) {
let comments = JSON.parse(sessionStorage.getItem('mydealz_comments'));
if (type === 'all') {
comments.sort((a, b) => b.commentId - a.commentId);
} else {
comments.sort((a, b) => b.dealId === a.dealId ? b.commentId - a.commentId : b.dealId - a.dealId);
}
document.getElementById('comments-container').innerHTML = comments.map(r => r.html).join('');
}
</script>
</head>
<body>
<div class="header">
<img src="https://www.mydealz.de/assets/img/logo/default-light_d4b86.svg" class="logo">
<a href="https://www.mydealz.de/profile/${username}" style="color:white;text-decoration:none" target="_blank">${username}s letzte ${pageResults.length} Kommentare</a>
</div>
<div class="sort-options">
Kommentare sortieren nach
<label><input type="radio" name="sort" checked onclick="sortComments('all')"> alle chronologisch</label>
<label><input type="radio" name="sort" onclick="sortComments('deal')"> beitragschronologisch</label>
</div>
<div id="comments-container" class="comments-container">
${pageResults.map(r => r.html).join('')}
</div>
</body>
</html>`);
resultWindow.document.close();
resultWindow.focus();
} else {
alert("Popup blockiert!");
}
} catch (error) {
console.error("Fehler:", error);
alert(`Fehler: ${error.message}`);
}
};
})();