Mydealz Enhanced Comment Editor

Erweitert den Kommentar-Editor um zusätzliche Formatierungsoptionen

  1. // ==UserScript==
  2. // @name Mydealz Enhanced Comment Editor
  3. // @namespace mydealz-enhanced-editor
  4. // @version 1.3
  5. // @description Erweitert den Kommentar-Editor um zusätzliche Formatierungsoptionen
  6. // @match https://www.mydealz.de/*
  7. // @exclude https://www.mydealz.de/*/edit*
  8. // @exclude https://www.mydealz.de/*/add*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function waitForEditor() {
  17. const observer = new MutationObserver((mutations) => {
  18. mutations.forEach((mutation) => {
  19. const editors = document.querySelectorAll('.tools-wrapper .toolbar');
  20. editors.forEach(editor => {
  21. if (!editor.dataset.enhanced) {
  22. enhanceEditor(editor);
  23. editor.dataset.enhanced = 'true';
  24. }
  25. });
  26. });
  27. });
  28.  
  29. observer.observe(document, {
  30. childList: true,
  31. subtree: true
  32. });
  33. }
  34.  
  35. function zitieren() {
  36. const p = document.querySelector('[parentcommentid]');
  37. if (!p) {
  38. alert('Erst auf "Antworten" klicken\ndann den Zitieren-Button nutzen');
  39. return;
  40. }
  41.  
  42. const i = p.getAttribute('parentcommentid');
  43. if (!i) {
  44. alert('Keine gültige Kommentar ID');
  45. return;
  46. }
  47.  
  48. fetch("https://www.mydealz.de/graphql", {
  49. method: 'POST',
  50. headers: {'Content-Type': 'application/json'},
  51. body: JSON.stringify({
  52. query: 'query comment($id:ID!){comment(id:$id){preparedHtmlContent createdAt createdAtTs}}',
  53. variables: {id: i}
  54. })
  55. })
  56. .then(r => r.json())
  57. .then(d => {
  58. let html = d.data.comment.preparedHtmlContent;
  59. let imgCount = 1;
  60. html = html.replace(/<img[^>]+src="([^"]+)"[^>]*>/g, (match,src) => {
  61. if (!src.includes('.jpg') || !src.split('/').pop().includes('_')) {
  62. const newName = `${i}_${imgCount}`;
  63. const newSrc = src.replace(/\/([^\/]+)\.jpg/, `/${newName}.jpg`)
  64. .replace(/\/([^\/]+)\/fs\//, `/${newName}/fs/`);
  65. imgCount++;
  66. return match.replace(src, newSrc);
  67. }
  68. return match;
  69. });
  70.  
  71. const t = document.querySelector('textarea[parentcommentid]');
  72. const e = document.querySelector('.redactor-editor[placeholder^="Antworten"]');
  73. if (t && e) {
  74. t.value = html;
  75. e.innerHTML = html;
  76. console.log('Inhalt eingefügt');
  77. } else {
  78. alert('Editor nicht gefunden');
  79. }
  80. })
  81. .catch(e => alert("Fehler: " + e.message));
  82. }
  83.  
  84. function enhanceEditor(toolbar) {
  85. const buttonContainer = document.createElement('div');
  86. buttonContainer.className = 'gap--all-1';
  87. buttonContainer.style.display = 'flex';
  88. buttonContainer.style.alignItems = 'center';
  89.  
  90. // Zitieren-Button zuerst hinzufügen
  91. const zitierButton = document.createElement('button');
  92. zitierButton.type = 'button';
  93. zitierButton.className = 'button button--type-tag button--mode-light button--square';
  94. zitierButton.title = 'Originaltext zitieren';
  95. zitierButton.style.minWidth = '36px';
  96. zitierButton.style.height = '36px';
  97. zitierButton.style.padding = '0 4px';
  98. zitierButton.style.marginRight = '0px';
  99.  
  100. const labelSpan = document.createElement('span');
  101. labelSpan.innerHTML = 'Z';
  102. labelSpan.style.fontSize = '18px';
  103. labelSpan.style.lineHeight = '1';
  104.  
  105. zitierButton.appendChild(labelSpan);
  106. zitierButton.addEventListener('click', zitieren);
  107. buttonContainer.appendChild(zitierButton);
  108.  
  109. // Restliche Buttons danach hinzufügen
  110. addButton(buttonContainer, "bold", "Fett Ctrl+B", "B",
  111. {module: "inline", fn: "format", args: ["strong"]});
  112. addButton(buttonContainer, "strike", "Durchgestrichen", "S",
  113. {module: "inline", fn: "format", args: ["del"]});
  114. addButton(buttonContainer, "italic", "Kursiv Ctrl+I", "I",
  115. {module: "inline", fn: "format", args: ["em"]});
  116. addButton(buttonContainer, "bullet-list", "Liste Ctrl+Shift+8", "•",
  117. {module: "list", fn: "toggle", args: ["unorderedlist"]});
  118. addButton(buttonContainer, "line", "Trennlinie", "-",
  119. {module: "line", fn: "insert", args: null});
  120.  
  121. const sendButton = toolbar.querySelector('button[disabled]');
  122. toolbar.insertBefore(buttonContainer, sendButton);
  123. }
  124.  
  125.  
  126. function addButton(container, icon, title, label, handler) {
  127. const button = document.createElement('button');
  128. button.type = 'button';
  129. button.className = 'button button--type-tag button--mode-light button--square';
  130. button.title = title;
  131. button.style.minWidth = '36px';
  132. button.style.height = '36px';
  133. button.style.padding = '0 4px';
  134. button.style.marginRight = '0px';
  135.  
  136. const labelSpan = document.createElement('span');
  137. labelSpan.innerHTML = label;
  138. labelSpan.style.fontSize = '18px';
  139. labelSpan.style.lineHeight = '1';
  140.  
  141. if (handler) {
  142. button.setAttribute('data-handler', 'wysiwyg-button popover-close');
  143. button.setAttribute('data-wysiwyg-button', JSON.stringify(handler));
  144. }
  145.  
  146. button.appendChild(labelSpan);
  147. container.appendChild(button);
  148. }
  149.  
  150. if (document.readyState === 'loading') {
  151. document.addEventListener('DOMContentLoaded', waitForEditor);
  152. } else {
  153. waitForEditor();
  154. }
  155. })();

QingJ © 2025

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