| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| var Setup_DownloadAllExceptInPlace = true; |
| var Setup_DownloadOnlyInPlace = false; |
| var Setup_DownloadOnlyRoot = false; |
|
|
| var Setup_DownloadOnlyInPlace_Mirrored = false; |
| var Setup_DownloadAllExceptInPlace_Mirrored = false; |
| var Setup_DownloadOnlyRoot_Mirrored = false; |
|
|
|
|
| |
|
|
| var debugVerbose = true; |
| var debugMaxIndex = 0; |
| var debugStopAfterPage = 999; |
| var debugNoPageTurn = false; |
| var setupGlobalTimeOffset = 0; |
| var setupTimeModifier = 2; |
| var setupDefaultDelay = 500; |
| var setupPlaySounds = true; |
| var setupBeepOnAdd = false; |
| var setupBeepOnPage = true; |
| var TimeToReloadPage = 10000; |
|
|
| |
|
|
| var pageURL = "https://www.mixamo.com/#/?type=Motion%2CMotionPack"; |
| var setupElementID_Products = "product"; |
| var setupElementID_Download = "btn-block btn btn-primary"; |
| var setupElementID_DownloadConfirm = "btn btn-primary"; |
| var setupElementID_InPlace = "inplace"; |
| var setupElementID_Mirror = "mirror"; |
| var setupElementID_Products = "product"; |
| var setupElementID_Pagination = ".pagination li:nth-last-child(2) a"; |
| var setupElementID_DownloadCaption = "Download"; |
| var DownloadPending_Regular = downloadRegularVariant; |
| var DownloadPending_Mirror = downloadMirrorVariant; |
| var DownloadPending_InPlace = downloadInPlaceVariant; |
| var DownloadPending_InPlaceMirror = downloadInPlaceMirrorVariant; |
| var timeEnd = 0, timeStart = 0; |
| var scriptPaused = true; |
| var index = -1; |
| var debugFailedStart = 0; |
| var pageNum = geUrlPageNum(); |
| var itemsPerPage = geUrlLimit(); |
| var NumOfFilesProcessed = 0; |
| var buttonClicked = 0; |
| var retryCounter = 0; |
| var button = document.querySelector( "setupElementID_AddToAssets" ); |
| var items = document.getElementsByClassName( setupElementID_Products ); |
|
|
| var pageMax = 5; |
| var downloadRegularVariant = true; |
| var download_RootExclude = false; |
| var download_RootExclussive = false; |
| var download_RootMirrored = false; |
| var downloadMirrorVariant = true; |
| var downloadInPlaceVariant = true; |
| var downloadInPlaceMirrorVariant = true; |
|
|
| function DownloadAllExceptInPlace(){ |
| |
| downloadRegularVariant = true; |
| download_RootExclude = true; |
| download_RootExclussive = false; |
| download_RootMirrored = false; |
| downloadMirrorVariant = false; |
| downloadInPlaceVariant = true; |
| downloadInPlaceMirrorVariant = false; |
| } |
|
|
| function DownloadAllExceptInPlace_Mirrored(){ |
| |
| downloadRegularVariant = true; |
| download_RootExclude = true; |
| download_RootExclussive = false; |
| download_RootMirrored = true; |
| downloadMirrorVariant = false; |
| downloadInPlaceVariant = false; |
| downloadInPlaceMirrorVariant = false; |
| } |
|
|
| function DownloadOnlyInPlace(){ |
| |
| downloadRegularVariant = false; |
| download_RootExclude = false; |
| download_RootExclussive = false; |
| download_RootMirrored = false; |
| downloadMirrorVariant = false; |
| downloadInPlaceVariant = true; |
| downloadInPlaceMirrorVariant = false; |
| } |
|
|
| function DownloadOnlyInPlace_Mirrored(){ |
| |
| downloadRegularVariant = false; |
| download_RootExclude = false; |
| download_RootExclussive = false; |
| download_RootMirrored = false; |
| downloadMirrorVariant = false; |
| downloadInPlaceVariant = false; |
| downloadInPlaceMirrorVariant = true; |
| } |
|
|
| function DownloadOnlyRoot(){ |
| |
| downloadRegularVariant = true; |
| download_RootExclude = false; |
| download_RootExclussive = true; |
| download_RootMirrored = false; |
| downloadMirrorVariant = false; |
| downloadInPlaceVariant = false; |
| downloadInPlaceMirrorVariant = false; |
| } |
|
|
| function DownloadOnlyRoot_Mirrored(){ |
| |
| downloadRegularVariant = true; |
| download_RootExclude = false; |
| download_RootExclussive = true; |
| download_RootMirrored = true; |
| downloadMirrorVariant = false; |
| downloadInPlaceVariant = false; |
| downloadInPlaceMirrorVariant = false; |
| } |
|
|
| function geUrlLimit(){ |
| var result = getUrlVars()["limit"]; |
| if (result && debugVerbose) console.log(result); |
| else { |
| if (debugVerbose) console.log("[DEBUG] geUrlLimit :: param LIMIT not found."); |
| result = "96"; |
| } |
| return result; |
| } |
|
|
| function isAnimPack(){ |
| var str = getAnimName(); |
| str = str.toLowerCase(); |
| var n = str.search(" pack"); |
| return ( n > -1 ); |
| } |
|
|
| var DownloadPending_Any = true; |
| function incIndex(){ |
| if (debugVerbose) console.log("[DEBUG] incIndex :: Start; index:",index); |
| ++index; |
| ++NumOfFilesProcessed; |
| buttonClicked = 0; |
|
|
| DownloadPending_Regular = downloadRegularVariant; |
| DownloadPending_Mirror = downloadMirrorVariant; |
| DownloadPending_InPlace = downloadInPlaceVariant; |
| DownloadPending_InPlaceMirror = downloadInPlaceMirrorVariant; |
| DownloadPending_Any = true; |
|
|
| if (debugVerbose) console.log("[DEBUG] incIndex :: End; index:",index); |
|
|
| if (onProcessElement()) |
| setTimeout(processElement, 2000 ); |
| } |
|
|
| function getUrlVars() { |
| var vars = {}; |
| var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, |
| function(m,key,value) { |
| vars[key] = value; |
| }); |
| return vars; |
| } |
|
|
| function geUrlPageNum(){ |
| var result = getUrlVars()["page"]; |
| if (result && debugVerbose) console.log(result); |
| else { |
| if (debugVerbose) console.log("[DEBUG]param PAGE not found."); |
| result = 1; |
| } |
| return result; |
| } |
|
|
| function timeMod( time1 ){ |
| var baseTime = time1 * setupDefaultDelay; |
| var t = ((baseTime)*setupTimeModifier) + setupGlobalTimeOffset; |
| if (t < baseTime*0.1) t = baseTime*0.1; |
| if (t > baseTime*10) t = baseTime*10; |
| return t; |
| } |
|
|
| function reloadPage() { |
| if (debugVerbose) console.log("[DEBUG] reloadPage :: Start; index:",index); |
| scriptPaused = true; |
|
|
| if (pageNum >= debugStopAfterPage) { |
| return; |
| } |
|
|
|
|
| var newUrl = ""; |
| newUrl = pageURL + "&limit=" + itemsPerPage + "&page=" + pageNum.toString(); |
|
|
| if (debugVerbose) console.log("[DEBUG] reloadPage :: ",newUrl); |
| document.location.href = newUrl; |
|
|
| setTimeout( mixamoScript, 2000 ); |
| } |
|
|
| function onFinish(){ |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
|
|
| if (!audioCtx) var audioCtx = new (window.AudioContext || window.webkitAudioContext || window.audioContext); |
| function beep(duration, frequency, volume, type, callback) { |
| if (!setupPlaySounds) return; |
|
|
| var oscillator = audioCtx.createOscillator(); |
| var gainNode = audioCtx.createGain(); |
|
|
| oscillator.connect(gainNode); |
| gainNode.connect(audioCtx.destination); |
|
|
| if (volume){gainNode.gain.value = volume;}; |
| if (frequency){oscillator.frequency.value = frequency;} |
| if (type){oscillator.type = type;} |
| if (callback){oscillator.onended = callback;} |
|
|
| oscillator.start(); |
| setTimeout(function(){oscillator.stop()}, (duration ? duration : 500)); |
| } |
|
|
| function soundOnPageEnd(){ |
|
|
| setTimeout(function(){ beep(500, 500, 0.060, "triangle") }, 0); |
| setTimeout(function(){ beep(500, 550, 0.035, "triangle") }, 600); |
| setTimeout(function(){ beep(500, 600, 0.020, "triangle") }, 1200); |
| setTimeout(function(){ beep(500, 650, 0.005, "triangle") }, 1800); |
| } |
|
|
| function beepOnAdd(){ |
| if (debugVerbose) console.log("[DEBUG] beepOnAdd :: Start; index:",index); |
| beep(225, 200, 0.3, "triangle"); |
| } |
|
|
|
|
| |
| function printToLogCurrItems(){ |
|
|
| } |
|
|
| function onEndOfPage() { |
| if (debugVerbose) console.log("[DEBUG] onEndOfPage :: Start; index:",index); |
| scriptPaused = true; |
|
|
| var t = 0; |
| if (setupBeepOnPage) { |
| t = 1000; |
| setTimeout(soundOnPageEnd, 0); |
| } |
|
|
| |
| if (pageNum >= debugStopAfterPage) { |
| setTimeout( onFinish, 2000 ); |
| if (debugVerbose) console.log("[DEBUG] onEndOfPage_Assets :: Start; pageNum:",pageNum,"; debugStopAfterPage:",debugStopAfterPage); |
| return; |
| } else { |
| if (!debugNoPageTurn) { |
| index = 0; |
| ++pageNum; |
| setTimeout(reloadPage, TimeToReloadPage); |
| } |
| } |
|
|
| } |
|
|
| function isDownloadInProgress(){ |
| var elements = document.getElementsByClassName( "progress-bar" ); |
| if (elements && elements.length>0) |
| { |
| console.log("[DEBUG] Download In Progress"); |
| return true; |
| } else { |
| console.log("[DEBUG] Download Not In Progress"); |
| return false; |
| } |
| } |
|
|
| function onProcessElement() { |
| if (debugVerbose) console.log("[DEBUG] onProcessElement :: start; index:",index); |
|
|
| if (!items || items.length == 0) { |
| if (debugVerbose) console.log("[DEBUG] onProcessElement :: items; index:",index); |
| items = document.getElementsByClassName( setupElementID_Products ); |
| } |
| if (!button) { |
| if (debugVerbose) console.log("[DEBUG] onProcessElement :: button; index:",index); |
| |
| var buttons = document.getElementsByClassName( setupElementID_Download ); |
| if (buttons && buttons.length>0) |
| button = buttons[0]; |
| } |
| if (items.length != 0) { |
| |
| if(index >= items.length) { |
| |
| onEndOfPage(); |
| return true; |
| } |
| items[index].click(); |
|
|
| if (debugVerbose) console.log("[DEBUG] onProcessElement :: Clicked"); |
| return true; |
| } |
|
|
| return false; |
| } |
|
|
| function getAnimName(){ |
| if (debugVerbose) console.log("[DEBUG] getAnimName :: Start; index:",index); |
| var element = document.getElementsByClassName( "text-center h5" ); |
| if (element && element.length>0) { |
| if (debugVerbose) console.log("[DEBUG] getAnimName :: name:",element[0].textContent,"; Start; index:",index); |
| return element[0].textContent; |
| } |
| if (debugVerbose) console.log("[DEBUG] getAnimName :: Failed; Start; index:",index); |
| return "[]"; |
| } |
|
|
| function confirmDownload(){ |
| if (debugVerbose) console.log("[DEBUG] confirmDownload :: start; index:",index); |
| var buttons = document.getElementsByClassName( setupElementID_DownloadConfirm ); |
| if (buttons && buttons.length>1) { |
| buttons[1].click(); |
|
|
| if (debugVerbose) console.log("[DEBUG] confirmDownload :: Button Clicked"); |
|
|
| setTimeout( processElementEx, 1000 ); |
| } else if (debugVerbose) console.log("[DEBUG] confirmDownload :: Button Not Found"); |
| } |
|
|
| function initAnimDownload() { |
| if (debugVerbose) console.log("[DEBUG] initAnimDownload :: Start; Index:",index); |
|
|
| var currAnim = getAnimName(); |
| if (debugVerbose) console.log("[DEBUG] initAnimDownload :: Anim: ",currAnim,"; index:",index); |
|
|
| |
| if (button.textContent == setupElementID_DownloadCaption) { |
| if (buttonClicked == 0) { |
| button.click(); |
|
|
| |
| |
| if (setupBeepOnAdd) beepOnAdd(); |
|
|
| setTimeout( confirmDownload, 1000); |
|
|
| if (debugVerbose) console.log("[DEBUG] initAnimDownload :: Added To Assets; buttonClicked:",buttonClicked); |
| return true; |
| } |
| } else { |
| if (debugVerbose) console.log("[DEBUG] initAnimDownload :: button.textContent:",button.textContent); |
| return false; |
|
|
| } |
| if (debugVerbose) console.log("[DEBUG] initAnimDownload :: end"); |
| } |
|
|
| function checkElement(elementName, desiredState) { |
| var element = document.getElementsByName(elementName); |
| if (element.length != 0) { |
| if (element[0].checked != desiredState) { |
| if (debugVerbose) console.log("[DEBUG] checkElement :: Clicked; previous state:",element[0].checked,"; elementName:",elementName,"; desiredState:",desiredState); |
| element[0].click(); |
| } else if (debugVerbose) console.log("[DEBUG] checkElement :: Element already has desired state; elementName:",elementName,"; desiredState:",desiredState); |
|
|
| return true; |
| } |
| if (debugVerbose) console.log("[DEBUG] checkElement :: Element not found; elementName:",elementName,"; desiredState:",desiredState); |
|
|
| return false; |
| } |
|
|
| function isElementChecked(elementName, desiredState) { |
| var element = document.getElementsByName(elementName); |
| if (element.length != 0) { |
| if (debugVerbose) console.log("[DEBUG] isElementChecked :: elementName: ",elementName,"; desiredState: ",desiredState,"; current state:",element[0].checked,"; items found: ",element.length); |
| if (element[0].checked != desiredState) { |
| if (debugVerbose) console.log("[DEBUG] isElementChecked :: return: 0"); |
| return 0; |
| } else { |
| if (debugVerbose) console.log("[DEBUG] isElementChecked :: return: 1"); |
| return 1; |
| } |
| } |
| if (debugVerbose) console.log("[DEBUG] isElementChecked :: Element not found; elementName:",elementName,"; desiredState:",desiredState); |
| return -1; |
| } |
|
|
| var waitingForDownloadToComplete = false; |
| function processElement() { |
| if (debugVerbose) console.log("[DEBUG] processElement :: start; index:",index); |
|
|
| if (isDownloadInProgress()) { |
| |
| waitingForDownloadToComplete = true; |
| setTimeout(processElement, 500 ); |
| return; |
| } |
|
|
| if (waitingForDownloadToComplete === true){ |
| |
| waitingForDownloadToComplete = false; |
| setTimeout(processElement, 1000 ); |
| return; |
| } |
|
|
| if (debugMaxIndex > 0 && NumOfFilesProcessed >= debugMaxIndex) { |
| if (debugVerbose) console.log("[DEBUG] processElement :: debugMaxIndex:",debugMaxIndex,"; onFinish"); |
| onFinish(); |
| return; |
| } |
|
|
| if ( scriptPaused ) return; |
|
|
| retryCounter = 0; |
|
|
| setTimeout(processElementEx, timeMod( 1 )); |
|
|
| if (debugVerbose) console.log("[DEBUG] processElement :: End"); |
| } |
|
|
| function processElementEx(){ |
| if (debugVerbose) { |
| console.log("[DEBUG] processElementEx :: DownloadPending_Regular: ",DownloadPending_Regular); |
| console.log("[DEBUG] processElementEx :: DownloadPending_Mirror: ",DownloadPending_Mirror); |
| console.log("[DEBUG] processElementEx :: DownloadPending_InPlace: ",DownloadPending_InPlace); |
| console.log("[DEBUG] processElementEx :: DownloadPending_InPlaceMirror: ",DownloadPending_InPlaceMirror); |
| } |
|
|
| if (!isAnimPack()) { |
| |
| if (DownloadPending_Regular) { |
| if (initAnimDownload_Regular() ) { |
| setTimeout(initAnimDownload, timeMod( 2 ) ); |
| if (debugVerbose) console.log("[DEBUG] processElementEx :: call initAnimDownload"); |
| } else { |
| setTimeout(processElementEx, timeMod( 1 ) ); |
| if (debugVerbose) console.log("[DEBUG] processElementEx :: call processElementEx"); |
| } |
| DownloadPending_Regular = false; |
| return; |
| } else if (DownloadPending_Mirror){ |
| setTimeout(initAnimDownload_Mirror, timeMod( 1 ) ); |
| if (debugVerbose) console.log("[DEBUG] processElementEx :: call initAnimDownload_Mirror"); |
| return; |
| } else if (DownloadPending_InPlace){ |
| setTimeout(initAnimDownload_InPlace, timeMod( 1 ) ); |
| if (debugVerbose) console.log("[DEBUG] processElementEx :: call initAnimDownload_InPlace"); |
| return; |
| } else if (DownloadPending_InPlaceMirror){ |
| setTimeout(initAnimDownload_InPlaceMirror, timeMod( 1 ) ); |
| if (debugVerbose) console.log("[DEBUG] processElementEx :: call initAnimDownload_InPlaceMirror"); |
| return; |
| } |
| } else { |
| if (debugVerbose) console.log("[DEBUG] processElementEx :: skipping Pack"); |
| } |
|
|
| if (debugVerbose) { |
| console.log("[DEBUG] processElementEx :: DownloadPending_Regular: ",DownloadPending_Regular); |
| console.log("[DEBUG] processElementEx :: DownloadPending_Mirror: ",DownloadPending_Mirror); |
| console.log("[DEBUG] processElementEx :: DownloadPending_InPlace: ",DownloadPending_InPlace); |
| console.log("[DEBUG] processElementEx :: DownloadPending_InPlaceMirror: ",DownloadPending_InPlaceMirror); |
| } |
|
|
| |
| setTimeout(incIndex, timeMod(2) ); |
| } |
|
|
| function initAnimDownload_Regular(){ |
| if (debugVerbose) console.log("[DEBUG] initAnimDownload_Regular :: Start"); |
| r1 = isElementChecked(setupElementID_Mirror, false); |
| r2 = isElementChecked(setupElementID_InPlace, false); |
|
|
| if (debugVerbose) console.log("[DEBUG] initAnimDownload_Regular :: R1: ",r1,", R2: ",r2); |
|
|
| if ((download_RootExclude===true && r2>-1) || (download_RootExclussive===true && r2<0)) { |
| if (debugVerbose) console.log("[DEBUG] initAnimDownload_Regular :: download_RootExclude: ",download_RootExclude); |
| if (debugVerbose) console.log("[DEBUG] initAnimDownload_Regular :: download_RootExclussive: ",download_RootExclussive); |
| return false; |
| } |
| if (download_RootMirrored===true) { |
| DownloadPending_Mirror = true; |
| return false; |
| } else { |
| return true; |
| } |
| } |
|
|
| function initAnimDownload_Mirror(){ |
| r1 = isElementChecked(setupElementID_Mirror, true); |
| r2 = isElementChecked(setupElementID_InPlace, false); |
|
|
| if (debugVerbose) console.log("[DEBUG] initAnimDownload_Mirror :: R1: ",r1,", R2: ",r2); |
|
|
| if (r1 === -1) { |
| |
| DownloadPending_Mirror = false; |
| setTimeout(processElementEx, timeMod( 1 ) ); |
| } else if (r1===0 || r2===0) { |
| |
| if (r1===0) checkElement(setupElementID_Mirror, true); |
| if (r2===0) checkElement(setupElementID_InPlace, false); |
| setTimeout(processElementEx, timeMod( 1 ) ); |
| } else { |
| |
| setTimeout(initAnimDownload, timeMod( 2 ) ); |
| DownloadPending_Mirror = false; |
| } |
| } |
|
|
| function initAnimDownload_InPlace(){ |
| |
| r1 = isElementChecked(setupElementID_InPlace, false); |
| r2 = isElementChecked(setupElementID_Mirror, false); |
|
|
| if (debugVerbose) console.log("[DEBUG] initAnimDownload_InPlace :: R1: ",r1,", R2: ",r2); |
|
|
| if (r1 === -1) { |
| |
| DownloadPending_InPlace = false; |
| setTimeout(processElementEx, timeMod( 1 ) ); |
| } else if (r1===0 || r2===0) { |
| |
| |
| if (r1===0) checkElement(setupElementID_InPlace, false); |
| if (r2===0) checkElement(setupElementID_Mirror, false); |
| setTimeout(processElementEx, timeMod( 1 ) ); |
| } else { |
| |
| setTimeout(initAnimDownload, timeMod( 2 ) ); |
| DownloadPending_InPlace = false; |
| } |
| } |
|
|
| function initAnimDownload_InPlaceMirror(){ |
| r1 = isElementChecked(setupElementID_InPlace, true); |
| r2 = isElementChecked(setupElementID_Mirror, true); |
|
|
| if (debugVerbose) console.log("[DEBUG] initAnimDownload_InPlaceMirror :: R1: ",r1,", R2: ",r2); |
|
|
| if (r1 === -1 || r2 === -1) { |
| |
| DownloadPending_InPlaceMirror = false; |
| setTimeout(processElementEx, timeMod( 1 ) ); |
| } else if (r1===0 || r2===0) { |
| |
| if (r1===0) checkElement(setupElementID_InPlace, true); |
| if (r2===0) checkElement(setupElementID_Mirror, true); |
| setTimeout(processElementEx, timeMod( 1 ) ); |
| } else { |
| |
| setTimeout(initAnimDownload, timeMod( 2 ) ); |
| DownloadPending_InPlaceMirror = false; |
| } |
| } |
|
|
| function mixamoScript(){ |
| timeStart = Date.now(); |
|
|
| if (debugVerbose) console.log("[DEBUG] mixamoScript :: Start; index:",index); |
| var pagination = document.querySelector(setupElementID_Pagination); |
| if (pagination) pageMax = parseInt(pagination.textContent, 10); |
| else pageMax = 1; |
|
|
| scriptPaused = false; |
| items = document.getElementsByClassName( setupElementID_Products ); |
|
|
| index = -1; |
|
|
| |
| if (items.length == 0) { |
| ++debugFailedStart; |
| if (debugFailedStart > 2) { |
| reloadPage(); |
| return; |
| } |
| setTimeout(mixamoScript, 2000 ); |
| return; |
| } |
| debugFailedStart = 0; |
|
|
| |
| incIndex(); |
| |
| } |
|
|
| if (Setup_DownloadAllExceptInPlace===true) DownloadAllExceptInPlace(); |
| else if (Setup_DownloadAllExceptInPlace_Mirrored===true) DownloadAllExceptInPlace_Mirrored(); |
| else if (Setup_DownloadOnlyInPlace===true) DownloadOnlyInPlace(); |
| else if (Setup_DownloadOnlyInPlace_Mirrored===true) DownloadOnlyInPlace_Mirrored(); |
| else if (Setup_DownloadOnlyRoot===true) DownloadOnlyRoot(); |
| else if (Setup_DownloadOnlyRoot_Mirrored===true) DownloadOnlyRoot_Mirrored(); |
|
|
| mixamoScript(); |