Closed schulle334 closed 2 months ago
Maybe it works so that the closed realms are displayed, but I can't test it at the moment
// Function to filter the events
function filterEvents(userSettings) {
const { minScore, minPopulation, timeLimitMinutes } = userSettings;
const events = document.querySelectorAll('.realmstock-panel.event');
const seenEvents = new Set();
const currentTime = new Date();
events.forEach(event => {
const scoreElement = event.querySelector('.event-score');
const populationElement = event.querySelector('.event-population');
const titleElement = event.querySelector('.event-title');
const serverElement = event.querySelector('.event-server');
const timeElement = event.querySelector('.event-time');
// Check that the elements exist
if (scoreElement && populationElement && titleElement && serverElement && timeElement) {
// Extract event details
const scoreText = scoreElement.textContent.trim();
const scoreMatch = scoreText.match(/Score:\s*(\d+)%/);
const score = scoreMatch ? parseInt(scoreMatch[1], 10) : 0;
const populationText = populationElement.textContent.trim();
const populationMatch = populationText.match(/(\d+)\/(\d+)/);
const currentPopulation = populationMatch ? parseInt(populationMatch[1], 10) : 0;
const maxPopulationValue = populationMatch ? parseInt(populationMatch[2], 10) : 0;
const eventTimeText = timeElement.textContent.trim();
const [eventHours, eventMinutes] = eventTimeText.split(':').map(num => parseInt(num, 10));
const eventTime = new Date(currentTime);
eventTime.setHours(eventHours);
eventTime.setMinutes(eventMinutes);
eventTime.setSeconds(0);
const timeDifference = (currentTime - eventTime) / (1000 * 60); // in minutes
const eventKey = `${titleElement.textContent.trim()}-${serverElement.textContent.trim()}-${currentPopulation}/${maxPopulationValue}`;
// Check if the event is "Realm Closed"
const isRealmClosed = titleElement.textContent.trim() === "Realm Closed";
// Logic to determine if event should be displayed
if (isRealmClosed) {
// Always display "Realm Closed" events
event.style.display = 'block';
} else {
// Apply filtering for non-"Realm Closed" events
const shouldHideEvent = timeDifference > timeLimitMinutes ||
seenEvents.has(eventKey) ||
score < minScore ||
currentPopulation < minPopulation ||
maxPopulationValue !== 85;
// Toggle visibility based on filters
if (shouldHideEvent) {
event.style.display = 'none';
} else {
event.style.display = 'block';
seenEvents.add(eventKey);
}
}
} else {
console.warn('One or more required elements are missing:', {
scoreElement,
populationElement,
titleElement,
serverElement,
timeElement
});
}
});
}
Current problems that could be solved, but I don't have the time or brainpower.