GazelleGames Perfect Batch Screenshot Processor

Perfectly integrated batch processor for PTPImg URLs on GazelleGames

当前为 2025-06-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GazelleGames Perfect Batch Screenshot Processor
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Perfectly integrated batch processor for PTPImg URLs on GazelleGames
  6. // @author stormlight
  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'; // Align with screenshot fields
  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. <input type="button" id="gg-process-btn" value="Fill Screenshot Fields">
  27. `;
  28.  
  29. return container;
  30. }
  31.  
  32. // Process URLs
  33. function processURLs(e) {
  34. e.preventDefault();
  35.  
  36. const textarea = document.getElementById('gg-batch-urls');
  37. const urls = textarea.value.split('\n')
  38. .map(url => url.trim())
  39. .filter(url => url !== '');
  40.  
  41. if (urls.length === 0) {
  42. alert('Please enter at least one URL');
  43. return;
  44. }
  45.  
  46. // Get all existing fields
  47. const fields = document.querySelectorAll('#image_block input[name="screens[]"]');
  48.  
  49. // Adjust field count if needed
  50. if (urls.length > fields.length) {
  51. const toAdd = urls.length - fields.length;
  52. for (let i = 0; i < toAdd; i++) {
  53. if (typeof AddScreenField === 'function') {
  54. AddScreenField(true);
  55. } else {
  56. // Fallback method
  57. const newField = document.createElement('span');
  58. newField.innerHTML = `<br><input type="text" name="screens[]" style="width: 90%;"><input type="button" value="PTPImg It">`;
  59. document.getElementById('image_block').appendChild(newField);
  60. }
  61. }
  62. } else if (urls.length < fields.length) {
  63. const toRemove = fields.length - urls.length;
  64. for (let i = 0; i < toRemove; i++) {
  65. if (typeof RemoveScreenField === 'function') {
  66. RemoveScreenField();
  67. } else {
  68. // Fallback method
  69. const fields = document.querySelectorAll('#image_block span');
  70. if (fields.length > 1) {
  71. fields[fields.length - 1].remove();
  72. }
  73. }
  74. }
  75. }
  76.  
  77. // Populate fields
  78. const inputs = document.querySelectorAll('#image_block input[name="screens[]"]');
  79. for (let i = 0; i < urls.length; i++) {
  80. if (i < inputs.length) {
  81. inputs[i].value = urls[i];
  82. }
  83. }
  84. }
  85.  
  86. // Main function to set up the UI
  87. function init() {
  88. const imageBlock = document.getElementById('image_block');
  89. if (!imageBlock) return;
  90.  
  91. // Create container for the row layout
  92. const wrapper = document.createElement('div');
  93. wrapper.style.display = 'flex';
  94. wrapper.style.gap = '20px';
  95. wrapper.style.marginTop = '5px'; // Reduced to match site spacing
  96.  
  97. // Wrap the image block
  98. const screenshotsColumn = document.createElement('div');
  99. screenshotsColumn.style.flex = '1.2'; // Slightly wider than processor
  100. screenshotsColumn.appendChild(imageBlock);
  101.  
  102. // Create the batch processor
  103. const batchColumn = createBatchProcessor();
  104.  
  105. // Add both columns to the wrapper
  106. wrapper.appendChild(screenshotsColumn);
  107. wrapper.appendChild(batchColumn);
  108.  
  109. // Find the best insertion point
  110. const screenshotsHeader = [...document.querySelectorAll('h3')].find(h3 =>
  111. h3.textContent.includes('Screenshots')
  112. );
  113.  
  114. if (screenshotsHeader) {
  115. // Insert after the header but before any existing content
  116. const parent = screenshotsHeader.parentNode;
  117. parent.insertBefore(wrapper, screenshotsHeader.nextSibling);
  118. } else {
  119. // Fallback to inserting before the image block
  120. imageBlock.parentNode.insertBefore(wrapper, imageBlock);
  121. }
  122.  
  123. // Add event listener to the process button
  124. document.getElementById('gg-process-btn').addEventListener('click', processURLs);
  125. }
  126.  
  127. // Run the script
  128. setTimeout(init, 500);
  129. })();