Comment PopUp

Das Skript stellt einen Kommentar anhand seiner commentID in einem PopUp dar.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/531060/1561179/Comment%20PopUp.js

  1. function showCommentPopup(commentID) {
  2. let popup = document.getElementById('commentPopup');
  3. if (!popup) {
  4. popup = document.createElement('div');
  5. popup.id = 'commentPopup';
  6. popup.style.position = 'fixed';
  7. popup.style.backgroundColor = '#fff';
  8. popup.style.padding = '12px';
  9. popup.style.border = '1px solid #ccc';
  10. popup.style.borderRadius = '6px';
  11. popup.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
  12. popup.style.zIndex = '9999';
  13. popup.style.maxWidth = '600px';
  14. popup.style.maxHeight = '400px';
  15. popup.style.overflow = 'auto';
  16. popup.style.display = 'none';
  17. document.body.appendChild(popup);
  18. }
  19.  
  20. const fetchDealTitle = async (threadId) => {
  21. const query = `query getThread($filter: IDFilter!) { thread(threadId: $filter) { title } }`;
  22. try {
  23. const response = await fetch("https://www.mydealz.de/graphql", {
  24. method: 'POST',
  25. headers: {'Content-Type': 'application/json'},
  26. body: JSON.stringify({ query, variables: { filter: { eq: threadId } } })
  27. });
  28. const result = await response.json();
  29. return result.data?.thread?.title || "Titel nicht verfügbar";
  30. } catch (e) {
  31. return "Titel konnte nicht geladen werden";
  32. }
  33. };
  34.  
  35. async function fetchSingleComment(commentId) {
  36. const response = await fetch('https://www.mydealz.de/graphql', {
  37. method: 'POST',
  38. headers: {'Content-Type': 'application/json'},
  39. credentials: 'include',
  40. body: JSON.stringify({
  41. query: `query comment($id: ID!) { comment(id: $id) { preparedHtmlContent createdAtTs url user { username } } }`,
  42. variables: { id: commentId }
  43. })
  44. });
  45. return response.json();
  46. }
  47.  
  48. async function loadAndShowComment() {
  49. try {
  50. popup.style.display = 'block';
  51. popup.innerHTML = '<em>Lade Kommentar...</em>';
  52.  
  53. const commentResponse = await fetchSingleComment(commentID);
  54. const commentData = commentResponse.data.comment;
  55. const threadId = commentData.url.match(/-(\d+)#/)[1];
  56. const threadTitle = (await fetchDealTitle(threadId)).substring(0, 60);
  57.  
  58. const commentDate = new Date(commentData.createdAtTs * 1000)
  59. .toLocaleString('de-DE', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })
  60. .replace(',', '');
  61.  
  62. popup.innerHTML = `
  63. <div style="position:relative;">
  64. <div style="background:#4CAF50; color:#fff; margin:-12px -12px 12px -12px; padding:8px 12px; border-radius:5px 5px 0 0;">
  65. <button onclick="document.getElementById('commentPopup').style.display='none'"
  66. style="position:absolute; top:6px; right:12px; background:none; border:0; color:#fff; cursor:pointer; font-size:16px">
  67. ×
  68. </button>
  69. <div style="font-size:14px; font-weight:bold; white-space:nowrap; overflow:hidden; text-overflow:ellipsis">
  70. ${threadTitle}
  71. </div>
  72. </div>
  73. <div style="margin:0 8px;">
  74. <div style="font-weight:bold; margin-bottom:8px; font-size:14px;">
  75. @${commentData.user.username} am ${commentDate}
  76. </div>
  77. <div style="font-size:14px; line-height:1.4; margin-bottom:15px">
  78. ${commentData.preparedHtmlContent}
  79. </div>
  80. <div style="text-align:right;">
  81. <button onclick="window.open('${commentData.url}'); document.getElementById('commentPopup').style.display='none'"
  82. style="padding:6px 12px; background:#4CAF50; color:#fff; border:none; border-radius:4px; cursor:pointer">
  83. Zum Kommentar
  84. </button>
  85. </div>
  86. </div>
  87. </div>`;
  88.  
  89. // Zentrierte Positionierung
  90. popup.style.left = `${(window.innerWidth - popup.offsetWidth)/2}px`;
  91. popup.style.top = `${(window.innerHeight - popup.offsetHeight)/2}px`;
  92.  
  93. } catch (e) {
  94. popup.innerHTML = `<div style="color:#d00; padding:12px">Fehler: ${e.message}</div>`;
  95. popup.style.display = 'block';
  96. }
  97. }
  98.  
  99. loadAndShowComment();
  100.  
  101. document.addEventListener('click', (e) => {
  102. if (!popup.contains(e.target)) popup.style.display = 'none';
  103. }, {once: true});
  104. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址