Thingiverse allow adding things to multiple collections

Enables the Collected button to be pressed to add an item to another collection - this additionally fixes the issue that the server does not update immediately once a thing has been removed from a collection, allowing you to immediately add to another one.

  1. // ==UserScript==
  2. // @name Thingiverse allow adding things to multiple collections
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Enables the Collected button to be pressed to add an item to another collection - this additionally fixes the issue that the server does not update immediately once a thing has been removed from a collection, allowing you to immediately add to another one.
  6. // @author H. J. Norden
  7. // @match https://www.thingiverse.com/thing:*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. let DONE = false;
  15.  
  16. function get_collected_btn() {
  17. if (DONE) return;
  18. for (let el of document.getElementsByTagName("a")) {
  19. if (el.innerHTML === "Collected") {
  20. return el.parentNode;
  21. }
  22. }
  23. }
  24.  
  25. function show_collection_window() {
  26. let el = document.getElementsByClassName("SidebarMenu__collectWindowWrapper--2dRST")[0];
  27. el.classList.remove("CollectThingWindow__hidden--OSA7G");
  28. }
  29.  
  30. function hide_collection_window() {
  31. let el = document.getElementsByClassName("SidebarMenu__collectWindowWrapper--2dRST")[0];
  32. el.classList.add("CollectThingWindow__hidden--OSA7G");
  33. }
  34.  
  35. function fix_collection_window_closing() {
  36. let close_btn = document.getElementsByClassName("CollectThingWindow__closeImageWraper--2oYuJ")[0];
  37. let save_btn = document.getElementsByClassName("CollectThingWindow__buttonWrapper--1rp4p")[0];
  38. close_btn.addEventListener("click", hide_collection_window);
  39. save_btn.addEventListener("click", hide_collection_window);
  40. }
  41.  
  42. function enable_collection(from_button) {
  43. if (DONE) return;
  44. if (from_button === undefined) {
  45. console.log("Couldn't find 'Collected' button!");
  46. return;
  47. }
  48.  
  49. fix_collection_window_closing();
  50.  
  51. from_button.classList.remove("SideMenuItem__itemDisabled--pGJ7S");
  52. from_button.addEventListener("click", show_collection_window);
  53.  
  54. DONE = true;
  55. }
  56.  
  57.  
  58. // Try multiple timeouts for different network conditions...
  59. setTimeout(function(){enable_collection(get_collected_btn());}, 100);
  60. setTimeout(function(){enable_collection(get_collected_btn());}, 500);
  61. setTimeout(function(){enable_collection(get_collected_btn());}, 2000);
  62. setTimeout(function(){enable_collection(get_collected_btn());}, 5000);
  63.  
  64. })();