Redbubble Get Promotional Image URLs

Gets urls for all promo images from a RedBubble promotion page and saves a txt file contianing urls

  1. // ==UserScript==
  2. // @name Redbubble Get Promotional Image URLs
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.3
  5. // @description Gets urls for all promo images from a RedBubble promotion page and saves a txt file contianing urls
  6. // @author Dylan Banta
  7. // @match https://www.redbubble.com/studio/promote/*
  8. // @require https://greasyfork.org/scripts/404462-my-logger-util/code/My_Logger_Util.js?version=812560
  9. // @require https://greasyfork.org/scripts/404600-my-general-utils/code/My_General_Utils.js?version=812567
  10. // @require https://greasyfork.org/scripts/404687-file-saver-util/code/File_Saver_Util.js?version=812568
  11. // @require https://code.jquery.com/jquery-3.5.1.min.js
  12. // @require https://greasyfork.org/scripts/404687-file-saver-util/code/File_Saver_Util.js?version=812564
  13. // @resource customCSS https://raw.githubusercontent.com/DylanBanta/Tampermonkey/master/RedBubble_Get_Promotional_Image_URLs/savebtn.css
  14. // @grant GM_getResourceText
  15. // @grant GM_addStyle
  16. // @run-at document-end
  17. // ==/UserScript==
  18.  
  19. var productNum = 1;
  20. var urlArr = [];
  21.  
  22. //Custom css
  23. var cssTxt = GM_getResourceText("customCSS");
  24. GM_addStyle(cssTxt);
  25.  
  26. //Calls custom log util
  27. function log(logs, forceOn) {
  28. var call = log.caller.name; //get caller function
  29. var debug = true;
  30. logger(logs, debug, call, forceOn);
  31. }
  32.  
  33. //will be run when script loads
  34. function run() {
  35. log("run Enter", true);
  36.  
  37. var settingsBtns = ".node_modules--redbubble-design-system-react-Box-styles__box--206r9.node_modules--redbubble-design-system-react-Text-styles__text--NLf2i.node_modules--redbubble-design-system-react-Text-styles__display1--2XY2m";
  38. waitForElement(settingsBtns, createSaveBtn);
  39. }
  40.  
  41. //Creates the save button on the page
  42. function createSaveBtn(select) {
  43. log("createSaveBtn Enter", true);
  44. var saveButtonElement = '<div><input type="button" value="Save All" class="saveBtn"/></div>'; //saveBtn html
  45. //run createElements with saveButtonElement as element, and select as append location
  46. createElements(saveButtonElement, select);
  47. //Add save() function to btn click
  48. $('.saveBtn').click(function () {
  49. save(); //save button function
  50. });
  51. }
  52.  
  53. async function save() {
  54. log("save Enter", true);
  55.  
  56. // Select the buttons that open the download menu from the DOM
  57. const buttons = document.querySelectorAll(".node_modules--redbubble-design-system-react-Button-styles__small--127Kw");
  58. // For every button found, run the following
  59.  
  60. const productArr = [1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 15, 16, 17, 18, 21, 23, 27, 29, 47, 31, 32, 41, 43, 48, 49, 50, 55, 56, 58, 63, 65, 67, 70];
  61.  
  62. for (var i = 0; i < buttons.length; i++) {
  63. if (i != 0) {
  64. for (var j = 0; j < productArr.length; j++) {
  65. if (i == productArr[j]) {
  66. buttons[i].click();
  67. await sleep(50);
  68. const download = document.querySelector("li[id$=item-0]");
  69. download.click();
  70. await modal();
  71. await sleep(50);
  72. }
  73. }
  74. }
  75. }
  76.  
  77. var outputTxt;
  78. for (var k = 0; k < urlArr.length; k++) {
  79. log("urlArr["+k+"]" + urlArr[k]);
  80. if(k == 0){
  81. outputTxt = urlArr[k];
  82. /*
  83. outputTxt.push(urlArr[k]);
  84. outputTxt.push("\n");
  85. */
  86. } else {
  87. outputTxt = outputTxt + "\n" + urlArr[k];
  88. }
  89. }
  90.  
  91. const urlData = window.location.href.split("/");
  92. const productID = urlData[urlData.length-1];
  93.  
  94. saveLocalFile(outputTxt, productID + "_urls.txt");
  95. }
  96.  
  97. async function modal() {
  98. const modal = document.querySelector(".node_modules--redbubble-design-system-react-Modal-ModalCard-styles__card--zujT9");
  99. await sleep(2000); //Wait for modal to load
  100. var productTitle = $(".node_modules--redbubble-design-system-react-Box-styles__box--206r9.node_modules--redbubble-design-system-react-Text-styles__text--NLf2i.node_modules--redbubble-design-system-react-Text-styles__display2--3ZwPH.node_modules--redbubble-design-system-react-Box-styles__display-block--2XANJ").text();
  101. log("Product #" + productNum + " | " + productTitle);
  102. const images = modal.querySelector("img");
  103. const sourceImg = images.getAttribute("src");
  104. urlArr.push(sourceImg);
  105. const close = document.querySelector("button[aria-label='Dismiss modal']");
  106. close.click();
  107. productNum++;
  108. }
  109.  
  110. //When script loads run();
  111. run();