Xaymar

Mixamo Add All Assets Script

Dec 23rd, 2015
6,928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var pageURL = document.location.protocol + "//" + document.location.host + document.location.pathname + "#/search?page=",
  2.     pageURLSuffix = "&limit=96&type=Motion%252CMotionPack",
  3.     pageNum = parseInt(document.querySelector(".pagination li.active a").textContent, 10),
  4.     pageMax = parseInt(document.querySelector(".pagination li:nth-last-child(2) a").textContent, 10);
  5. function MixamoScript() {
  6.     var items = document.getElementsByClassName("product");
  7.     if (items.length == 0) {
  8.         window.setTimeout(MixamoScript, 1000);
  9.         return;
  10.     }
  11.    
  12.     var killScript = setInterval(runAddToMyAssets, 250);
  13.     var button = document.querySelector(".add-to-cart"),
  14.         next = false,
  15.         index = 0,
  16.         isClicked = false;
  17.     console.log("MixamoScript: ", pageNum, "/", pageMax);
  18.    
  19.     function runAddToMyAssets() {
  20.         if (items.length == 0) {
  21.             items = document.getElementsByClassName("product");
  22.         }
  23.         if (button == null) {
  24.             button = document.querySelector(".add-to-cart");
  25.         }
  26.        
  27.         // Make sure we have items available to click.
  28.         if (items.length != 0) {
  29.             // Next Page
  30.             if(index >= items.length) {
  31.                 clearInterval(killScript);
  32.                 //nextButton.click();
  33.                
  34.                 if (pageNum >= pageMax) {
  35.                     window.removeEventListener("hashchange", MixamoScript);
  36.                     console.log("MixamoScript: Done.");
  37.                     return;
  38.                 } else {
  39.                     ++pageNum;
  40.                 }
  41.                 console.log("MixamoScript: ", pageNum, "/", pageMax);
  42.                
  43.                 document.location.href = pageURL + pageNum.toString() + pageURLSuffix;
  44.                 return;
  45.             }
  46.            
  47.             // Next Element
  48.             if (next) {
  49.                 ++index;
  50.             }
  51.            
  52.             // Click Element
  53.             if(!isClicked) {
  54.                 items[index].click();
  55.             }
  56.            
  57.             // Add Asset
  58.             addToMyAssets();
  59.         }
  60.         return;
  61.     }
  62.  
  63.     function addToMyAssets() {
  64.         next = false;
  65.         isClicked = true;
  66.         if(button.disabled == true) {
  67.             return;
  68.         }
  69.         if (button.textContent == "Add to My Assets") {
  70.             button.click();
  71.             next = true;
  72.             isClicked = false;
  73.             return;
  74.         }
  75.         if (button.textContent == "View / Download") {
  76.             next = true;
  77.             isClicked = false;
  78.         }
  79.     }
  80. }
  81. MixamoScript();
  82. window.addEventListener("hashchange", MixamoScript, false);
Advertisement
Add Comment
Please, Sign In to add comment