Add auto click Chest

Also a workaround for jQuery unbind mouseup event.
This commit is contained in:
tretrauit 2021-07-04 20:02:30 +00:00
parent c44116eee5
commit 01d4db7b8c

View File

@ -1,74 +1,78 @@
// TODO: FIX JQUERY ASYNC (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 {
// Fetch jQuery constructor(targetNode, classToWatch, classAddedCallback, classRemovedCallback) {
await fetch("https://code.jquery.com/jquery-3.6.0.min.js").then(x => x.text()).then(y => eval(y)).then(() => $("window").off("mouseup")) this.targetNode = targetNode
{ this.classToWatch = classToWatch
// From https://stackoverflow.com/a/53914092 this.classAddedCallback = classAddedCallback
class ClassWatcher { this.classRemovedCallback = classRemovedCallback
this.observer = null
this.lastClassState = targetNode.classList.contains(this.classToWatch)
constructor(targetNode, classToWatch, classAddedCallback, classRemovedCallback) { this.init()
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()
}
init() { observe() {
this.observer = new MutationObserver(this.mutationCallback) this.observer.observe(this.targetNode, { attributes: true })
this.observe() }
}
observe() { disconnect() {
this.observer.observe(this.targetNode, { attributes: true }) this.observer.disconnect()
} }
disconnect() { mutationCallback = mutationsList => {
this.observer.disconnect() for(let mutation of mutationsList) {
} if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
let currentClassState = mutation.target.classList.contains(this.classToWatch)
mutationCallback = mutationsList => { if(this.lastClassState !== currentClassState) {
for(let mutation of mutationsList) { this.lastClassState = currentClassState
if (mutation.type === 'attributes' && mutation.attributeName === 'class') { if(currentClassState) {
let currentClassState = mutation.target.classList.contains(this.classToWatch) this.classAddedCallback()
if(this.lastClassState !== currentClassState) { }
this.lastClassState = currentClassState else {
if(currentClassState) { this.classRemovedCallback()
this.classAddedCallback() }
}
else {
this.classRemovedCallback()
} }
} }
} }
} }
} }
}
function clickFirstButtonByClassName(className) { function clickFirstButtonByClassName(className) {
document.getElementsByClassName(className)[0].dispatchEvent(new MouseEvent("click")); document.getElementsByClassName(className)[0].dispatchEvent(new MouseEvent("click"));
} }
// Click the spin button // Click the spin button
function spin() { function spin() {
if (document.getElementsByClassName("popup-draw__card").length > 0) { if (document.getElementsByClassName("popup-draw__card").length > 0) {
let teams = document.getElementsByClassName("popup-draw__card") // Do pick random 3 cards instead of spin.
for (let i = 0; i < 3; i++) { let teams = document.getElementsByClassName("popup-draw__card")
teams[i].dispatchEvent(new MouseEvent("click")); for (let i = 0; i < 3; i++) {
teams[i].dispatchEvent(new MouseEvent("click"));
}
}
else {
// Spin
clickFirstButtonByClassName("wheel__main--note")
clickFirstButtonByClassName("chest")
} }
} }
else { // Close the dialog
clickFirstButtonByClassName("wheel__main--note") function closeSwal2() {
clickFirstButtonByClassName("swal2-close")
} }
}
// Close the dialog
function closeSwal2() {
clickFirstButtonByClassName("swal2-close")
}
// Watch for SweetAlert 2 // Watch for SweetAlert 2
let bodywatcher = new ClassWatcher(document.body, 'swal2-shown', closeSwal2, spin); new ClassWatcher(document.body, 'swal2-shown', closeSwal2, spin);
spin() spin()
} }
})();