Select All Torrents Button on Deleted Torrents Page

Add a "Select All" button to select all checkboxes for torrents on delete notification page

目前为 2025-03-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Select All Torrents Button on Deleted Torrents Page
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @match https://gazellegames.net/torrents.php?action=delete_notify
  6. // @description Add a "Select All" button to select all checkboxes for torrents on delete notification page
  7. // @author SleepingGiant
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function addSelectAllButton() {
  15. var selectAllButton = document.createElement('button');
  16. selectAllButton.innerText = 'Select All';
  17. // Add the 'button' class to apply the existing page styles
  18. selectAllButton.classList.add('button', 'input[type=submit]', 'input[type=button]');
  19. var container = document.querySelector('.center');
  20.  
  21. if (container) {
  22. // Insert the button into the container
  23. container.appendChild(selectAllButton);
  24.  
  25. selectAllButton.addEventListener('click', function () {
  26. var checkboxes = document.querySelectorAll('input[type="checkbox"]');
  27. if (checkboxes.length > 0) {
  28. var allChecked = Array.from(checkboxes).every(checkbox => checkbox.checked);
  29. checkboxes.forEach(function (checkbox) {
  30. checkbox.checked = !allChecked;
  31. });
  32. }
  33. });
  34.  
  35. // Once the button is added, stop further retries
  36. clearInterval(intervalId);
  37. }
  38. }
  39.  
  40. // Retry adding the button every 100ms, up to 100 times
  41. let retryCount = 0;
  42. let maxRetries = 100;
  43. let intervalId = setInterval(function() {
  44. addSelectAllButton();
  45. retryCount++;
  46.  
  47. if (retryCount >= maxRetries) {
  48. clearInterval(intervalId);
  49. console.log('Max retries reached. Stopping attempts.');
  50. }
  51. }, 75);
  52. })();