Skip to content

Instantly share code, notes, and snippets.

@vieitasraphael
Created July 10, 2025 04:47
Show Gist options
  • Save vieitasraphael/73fffa5edafd545a870ed459b245186f to your computer and use it in GitHub Desktop.
Save vieitasraphael/73fffa5edafd545a870ed459b245186f to your computer and use it in GitHub Desktop.
Bestiary Arena Mod: Automatically clicks "Fechar" button if visible for more than 3 seconds.
// 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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment