From 01d4db7b8c3b777007c20f46214495f45834abd4 Mon Sep 17 00:00:00 2001 From: tretrauit <3550664-tretrauit@users.noreply.gitlab.com> Date: Sun, 4 Jul 2021 20:02:30 +0000 Subject: [PATCH] Add auto click Chest Also a workaround for jQuery unbind mouseup event. --- Games/Arena_of_Valor/AWC_AutoSpin.js | 132 ++++++++++++++------------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/Games/Arena_of_Valor/AWC_AutoSpin.js b/Games/Arena_of_Valor/AWC_AutoSpin.js index edaf5ea..af00d56 100644 --- a/Games/Arena_of_Valor/AWC_AutoSpin.js +++ b/Games/Arena_of_Valor/AWC_AutoSpin.js @@ -1,74 +1,78 @@ -// TODO: FIX JQUERY ASYNC - -// Fetch jQuery -await fetch("https://code.jquery.com/jquery-3.6.0.min.js").then(x => x.text()).then(y => eval(y)).then(() => $("window").off("mouseup")) -{ - // From https://stackoverflow.com/a/53914092 - class ClassWatcher { - - constructor(targetNode, classToWatch, classAddedCallback, classRemovedCallback) { - this.targetNode = targetNode - this.classToWatch = classToWatch - this.classAddedCallback = classAddedCallback - this.classRemovedCallback = classRemovedCallback - this.observer = null - this.lastClassState = targetNode.classList.contains(this.classToWatch) +(async function() { + // Fetch jQuery + await fetch("https://code.jquery.com/jquery-3.6.0.min.js").then(x => x.text()).then(y => eval(y)) + setTimeout(() => { $("window").off("mouseup") }, 1000) + { + // From https://stackoverflow.com/a/53914092 + class ClassWatcher { - this.init() - } - - init() { - this.observer = new MutationObserver(this.mutationCallback) - this.observe() - } - - observe() { - this.observer.observe(this.targetNode, { attributes: true }) - } - - disconnect() { - this.observer.disconnect() - } - - mutationCallback = mutationsList => { - for(let mutation of mutationsList) { - if (mutation.type === 'attributes' && mutation.attributeName === 'class') { - let currentClassState = mutation.target.classList.contains(this.classToWatch) - if(this.lastClassState !== currentClassState) { - this.lastClassState = currentClassState - if(currentClassState) { - this.classAddedCallback() - } - else { - this.classRemovedCallback() + constructor(targetNode, classToWatch, classAddedCallback, classRemovedCallback) { + this.targetNode = targetNode + this.classToWatch = classToWatch + this.classAddedCallback = classAddedCallback + this.classRemovedCallback = classRemovedCallback + this.observer = null + this.lastClassState = targetNode.classList.contains(this.classToWatch) + + this.init() + } + + init() { + this.observer = new MutationObserver(this.mutationCallback) + this.observe() + } + + observe() { + this.observer.observe(this.targetNode, { attributes: true }) + } + + disconnect() { + this.observer.disconnect() + } + + mutationCallback = mutationsList => { + for(let mutation of mutationsList) { + if (mutation.type === 'attributes' && mutation.attributeName === 'class') { + let currentClassState = mutation.target.classList.contains(this.classToWatch) + if(this.lastClassState !== currentClassState) { + this.lastClassState = currentClassState + if(currentClassState) { + this.classAddedCallback() + } + else { + this.classRemovedCallback() + } } } } } } - } - - function clickFirstButtonByClassName(className) { - document.getElementsByClassName(className)[0].dispatchEvent(new MouseEvent("click")); - } - // Click the spin button - function spin() { - if (document.getElementsByClassName("popup-draw__card").length > 0) { - let teams = document.getElementsByClassName("popup-draw__card") - for (let i = 0; i < 3; i++) { - teams[i].dispatchEvent(new MouseEvent("click")); + + function clickFirstButtonByClassName(className) { + document.getElementsByClassName(className)[0].dispatchEvent(new MouseEvent("click")); + } + // Click the spin button + function spin() { + if (document.getElementsByClassName("popup-draw__card").length > 0) { + // Do pick random 3 cards instead of spin. + let teams = document.getElementsByClassName("popup-draw__card") + for (let i = 0; i < 3; i++) { + teams[i].dispatchEvent(new MouseEvent("click")); + } + } + else { + // Spin + clickFirstButtonByClassName("wheel__main--note") + clickFirstButtonByClassName("chest") } } - else { - clickFirstButtonByClassName("wheel__main--note") + // Close the dialog + function closeSwal2() { + clickFirstButtonByClassName("swal2-close") } + + // Watch for SweetAlert 2 + new ClassWatcher(document.body, 'swal2-shown', closeSwal2, spin); + spin() } - // Close the dialog - function closeSwal2() { - clickFirstButtonByClassName("swal2-close") - } - - // Watch for SweetAlert 2 - let bodywatcher = new ClassWatcher(document.body, 'swal2-shown', closeSwal2, spin); - spin() -} +})();