|
// Close Button Monitor Mod for Bestiary Arena |
|
// Developed by Manus |
|
|
|
console.log("Close Button Monitor initializing..."); |
|
|
|
// --- Configuration --- |
|
const CHECK_INTERVAL = 1000; // Check for the button every 1 second |
|
const CLICK_DELAY = 3000; // Click the button if it's visible for 3 seconds |
|
|
|
// --- State --- |
|
let closeButtonTimer = null; |
|
let lastButtonFound = null; |
|
|
|
// --- Helper Functions --- |
|
|
|
// Function to find any button with the text "Fechar" |
|
const findCloseButton = () => { |
|
const text = document.documentElement.lang === 'pt' ? 'Fechar' : 'Close'; |
|
const buttons = document.querySelectorAll('button'); |
|
for (const button of buttons) { |
|
if (button.textContent.includes(text) && isElementVisible(button)) { |
|
return button; |
|
} |
|
} |
|
return null; |
|
}; |
|
|
|
// Function to check if an element is visible in the DOM |
|
const isElementVisible = (el) => { |
|
return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length); |
|
}; |
|
|
|
// --- Main Logic --- |
|
|
|
// This function checks for the close button and decides whether to click it |
|
const monitorCloseButton = () => { |
|
const closeButton = findCloseButton(); |
|
|
|
if (closeButton) { |
|
// If we just found the button for the first time, start a timer |
|
if (!closeButtonTimer) { |
|
console.log("[Close Monitor] 'Fechar' button detected. Starting 3-second timer..."); |
|
lastButtonFound = closeButton; |
|
closeButtonTimer = setTimeout(() => { |
|
// After 3 seconds, check if the *same* button is still visible |
|
if (lastButtonFound && isElementVisible(lastButtonFound)) { |
|
console.log("[Close Monitor] 'Fechar' button has been visible for 3 seconds. Clicking it now."); |
|
lastButtonFound.click(); |
|
} |
|
// Reset the timer |
|
closeButtonTimer = null; |
|
lastButtonFound = null; |
|
}, CLICK_DELAY); |
|
} |
|
} else { |
|
// If the button is no longer visible, clear the timer |
|
if (closeButtonTimer) { |
|
console.log("[Close Monitor] 'Fechar' button disappeared. Canceling timer."); |
|
clearTimeout(closeButtonTimer); |
|
closeButtonTimer = null; |
|
lastButtonFound = null; |
|
} |
|
} |
|
}; |
|
|
|
// --- Initialization --- |
|
|
|
function init() { |
|
console.log("[Close Monitor] Starting to monitor for 'Fechar' button..."); |
|
// Start the monitoring loop |
|
setInterval(monitorCloseButton, CHECK_INTERVAL); |
|
|
|
// Add a simple UI button to show the mod is active |
|
api.ui.addButton({ |
|
id: 'close-button-monitor-mod', |
|
text: '', |
|
icon: ' क्ल ', // Using a less common character to represent 'close' |
|
modId: 'close-button-monitor', |
|
tooltip: 'Close Button Monitor is active', |
|
primary: false |
|
}); |
|
} |
|
|
|
// Run the initialization function |
|
init(); |
|
|
|
|