Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (() => {
- let cancelRequested = false;
- const styleButton = (button, bgColor) => {
- button.style.padding = '12px 18px';
- button.style.width = '100%';
- button.style.backgroundColor = bgColor;
- button.style.border = 'none';
- button.style.color = 'white';
- button.style.borderRadius = '10px';
- button.style.cursor = 'pointer';
- button.style.fontSize = '16px';
- button.style.transition = 'background-color 0.3s ease-in-out';
- button.style.marginBottom = '10px';
- };
- const styleInput = (input) => {
- input.style.width = '100%';
- input.style.padding = '10px';
- input.style.marginBottom = '15px';
- input.style.borderRadius = '10px';
- input.style.border = '1px solid #333';
- input.style.backgroundColor = '#2b2b2b';
- input.style.color = '#f1f1f1';
- input.style.fontSize = '16px';
- };
- const extractMessageIds = () => {
- const messageElements = document.querySelectorAll('li[data-drag-id]');
- return Array.from(messageElements)
- .map(el => el.getAttribute('data-drag-id'))
- .filter(id => /^\d{6}$/.test(id)); // Only 6-digit numeric IDs
- };
- const deleteMessages = async (messageIds, statusText, progressBar) => {
- const url = 'https://aae.viggo.dk/Basic/Message/DeleteMessages/?folderId=11';
- let deleted = 0;
- let i = 0;
- while (i < messageIds.length) {
- if (cancelRequested) {
- statusText.textContent = `Annulleret efter ${deleted} / ${messageIds.length} beskeder.`;
- return;
- }
- const bulkSize = Math.floor(Math.random() * (175 - 75 + 1)) + 75;
- const chunk = messageIds.slice(i, i + bulkSize);
- const payload = chunk.map(id => `MessageId=${encodeURIComponent(id)}`).join('&');
- try {
- const res = await fetch(url, {
- method: 'DELETE',
- headers: {
- 'Accept': '*/*',
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'X-Requested-With': 'XMLHttpRequest'
- },
- body: payload,
- credentials: 'include'
- });
- if (res.ok) {
- deleted += chunk.length;
- progressBar.value = (deleted / messageIds.length) * 100;
- statusText.textContent = `Sletter ${deleted} / ${messageIds.length}`;
- } else {
- console.error('Sletning fejlede:', res.statusText);
- }
- } catch (err) {
- console.error('Netværksfejl ved sletning:', err);
- }
- i += bulkSize;
- }
- alert(`${deleted} besked(er) slettet.`);
- statusText.textContent = 'Sletning færdig - opdaterer siden...';
- setTimeout(() => location.reload(), 1500);
- };
- const showConfirmation = (count, onConfirm) => {
- const confirmBox = document.createElement('div');
- confirmBox.style.position = 'fixed';
- confirmBox.style.top = '50%';
- confirmBox.style.left = '50%';
- confirmBox.style.transform = 'translate(-50%, -50%)';
- confirmBox.style.background = '#1a1a1a';
- confirmBox.style.color = '#fff';
- confirmBox.style.padding = '20px';
- confirmBox.style.borderRadius = '12px';
- confirmBox.style.boxShadow = '0 0 15px rgba(0,0,0,0.5)';
- confirmBox.style.zIndex = '10000';
- confirmBox.innerHTML = `<p style="font-size:16px;margin-bottom:15px;">Er du sikker på, at du vil slette <strong>${count}</strong> besked(er)?</p>`;
- const btnYes = document.createElement('button');
- btnYes.textContent = '✅ Ja, slet';
- styleButton(btnYes, '#f44336');
- btnYes.style.width = '45%';
- btnYes.style.marginRight = '10%';
- const btnNo = document.createElement('button');
- btnNo.textContent = '❌ Annuller';
- styleButton(btnNo, '#555');
- btnNo.style.width = '45%';
- btnYes.addEventListener('click', () => {
- document.body.removeChild(confirmBox);
- onConfirm();
- });
- btnNo.addEventListener('click', () => {
- document.body.removeChild(confirmBox);
- });
- confirmBox.appendChild(btnYes);
- confirmBox.appendChild(btnNo);
- document.body.appendChild(confirmBox);
- };
- const createUI = () => {
- const uiContainer = document.createElement('div');
- uiContainer.style.width = '300px';
- uiContainer.style.position = 'fixed';
- uiContainer.style.top = '100px';
- uiContainer.style.right = '50px';
- uiContainer.style.backgroundColor = '#1a1a1a';
- uiContainer.style.color = '#f1f1f1';
- uiContainer.style.padding = '20px';
- uiContainer.style.borderRadius = '15px';
- uiContainer.style.boxShadow = '0 6px 12px rgba(0, 0, 0, 0.3)';
- uiContainer.style.zIndex = '9999';
- uiContainer.style.fontFamily = "'Arial', sans-serif";
- uiContainer.style.display = 'none';
- const header = document.createElement('div');
- header.innerHTML = '🗑️ <strong>Viggo Besked Sletter</strong>';
- header.style.marginBottom = '15px';
- header.style.fontSize = '18px';
- uiContainer.appendChild(header);
- const label = document.createElement('label');
- label.textContent = 'Skriv Besked ID(er) (komma-separeret):';
- label.style.display = 'block';
- label.style.marginBottom = '5px';
- const textarea = document.createElement('textarea');
- textarea.style.width = '100%';
- textarea.style.height = '100px';
- textarea.style.padding = '10px';
- textarea.style.borderRadius = '10px';
- textarea.style.border = '1px solid #333';
- textarea.style.marginBottom = '15px';
- textarea.style.backgroundColor = '#2b2b2b';
- textarea.style.color = '#f1f1f1';
- textarea.style.resize = 'none';
- const extractButton = document.createElement('button');
- extractButton.textContent = '🔎 Find alle besked ID(er)';
- styleButton(extractButton, '#4CAF50');
- extractButton.addEventListener('click', () => {
- const messageIds = extractMessageIds();
- textarea.value = messageIds.join(', ');
- });
- const topExclusionLabel = document.createElement('label');
- topExclusionLabel.textContent = 'Antal beskeder der skal beholdes fra toppen:';
- topExclusionLabel.style.display = 'block';
- topExclusionLabel.style.marginBottom = '5px';
- const topExclusionInput = document.createElement('input');
- topExclusionInput.type = 'number';
- styleInput(topExclusionInput);
- const statusText = document.createElement('div');
- statusText.style.marginBottom = '10px';
- const progressBar = document.createElement('progress');
- progressBar.style.width = '100%';
- progressBar.max = 100;
- progressBar.value = 0;
- const cancelButton = document.createElement('button');
- cancelButton.textContent = '⛔ Annuller';
- styleButton(cancelButton, '#555');
- cancelButton.style.marginTop = '10px';
- cancelButton.addEventListener('click', () => {
- cancelRequested = true;
- });
- const deleteButton = document.createElement('button');
- deleteButton.textContent = '🗑️ Slet Beskeder';
- styleButton(deleteButton, '#f44336');
- deleteButton.addEventListener('click', () => {
- cancelRequested = false;
- const topCount = parseInt(topExclusionInput.value) || 0;
- const allIds = textarea.value.split(',').map(id => id.trim()).filter(Boolean);
- const idsToDelete = topCount > 0 ? allIds.slice(topCount) : allIds;
- if (idsToDelete.length === 0) {
- statusText.textContent = 'Ingen beskeder valgt.';
- return;
- }
- showConfirmation(idsToDelete.length, async () => {
- deleteButton.disabled = true;
- deleteButton.style.opacity = '0.5';
- deleteButton.textContent = '⏳ Sletter...';
- statusText.textContent = `Sletter 0 / ${idsToDelete.length}`;
- await deleteMessages(idsToDelete, statusText, progressBar);
- deleteButton.disabled = false;
- deleteButton.style.opacity = '1';
- deleteButton.textContent = '🗑️ Slet Beskeder';
- });
- });
- const helpButton = document.createElement('button');
- helpButton.textContent = '📘 Brugsanvisning';
- styleButton(helpButton, '#007BFF');
- helpButton.addEventListener('click', () => {
- alert(
- '🔹 Sådan bruger du Viggo Besked Sletter:\n\n' +
- '1️⃣ Scroll helt ned til bunden så alle beskeder indlæses.\n' +
- '2️⃣ Klik "🔎 Find alle besked ID(er)" for at samle ID’erne.\n' +
- '3️⃣ Udfyld antal fra toppen du vil beholde.\n' +
- '4️⃣ Klik "🗑️ Slet Beskeder" for at starte sletningen.\n' +
- '❗ 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' +
- '❗ Sletning kan ikke fortrydes.\n' +
- '⛔ Du kan afbryde med "Annuller" undervejs.\n' +
- '✅ Når færdig, genindlæses siden automatisk.'
- );
- });
- uiContainer.appendChild(label);
- uiContainer.appendChild(textarea);
- uiContainer.appendChild(extractButton);
- uiContainer.appendChild(topExclusionLabel);
- uiContainer.appendChild(topExclusionInput);
- uiContainer.appendChild(deleteButton);
- uiContainer.appendChild(cancelButton);
- uiContainer.appendChild(statusText);
- uiContainer.appendChild(progressBar);
- uiContainer.appendChild(helpButton);
- document.body.appendChild(uiContainer);
- const toggleButton = document.createElement('button');
- toggleButton.textContent = '🔽 Åben Sletter';
- toggleButton.style.position = 'fixed';
- toggleButton.style.top = '47px';
- toggleButton.style.right = '200px';
- toggleButton.style.backgroundColor = '#1a1a1a';
- toggleButton.style.color = '#f1f1f1';
- toggleButton.style.padding = '6px 10px';
- toggleButton.style.border = 'none';
- toggleButton.style.borderRadius = '8px';
- toggleButton.style.cursor = 'pointer';
- toggleButton.style.fontSize = '14px';
- toggleButton.addEventListener('click', () => {
- const isVisible = uiContainer.style.display === 'block';
- uiContainer.style.display = isVisible ? 'none' : 'block';
- toggleButton.textContent = isVisible ? '🔽 Åben Sletter' : '🔼 Luk Sletter';
- });
- document.body.appendChild(toggleButton);
- };
- createUI();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement