Export Shopify Fullsize File URLs

Export all fullsize file URLs from Shopify to clipboard and log them in console (bulk export with pagination)

目前为 2024-05-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Export Shopify Fullsize File URLs
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.7
  5. // @description Export all fullsize file URLs from Shopify to clipboard and log them in console (bulk export with pagination)
  6. // @author sharmanhall
  7. // @match https://admin.shopify.com/store/*/content/files?limit=*&selectedView=all
  8. // @match https://admin.shopify.com/store/*/content/files*
  9. // @grant GM_setClipboard
  10. // @grant GM_log
  11. // @run-at document-end
  12. // @license MIT
  13. // @icon https://www.google.com/s2/favicons?sz=64&domain=shopify.com
  14. // @compatible chrome
  15. // @compatible edge
  16. // @compatible firefox
  17. // @compatible safari
  18. // @compatible brave
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. let accumulatedUrls = [];
  25.  
  26. // Function to extract file URLs
  27. function extractFileUrls() {
  28. // Select all elements that contain file URLs using the provided selector
  29. const fileElements = document.querySelectorAll('td._ThumbnailCell_b1ynd_1.Polaris-IndexTable__TableCell div > div > button > span img');
  30.  
  31. // Extract URLs from the elements and convert to fullsize image URLs
  32. const fileUrls = Array.from(fileElements).map(el => el.src.replace('_60x60', ''));
  33.  
  34. // Log the URLs to the console
  35. console.log('Fullsize File URLs:', fileUrls);
  36.  
  37. // Copy URLs to clipboard
  38. GM_setClipboard(fileUrls.join('\n'));
  39.  
  40. // Log success message
  41. GM_log('Fullsize file URLs copied to clipboard.');
  42. }
  43.  
  44. // Function to accumulate file URLs and copy to clipboard
  45. function accumulateFileUrls() {
  46. // Select all elements that contain file URLs using the provided selector
  47. const fileElements = document.querySelectorAll('td._ThumbnailCell_b1ynd_1.Polaris-IndexTable__TableCell div > div > button > span img');
  48.  
  49. // Extract URLs from the elements and convert to fullsize image URLs
  50. const fileUrls = Array.from(fileElements).map(el => el.src.replace('_60x60', ''));
  51.  
  52. // Add to accumulated URLs
  53. accumulatedUrls = accumulatedUrls.concat(fileUrls);
  54.  
  55. // Log the accumulated URLs to the console
  56. console.log('Accumulated Fullsize File URLs:', accumulatedUrls);
  57.  
  58. // Copy accumulated URLs to clipboard
  59. GM_setClipboard(accumulatedUrls.join('\n'));
  60.  
  61. // Log success message
  62. GM_log('Accumulated fullsize file URLs copied to clipboard.');
  63. }
  64.  
  65. // Function to create a floating button for extracting URLs
  66. function createFloatingButton() {
  67. const button = document.createElement('button');
  68. button.innerText = 'Export File URLs';
  69. button.style.position = 'fixed';
  70. button.style.bottom = '10px';
  71. button.style.right = '10px';
  72. button.style.zIndex = '1000';
  73. button.style.padding = '10px';
  74. button.style.backgroundColor = '#008CBA';
  75. button.style.color = 'white';
  76. button.style.border = 'none';
  77. button.style.borderRadius = '5px';
  78. button.style.cursor = 'pointer';
  79.  
  80. button.addEventListener('click', extractFileUrls);
  81.  
  82. document.body.appendChild(button);
  83. }
  84.  
  85. // Function to create a floating button for accumulating URLs
  86. function createAccumulateButton() {
  87. const button = document.createElement('button');
  88. button.innerText = 'Accumulate URLs';
  89. button.style.position = 'fixed';
  90. button.style.bottom = '10px';
  91. button.style.right = '150px';
  92. button.style.zIndex = '1000';
  93. button.style.padding = '10px';
  94. button.style.backgroundColor = '#FFA500';
  95. button.style.color = 'white';
  96. button.style.border = 'none';
  97. button.style.borderRadius = '5px';
  98. button.style.cursor = 'pointer';
  99.  
  100. button.addEventListener('click', accumulateFileUrls);
  101.  
  102. document.body.appendChild(button);
  103. }
  104.  
  105. // Function to create a floating input area for changing the limit parameter
  106. function createLimitInput() {
  107. const container = document.createElement('div');
  108. container.style.position = 'fixed';
  109. container.style.bottom = '50px';
  110. container.style.right = '10px';
  111. container.style.zIndex = '1000';
  112. container.style.padding = '10px';
  113. container.style.backgroundColor = '#fff';
  114. container.style.border = '1px solid #ccc';
  115. container.style.borderRadius = '5px';
  116.  
  117. const label = document.createElement('label');
  118. label.innerText = 'Set Limit: ';
  119. label.style.marginRight = '5px';
  120.  
  121. const input = document.createElement('input');
  122. input.type = 'number';
  123. input.value = 10;
  124. input.style.marginRight = '5px';
  125. input.style.width = '50px';
  126.  
  127. const setButton = document.createElement('button');
  128. setButton.innerText = 'Set';
  129. setButton.style.padding = '5px';
  130. setButton.style.backgroundColor = '#008CBA';
  131. setButton.style.color = 'white';
  132. setButton.style.border = 'none';
  133. setButton.style.borderRadius = '5px';
  134. setButton.style.cursor = 'pointer';
  135.  
  136. setButton.addEventListener('click', () => {
  137. const limit = input.value;
  138. const currentUrl = new URL(window.location.href);
  139. currentUrl.searchParams.set('limit', limit);
  140. window.location.href = currentUrl.toString();
  141. });
  142.  
  143. container.appendChild(label);
  144. container.appendChild(input);
  145. container.appendChild(setButton);
  146.  
  147. document.body.appendChild(container);
  148. }
  149.  
  150. // Function to create quick change buttons
  151. function createQuickChangeButtons() {
  152. const limits = [10, 50, 100, 200, 250];
  153. const container = document.createElement('div');
  154. container.style.position = 'fixed';
  155. container.style.bottom = '110px';
  156. container.style.right = '10px';
  157. container.style.zIndex = '1000';
  158. container.style.padding = '10px';
  159. container.style.backgroundColor = '#fff';
  160. container.style.border = '1px solid #ccc';
  161. container.style.borderRadius = '5px';
  162. container.style.display = 'flex';
  163. container.style.flexDirection = 'column';
  164. container.style.gap = '5px';
  165.  
  166. limits.forEach(limit => {
  167. const button = document.createElement('button');
  168. button.innerText = `Set Limit ${limit}`;
  169. button.style.padding = '5px';
  170. button.style.backgroundColor = '#008CBA';
  171. button.style.color = 'white';
  172. button.style.border = 'none';
  173. button.style.borderRadius = '5px';
  174. button.style.cursor = 'pointer';
  175.  
  176. button.addEventListener('click', () => {
  177. const currentUrl = new URL(window.location.href);
  178. currentUrl.searchParams.set('limit', limit);
  179. window.location.href = currentUrl.toString();
  180. });
  181.  
  182. container.appendChild(button);
  183. });
  184.  
  185. document.body.appendChild(container);
  186. }
  187.  
  188. // Wait for the page to fully load
  189. window.addEventListener('load', () => {
  190. createFloatingButton();
  191. createAccumulateButton();
  192. createLimitInput();
  193. createQuickChangeButtons();
  194. });
  195.  
  196. })();