From 482114e66c1184403c65ddb027031f16e2d775c5 Mon Sep 17 00:00:00 2001 From: tretrauit <3550664-tretrauit@users.noreply.gitlab.com> Date: Sat, 3 Jul 2021 19:46:24 +0000 Subject: [PATCH] Add new file --- Games/Arena_of_Valor/AWC_AutoSpin.js | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Games/Arena_of_Valor/AWC_AutoSpin.js diff --git a/Games/Arena_of_Valor/AWC_AutoSpin.js b/Games/Arena_of_Valor/AWC_AutoSpin.js new file mode 100644 index 0000000..aa9d07d --- /dev/null +++ b/Games/Arena_of_Valor/AWC_AutoSpin.js @@ -0,0 +1,66 @@ +// 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) + + 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() { + clickFirstButtonByClassName("wheel__main--note") + } + // Close the dialog + function closeSwal2() { + clickFirstButtonByClassName("swal2-close") + } + + // Watch for SweetAlert 2 + let bodywatcher = new ClassWatcher(document.body, 'swal2-shown', closeSwal2, spin); + spin() +}