From 94bcf902087c493c6352724fdfe4d5684b4b75ff Mon Sep 17 00:00:00 2001 From: tretrauit <3550664-tretrauit@users.noreply.gitlab.com> Date: Mon, 5 Jul 2021 20:10:56 +0000 Subject: [PATCH] Use 'jQuery' instead of '$' That fixes jQuery thingy Also semi-fix card drawing thingy? --- Games/Arena_of_Valor/AWC_AutoSpin.js | 74 +++++++++++++++++----------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/Games/Arena_of_Valor/AWC_AutoSpin.js b/Games/Arena_of_Valor/AWC_AutoSpin.js index 8997b59..702aa03 100644 --- a/Games/Arena_of_Valor/AWC_AutoSpin.js +++ b/Games/Arena_of_Valor/AWC_AutoSpin.js @@ -1,13 +1,6 @@ // Fetch jQuery await fetch("https://code.jquery.com/jquery-3.6.0.min.js").then(x => x.text()).then(y => eval(y)) // Wait for jQuery to be loaded. -async function execjQuery() { - while (!window.jQuery) { - - } - $("window").off("mouseup") -} -execjQuery() { // From https://stackoverflow.com/a/53914092 class ClassWatcher { @@ -56,36 +49,61 @@ execjQuery() var disableChest = false function clickFirstButtonByClassName(className) { - document.getElementsByClassName(className)[0].dispatchEvent(new MouseEvent("click")); + let btn = document.getElementsByClassName(className)[0] + if (!(typeof btn === "undefined")) { + btn.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")); - } + clickFirstButtonByClassName("wheel__main--note") + if (!disableChest) { + clickFirstButtonByClassName("chest") } - else { - // Spin - clickFirstButtonByClassName("wheel__main--note") - if (!disableChest) { - clickFirstButtonByClassName("chest") - } - document.getElementById("widget2").dispatchEvent(new MouseEvent("click")); + document.getElementById("widget2").dispatchEvent(new MouseEvent("click")); + } + + function pickCard() { + let teams = document.getElementsByClassName("popup-draw__card") + for (let i = 0; i < 3; i++) { + teams[i].dispatchEvent(new MouseEvent("click")); } } - // Close the dialog - function closeSwal2() { - if (document.getElementsByClassName("popup-alert__message")[0].innerHTML == "Đã đạt đến giới hạn Rương đếm ngược hàng ngày") { - disableChest = true - } + // Check for dialog message then close + function closeSwalDialog() { clickFirstButtonByClassName("swal2-close") + if (document.getElementsByClassName("swal2-close").length > 0) { + setTimeout(closeSwalDialog, 100); + } + } + + function Swal2Dialog() { + if (document.getElementsByClassName("popup-draw__card").length > 0) { + pickCard() + } + else { + let swal2msg = document.getElementsByClassName("popup-alert__message") + if (swal2msg.length > 0) { + if (swal2msg[0].innerHTML == "Đã đạt đến giới hạn Rương đếm ngược hàng ngày") { + disableChest = true + } + else if (swal2msg[0].innerHTML == "Bạn đã hết lượt quay trong ngày") { + closeAutoFarm() + } + } + } + closeSwalDialog() } // Watch for SweetAlert 2 - new ClassWatcher(document.body, 'swal2-shown', closeSwal2, spin); - // ReactModal__Body--open + let swal2Watcher = new ClassWatcher(document.body, 'swal2-shown', Swal2Dialog, spin); + + function closeAutoFarm() { + swal2Watcher.disconnect() + } + spin() + + jQuery("window").off("mouseup") + jQuery("document").off("visibilitychange") }