Advertisement
NewBestPastebins

Untitled

Jun 3rd, 2025 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.31 KB | None | 0 0
  1. (() => {
  2. let cancelRequested = false;
  3.  
  4. const styleButton = (button, bgColor) => {
  5. button.style.padding = '12px 18px';
  6. button.style.width = '100%';
  7. button.style.backgroundColor = bgColor;
  8. button.style.border = 'none';
  9. button.style.color = 'white';
  10. button.style.borderRadius = '10px';
  11. button.style.cursor = 'pointer';
  12. button.style.fontSize = '16px';
  13. button.style.transition = 'background-color 0.3s ease-in-out';
  14. button.style.marginBottom = '10px';
  15. };
  16.  
  17. const styleInput = (input) => {
  18. input.style.width = '100%';
  19. input.style.padding = '10px';
  20. input.style.marginBottom = '15px';
  21. input.style.borderRadius = '10px';
  22. input.style.border = '1px solid #333';
  23. input.style.backgroundColor = '#2b2b2b';
  24. input.style.color = '#f1f1f1';
  25. input.style.fontSize = '16px';
  26. };
  27.  
  28. const extractMessageIds = () => {
  29. const messageElements = document.querySelectorAll('li[data-drag-id]');
  30. return Array.from(messageElements)
  31. .map(el => el.getAttribute('data-drag-id'))
  32. .filter(id => /^\d{6}$/.test(id)); // Only 6-digit numeric IDs
  33. };
  34.  
  35.  
  36. const deleteMessages = async (messageIds, statusText, progressBar) => {
  37. const url = 'https://aae.viggo.dk/Basic/Message/DeleteMessages/?folderId=11';
  38. let deleted = 0;
  39. let i = 0;
  40. while (i < messageIds.length) {
  41. if (cancelRequested) {
  42. statusText.textContent = `Annulleret efter ${deleted} / ${messageIds.length} beskeder.`;
  43. return;
  44. }
  45. const bulkSize = Math.floor(Math.random() * (175 - 75 + 1)) + 75;
  46. const chunk = messageIds.slice(i, i + bulkSize);
  47. const payload = chunk.map(id => `MessageId=${encodeURIComponent(id)}`).join('&');
  48. try {
  49. const res = await fetch(url, {
  50. method: 'DELETE',
  51. headers: {
  52. 'Accept': '*/*',
  53. 'Content-Type': 'application/x-www-form-urlencoded',
  54. 'X-Requested-With': 'XMLHttpRequest'
  55. },
  56. body: payload,
  57. credentials: 'include'
  58. });
  59. if (res.ok) {
  60. deleted += chunk.length;
  61. progressBar.value = (deleted / messageIds.length) * 100;
  62. statusText.textContent = `Sletter ${deleted} / ${messageIds.length}`;
  63. } else {
  64. console.error('Sletning fejlede:', res.statusText);
  65. }
  66. } catch (err) {
  67. console.error('Netværksfejl ved sletning:', err);
  68. }
  69. i += bulkSize;
  70. }
  71. alert(`${deleted} besked(er) slettet.`);
  72. statusText.textContent = 'Sletning færdig - opdaterer siden...';
  73. setTimeout(() => location.reload(), 1500);
  74. };
  75.  
  76. const showConfirmation = (count, onConfirm) => {
  77. const confirmBox = document.createElement('div');
  78. confirmBox.style.position = 'fixed';
  79. confirmBox.style.top = '50%';
  80. confirmBox.style.left = '50%';
  81. confirmBox.style.transform = 'translate(-50%, -50%)';
  82. confirmBox.style.background = '#1a1a1a';
  83. confirmBox.style.color = '#fff';
  84. confirmBox.style.padding = '20px';
  85. confirmBox.style.borderRadius = '12px';
  86. confirmBox.style.boxShadow = '0 0 15px rgba(0,0,0,0.5)';
  87. confirmBox.style.zIndex = '10000';
  88. confirmBox.innerHTML = `<p style="font-size:16px;margin-bottom:15px;">Er du sikker på, at du vil slette <strong>${count}</strong> besked(er)?</p>`;
  89.  
  90. const btnYes = document.createElement('button');
  91. btnYes.textContent = '✅ Ja, slet';
  92. styleButton(btnYes, '#f44336');
  93. btnYes.style.width = '45%';
  94. btnYes.style.marginRight = '10%';
  95.  
  96. const btnNo = document.createElement('button');
  97. btnNo.textContent = '❌ Annuller';
  98. styleButton(btnNo, '#555');
  99. btnNo.style.width = '45%';
  100.  
  101. btnYes.addEventListener('click', () => {
  102. document.body.removeChild(confirmBox);
  103. onConfirm();
  104. });
  105.  
  106. btnNo.addEventListener('click', () => {
  107. document.body.removeChild(confirmBox);
  108. });
  109.  
  110. confirmBox.appendChild(btnYes);
  111. confirmBox.appendChild(btnNo);
  112. document.body.appendChild(confirmBox);
  113. };
  114.  
  115. const createUI = () => {
  116. const uiContainer = document.createElement('div');
  117. uiContainer.style.width = '300px';
  118. uiContainer.style.position = 'fixed';
  119. uiContainer.style.top = '100px';
  120. uiContainer.style.right = '50px';
  121. uiContainer.style.backgroundColor = '#1a1a1a';
  122. uiContainer.style.color = '#f1f1f1';
  123. uiContainer.style.padding = '20px';
  124. uiContainer.style.borderRadius = '15px';
  125. uiContainer.style.boxShadow = '0 6px 12px rgba(0, 0, 0, 0.3)';
  126. uiContainer.style.zIndex = '9999';
  127. uiContainer.style.fontFamily = "'Arial', sans-serif";
  128. uiContainer.style.display = 'none';
  129.  
  130. const header = document.createElement('div');
  131. header.innerHTML = '🗑️ <strong>Viggo Besked Sletter</strong>';
  132. header.style.marginBottom = '15px';
  133. header.style.fontSize = '18px';
  134. uiContainer.appendChild(header);
  135.  
  136. const label = document.createElement('label');
  137. label.textContent = 'Skriv Besked ID(er) (komma-separeret):';
  138. label.style.display = 'block';
  139. label.style.marginBottom = '5px';
  140.  
  141. const textarea = document.createElement('textarea');
  142. textarea.style.width = '100%';
  143. textarea.style.height = '100px';
  144. textarea.style.padding = '10px';
  145. textarea.style.borderRadius = '10px';
  146. textarea.style.border = '1px solid #333';
  147. textarea.style.marginBottom = '15px';
  148. textarea.style.backgroundColor = '#2b2b2b';
  149. textarea.style.color = '#f1f1f1';
  150. textarea.style.resize = 'none';
  151.  
  152. const extractButton = document.createElement('button');
  153. extractButton.textContent = '🔎 Find alle besked ID(er)';
  154. styleButton(extractButton, '#4CAF50');
  155. extractButton.addEventListener('click', () => {
  156. const messageIds = extractMessageIds();
  157. textarea.value = messageIds.join(', ');
  158. });
  159.  
  160. const topExclusionLabel = document.createElement('label');
  161. topExclusionLabel.textContent = 'Antal beskeder der skal beholdes fra toppen:';
  162. topExclusionLabel.style.display = 'block';
  163. topExclusionLabel.style.marginBottom = '5px';
  164.  
  165. const topExclusionInput = document.createElement('input');
  166. topExclusionInput.type = 'number';
  167. styleInput(topExclusionInput);
  168.  
  169. const statusText = document.createElement('div');
  170. statusText.style.marginBottom = '10px';
  171.  
  172. const progressBar = document.createElement('progress');
  173. progressBar.style.width = '100%';
  174. progressBar.max = 100;
  175. progressBar.value = 0;
  176.  
  177. const cancelButton = document.createElement('button');
  178. cancelButton.textContent = '⛔ Annuller';
  179. styleButton(cancelButton, '#555');
  180. cancelButton.style.marginTop = '10px';
  181. cancelButton.addEventListener('click', () => {
  182. cancelRequested = true;
  183. });
  184.  
  185. const deleteButton = document.createElement('button');
  186. deleteButton.textContent = '🗑️ Slet Beskeder';
  187. styleButton(deleteButton, '#f44336');
  188. deleteButton.addEventListener('click', () => {
  189. cancelRequested = false;
  190. const topCount = parseInt(topExclusionInput.value) || 0;
  191. const allIds = textarea.value.split(',').map(id => id.trim()).filter(Boolean);
  192. const idsToDelete = topCount > 0 ? allIds.slice(topCount) : allIds;
  193.  
  194. if (idsToDelete.length === 0) {
  195. statusText.textContent = 'Ingen beskeder valgt.';
  196. return;
  197. }
  198.  
  199. showConfirmation(idsToDelete.length, async () => {
  200. deleteButton.disabled = true;
  201. deleteButton.style.opacity = '0.5';
  202. deleteButton.textContent = '⏳ Sletter...';
  203. statusText.textContent = `Sletter 0 / ${idsToDelete.length}`;
  204. await deleteMessages(idsToDelete, statusText, progressBar);
  205. deleteButton.disabled = false;
  206. deleteButton.style.opacity = '1';
  207. deleteButton.textContent = '🗑️ Slet Beskeder';
  208. });
  209. });
  210.  
  211. const helpButton = document.createElement('button');
  212. helpButton.textContent = '📘 Brugsanvisning';
  213. styleButton(helpButton, '#007BFF');
  214. helpButton.addEventListener('click', () => {
  215. alert(
  216. '🔹 Sådan bruger du Viggo Besked Sletter:\n\n' +
  217. '1️⃣ Scroll helt ned til bunden så alle beskeder indlæses.\n' +
  218. '2️⃣ Klik "🔎 Find alle besked ID(er)" for at samle ID’erne.\n' +
  219. '3️⃣ Udfyld antal fra toppen du vil beholde.\n' +
  220. '4️⃣ Klik "🗑️ Slet Beskeder" for at starte sletningen.\n' +
  221. '❗ Hvis du vil beholde beskeder fra bunden, skal du manuelt slette ID(erne) på de beskeder, du vil beholde. Beskedernes ID(er) står i den samme rækkefølge som på selve beskedlisten på hjemmesiden i tekstfeltet med titlen "Skriv Besked ID(er) (komma-separeret):", så det sidste ID er også den sidste besked.\n' +
  222. '❗ Sletning kan ikke fortrydes.\n' +
  223. '⛔ Du kan afbryde med "Annuller" undervejs.\n' +
  224. '✅ Når færdig, genindlæses siden automatisk.'
  225. );
  226. });
  227.  
  228. uiContainer.appendChild(label);
  229. uiContainer.appendChild(textarea);
  230. uiContainer.appendChild(extractButton);
  231. uiContainer.appendChild(topExclusionLabel);
  232. uiContainer.appendChild(topExclusionInput);
  233. uiContainer.appendChild(deleteButton);
  234. uiContainer.appendChild(cancelButton);
  235. uiContainer.appendChild(statusText);
  236. uiContainer.appendChild(progressBar);
  237. uiContainer.appendChild(helpButton);
  238.  
  239. document.body.appendChild(uiContainer);
  240.  
  241. const toggleButton = document.createElement('button');
  242. toggleButton.textContent = '🔽 Åben Sletter';
  243. toggleButton.style.position = 'fixed';
  244. toggleButton.style.top = '47px';
  245. toggleButton.style.right = '200px';
  246. toggleButton.style.backgroundColor = '#1a1a1a';
  247. toggleButton.style.color = '#f1f1f1';
  248. toggleButton.style.padding = '6px 10px';
  249. toggleButton.style.border = 'none';
  250. toggleButton.style.borderRadius = '8px';
  251. toggleButton.style.cursor = 'pointer';
  252. toggleButton.style.fontSize = '14px';
  253. toggleButton.addEventListener('click', () => {
  254. const isVisible = uiContainer.style.display === 'block';
  255. uiContainer.style.display = isVisible ? 'none' : 'block';
  256. toggleButton.textContent = isVisible ? '🔽 Åben Sletter' : '🔼 Luk Sletter';
  257. });
  258.  
  259. document.body.appendChild(toggleButton);
  260. };
  261.  
  262. createUI();
  263. })();
  264.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement