Skip to content

Instantly share code, notes, and snippets.

@qubodup
Created September 3, 2025 21:00
Show Gist options
  • Save qubodup/1bc7aca17fb7a25406bf2d8d7bfaac6f to your computer and use it in GitHub Desktop.
Save qubodup/1bc7aca17fb7a25406bf2d8d7bfaac6f to your computer and use it in GitHub Desktop.
Delete pending sound by username in queue semi-automation
// ==UserScript==
// @name Freesound Mod DELETE USERNAME
// @namespace http://tampermonkey.net/
// @version 2025-09-03
// @description Automate moderation checks with page redirection
// @include /^https:\/\/freesound\.org\/tickets\/moderation\/assigned\/\d+\/(?:\?.*)?$/
// @grant none
// ==/UserScript==
(function() {
'use strict';
/********************
* CONFIG SECTION
********************/
const CONFIG = {
username: 'USERNAME', // Username to search for
pageNumber: 5, // Page to redirect to from base
minMatches: 120, // Minimum times username must appear
minCheckedBoxes: 60, // Minimum number of checkboxes required
autoSubmit: false // Change to true if you want auto-submit enabled
};
/********************/
const { href, origin, pathname } = window.location;
// Require: /tickets/moderation/assigned/<digits>/
const m = pathname.match(/^\/tickets\/moderation\/assigned\/(\d+)\/$/);
if (!m) return;
const ticketId = m[1];
const baseUrl = `${origin}/tickets/moderation/assigned/${ticketId}/`;
const url = new URL(href);
const page = url.searchParams.get('page');
// Case 1: On base page (no ?page param) -> go to configured page
if (!page) {
console.log(`On base page, redirecting to page=${CONFIG.pageNumber}…`);
window.location.replace(`${baseUrl}?page=${CONFIG.pageNumber}`);
return;
}
// Case 2: If on configured page, run the existing logic
if (page === String(CONFIG.pageNumber)) {
const word = CONFIG.username;
const bodyText = document.body.innerText;
const count = (bodyText.match(new RegExp(word, 'g')) || []).length;
console.log(`'${word}' found ${count} times on page`);
if (count >= CONFIG.minMatches) {
// Step 0
const targetLink = document.querySelector('#assigned-tickets-table tr:first-child td:nth-child(2) a');
if (targetLink) {
const text = targetLink.textContent.trim();
console.log(`Step 0: Link text is "${text}"`);
if (text !== word) {
console.log(`Step 0 failed: expected "${word}", aborting`);
return;
}
} else {
console.log("Step 0 failed: target link not found, aborting");
return;
}
// Step 1
const selectOther = document.querySelector('#select-other');
if (selectOther) {
selectOther.click();
const checkedBoxes = document.querySelectorAll('input[type="checkbox"]:checked').length;
console.log(`${checkedBoxes} checkboxes are checked`);
if (checkedBoxes < CONFIG.minCheckedBoxes) {
console.log(`Less than ${CONFIG.minCheckedBoxes} checkboxes checked, aborting`);
return;
}
} else {
console.log("#select-other not found, aborting");
return;
}
// Step 2
const label = document.querySelector('label[for="id_action_1"].bw-radio-label');
const radio = document.querySelector('input#id_action_1');
if (label && radio) {
label.click();
if (!radio.checked) {
console.log("Radio button not selected, aborting");
return;
}
} else {
console.log("Radio label or input not found, aborting");
return;
}
// Step 3
const submitBtn = document.querySelector('#moderate-form-wrapper > div > form > button[type="submit"]');
if (submitBtn && CONFIG.autoSubmit) {
console.log("Auto-submitting form...");
submitBtn.click();
} else {
console.log("Auto-submit disabled. Review manually.");
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment