GazelleGames Batch Screenshot Processor

Batch process PTPImg URLs with option to preserve existing screenshots

  1. // ==UserScript==
  2. // @name GazelleGames Batch Screenshot Processor
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Batch process PTPImg URLs with option to preserve existing screenshots
  6. // @author YourName
  7. // @match https://gazellegames.net/torrents.php?action=editgroup&groupid=*
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create batch processor UI
  16. function createBatchProcessor() {
  17. const container = document.createElement('div');
  18. container.style.flex = '1';
  19. container.style.marginLeft = '20px';
  20. container.style.marginTop = '5px';
  21.  
  22. container.innerHTML = `
  23. <div style="margin-bottom: 10px;">
  24. <textarea id="gg-batch-urls" rows="10" style="width: 80%; padding: 5px; border: 1px solid #ccc; font-family: inherit; font-size: 13px;" placeholder="Paste PTPImg URLs here, one per line"></textarea>
  25. </div>
  26. <div style="margin-bottom: 8px;">
  27. <input type="checkbox" id="gg-keep-existing">
  28. <label for="gg-keep-existing" style="font-size: 13px;">Keep existing screenshots</label>
  29. </div>
  30. <input type="button" id="gg-process-btn" value="Fill Screenshot Fields">
  31. `;
  32.  
  33. return container;
  34. }
  35.  
  36. // Process URLs
  37. function processURLs(e) {
  38. e.preventDefault();
  39.  
  40. const textarea = document.getElementById('gg-batch-urls');
  41. const keepExisting = document.getElementById('gg-keep-existing').checked;
  42. const urls = textarea.value.split('\n')
  43. .map(url => url.trim())
  44. .filter(url => url !== '');
  45.  
  46. if (urls.length === 0) {
  47. alert('Please enter at least one URL');
  48. return;
  49. }
  50.  
  51. // Get all existing fields and their values
  52. const existingFields = Array.from(document.querySelectorAll('#image_block input[name="screens[]"]'))
  53. .map(input => input.value.trim())
  54. .filter(val => val !== '');
  55.  
  56. // Combine URLs based on checkbox
  57. const allUrls = keepExisting ? [...existingFields, ...urls] : urls;
  58.  
  59. // Adjust field count if needed
  60. if (allUrls.length > existingFields.length) {
  61. const toAdd = allUrls.length - existingFields.length;
  62. for (let i = 0; i < toAdd; i++) {
  63. if (typeof AddScreenField === 'function') {
  64. AddScreenField(true);
  65. } else {
  66. const newField = document.createElement('span');
  67. newField.innerHTML = `<br><input type="text" name="screens[]" style="width: 90%;"><input type="button" value="PTPImg It">`;
  68. document.getElementById('image_block').appendChild(newField);
  69. }
  70. }
  71. } else if (allUrls.length < existingFields.length && !keepExisting) {
  72. const toRemove = existingFields.length - allUrls.length;
  73. for (let i = 0; i < toRemove; i++) {
  74. if (typeof RemoveScreenField === 'function') {
  75. RemoveScreenField();
  76. } else {
  77. const fields = document.querySelectorAll('#image_block span');
  78. if (fields.length > 1) {
  79. fields[fields.length - 1].remove();
  80. }
  81. }
  82. }
  83. }
  84.  
  85. // Populate fields
  86. const inputs = document.querySelectorAll('#image_block input[name="screens[]"]');
  87. for (let i = 0; i < allUrls.length; i++) {
  88. if (i < inputs.length) {
  89. inputs[i].value = allUrls[i];
  90. }
  91. }
  92. }
  93.  
  94. // Main function to set up the UI
  95. function init() {
  96. const imageBlock = document.getElementById('image_block');
  97. if (!imageBlock) return;
  98.  
  99. // Create container for the row layout
  100. const wrapper = document.createElement('div');
  101. wrapper.style.display = 'flex';
  102. wrapper.style.gap = '20px';
  103. wrapper.style.marginTop = '5px';
  104.  
  105. // Wrap the image block
  106. const screenshotsColumn = document.createElement('div');
  107. screenshotsColumn.style.flex = '1.2';
  108. screenshotsColumn.appendChild(imageBlock);
  109.  
  110. // Create the batch processor
  111. const batchColumn = createBatchProcessor();
  112.  
  113. // Add both columns to the wrapper
  114. wrapper.appendChild(screenshotsColumn);
  115. wrapper.appendChild(batchColumn);
  116.  
  117. // Find the best insertion point
  118. const screenshotsHeader = [...document.querySelectorAll('h3')].find(h3 =>
  119. h3.textContent.includes('Screenshots')
  120. );
  121.  
  122. if (screenshotsHeader) {
  123. screenshotsHeader.parentNode.insertBefore(wrapper, screenshotsHeader.nextSibling);
  124. } else {
  125. imageBlock.parentNode.insertBefore(wrapper, imageBlock);
  126. }
  127.  
  128. // Add event listener to the process button
  129. document.getElementById('gg-process-btn').addEventListener('click', processURLs);
  130. }
  131.  
  132. // Run the script
  133. setTimeout(init, 500);
  134. })();