Fix jQuery and chest clicking?
This commit is contained in:
parent
61bff36c5c
commit
be75abf7b3
@ -1,95 +1,91 @@
|
|||||||
(async function() {
|
// Fetch jQuery
|
||||||
// Fetch jQuery
|
await fetch("https://code.jquery.com/jquery-3.6.0.min.js").then(x => x.text()).then(y => eval(y))
|
||||||
let 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.
|
||||||
let meaningOfLife = false;
|
async function execjQuery() {
|
||||||
async function waitForJQuery(){
|
while (!window.jQuery) {
|
||||||
while (true) {
|
|
||||||
if ($ != null){
|
|
||||||
$("window").off("mouseup")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await null; // prevents app from hanging
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
waitForJQuery();
|
$("window").off("mouseup")
|
||||||
{
|
}
|
||||||
// From https://stackoverflow.com/a/53914092
|
execjQuery()
|
||||||
class ClassWatcher {
|
{
|
||||||
|
// 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)
|
||||||
|
|
||||||
constructor(targetNode, classToWatch, classAddedCallback, classRemovedCallback) {
|
this.init()
|
||||||
this.targetNode = targetNode
|
}
|
||||||
this.classToWatch = classToWatch
|
|
||||||
this.classAddedCallback = classAddedCallback
|
init() {
|
||||||
this.classRemovedCallback = classRemovedCallback
|
this.observer = new MutationObserver(this.mutationCallback)
|
||||||
this.observer = null
|
this.observe()
|
||||||
this.lastClassState = targetNode.classList.contains(this.classToWatch)
|
}
|
||||||
|
|
||||||
this.init()
|
observe() {
|
||||||
}
|
this.observer.observe(this.targetNode, { attributes: true })
|
||||||
|
}
|
||||||
init() {
|
|
||||||
this.observer = new MutationObserver(this.mutationCallback)
|
disconnect() {
|
||||||
this.observe()
|
this.observer.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
observe() {
|
mutationCallback = mutationsList => {
|
||||||
this.observer.observe(this.targetNode, { attributes: true })
|
for(let mutation of mutationsList) {
|
||||||
}
|
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
|
||||||
|
let currentClassState = mutation.target.classList.contains(this.classToWatch)
|
||||||
disconnect() {
|
if(this.lastClassState !== currentClassState) {
|
||||||
this.observer.disconnect()
|
this.lastClassState = currentClassState
|
||||||
}
|
if(currentClassState) {
|
||||||
|
this.classAddedCallback()
|
||||||
mutationCallback = mutationsList => {
|
}
|
||||||
for(let mutation of mutationsList) {
|
else {
|
||||||
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
|
this.classRemovedCallback()
|
||||||
let currentClassState = mutation.target.classList.contains(this.classToWatch)
|
|
||||||
if(this.lastClassState !== currentClassState) {
|
|
||||||
this.lastClassState = currentClassState
|
|
||||||
if(currentClassState) {
|
|
||||||
this.classAddedCallback()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.classRemovedCallback()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var disableChest = false
|
|
||||||
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")
|
|
||||||
if (!disableChest) {
|
|
||||||
clickFirstButtonByClassName("chest")
|
|
||||||
}
|
|
||||||
document.getElementById("widget2").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
|
|
||||||
}
|
|
||||||
clickFirstButtonByClassName("swal2-close")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch for SweetAlert 2
|
|
||||||
new ClassWatcher(document.body, 'swal2-shown', closeSwal2, spin);
|
|
||||||
spin()
|
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
|
var disableChest = false
|
||||||
|
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")
|
||||||
|
if (!disableChest) {
|
||||||
|
clickFirstButtonByClassName("chest")
|
||||||
|
}
|
||||||
|
document.getElementById("widget2").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
|
||||||
|
}
|
||||||
|
clickFirstButtonByClassName("swal2-close")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Watch for SweetAlert 2
|
||||||
|
new ClassWatcher(document.body, 'swal2-shown', closeSwal2, spin);
|
||||||
|
// ReactModal__Body--open
|
||||||
|
spin()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user