88 lines
2.7 KiB
JavaScript
88 lines
2.7 KiB
JavaScript
const config = window.SeasonalsPluginConfig?.MarioDay || {};
|
|
const marioday = config.EnableMarioDay !== undefined ? config.EnableMarioDay : true;
|
|
|
|
let msgPrinted = false;
|
|
|
|
function toggleMarioDay() {
|
|
const container = document.querySelector('.marioday-container');
|
|
if (!container) return;
|
|
|
|
const videoPlayer = document.querySelector('.videoPlayerContainer');
|
|
const trailerPlayer = document.querySelector('.youtubePlayerContainer');
|
|
const isDashboard = document.body.classList.contains('dashboardDocument');
|
|
const hasUserMenu = document.querySelector('#app-user-menu');
|
|
|
|
if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) {
|
|
container.style.display = 'none';
|
|
if (!msgPrinted) {
|
|
console.log('MarioDay hidden');
|
|
msgPrinted = true;
|
|
}
|
|
} else {
|
|
container.style.display = 'block';
|
|
if (msgPrinted) {
|
|
console.log('MarioDay visible');
|
|
msgPrinted = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
const observer = new MutationObserver(toggleMarioDay);
|
|
observer.observe(document.body, {
|
|
childList: true,
|
|
subtree: true,
|
|
attributes: true
|
|
});
|
|
|
|
|
|
function createMarioDay(container) {
|
|
// MARK: Mario's running speed across the screen
|
|
const marioSpeedSeconds = 18;
|
|
|
|
const wrapper = document.createElement('div');
|
|
wrapper.className = 'mario-wrapper';
|
|
wrapper.style.animationDuration = `${marioSpeedSeconds}s`;
|
|
|
|
const mario = document.createElement('img');
|
|
mario.className = 'mario-runner';
|
|
mario.src = '../Seasonals/Resources/mario_assets/mario.gif';
|
|
|
|
wrapper.appendChild(mario);
|
|
container.appendChild(wrapper);
|
|
|
|
// Periodically throw out an 8-bit coin
|
|
const intervalId = setInterval(() => {
|
|
if (!document.body.contains(container)) { clearInterval(intervalId); return; }
|
|
if (container.style.display === 'none') return;
|
|
const coin = document.createElement('div');
|
|
coin.className = 'mario-coin';
|
|
|
|
// Grab Mario's current screen position to lock the coin's X coordinate
|
|
const marioRect = wrapper.getBoundingClientRect();
|
|
coin.style.left = `${marioRect.left + 16}px`;
|
|
coin.style.bottom = '35px'; // bottom offset
|
|
|
|
container.appendChild(coin);
|
|
setTimeout(() => coin.remove(), 2000);
|
|
|
|
}, 4000);
|
|
}
|
|
|
|
|
|
function initializeMarioDay() {
|
|
if (!marioday) return;
|
|
|
|
const container = document.querySelector('.marioday-container') || document.createElement("div");
|
|
|
|
if (!document.querySelector('.marioday-container')) {
|
|
container.className = "marioday-container";
|
|
container.setAttribute("aria-hidden", "true");
|
|
document.body.appendChild(container);
|
|
}
|
|
|
|
createMarioDay(container);
|
|
toggleMarioDay();
|
|
}
|
|
|
|
initializeMarioDay();
|