// IIFE to avoid polluting global scope (function() { // Wait for the DOM to be fully loaded document.addEventListener('DOMContentLoaded', function() { constCLASS_NAME = 'fullscreen-mode'; constSTORAGE_KEY = 'theme_fullscreen_mode'; constBUTTON_ID = 'fullscreen-toggle-btn';
// Find the container for the button const rightsideConfig = document.getElementById('rightside-config-hide');
// If the container doesn't exist, do nothing if (!rightsideConfig) { return; }
// Add the button to the page rightsideConfig.appendChild(button);
// --- 2. Function to apply the mode --- constapplyMode = (isFullScreen) => { if (isFullScreen) { document.body.classList.add(CLASS_NAME); button.innerHTML = '<i class="fas fa-compress"></i>'; // Change icon to "compress" } else { document.body.classList.remove(CLASS_NAME); button.innerHTML = '<i class="fas fa-expand"></i>'; // Change icon to "expand" } };
// --- 3. Add click event listener to the button --- button.addEventListener('click', () => { const isCurrentlyFullScreen = document.body.classList.contains(CLASS_NAME); // Toggle the mode and save the new state applyMode(!isCurrentlyFullScreen); localStorage.setItem(STORAGE_KEY, !isCurrentlyFullScreen); });
// --- 4. Check localStorage on page load and apply the saved mode --- const savedMode = localStorage.getItem(STORAGE_KEY); // If savedMode is 'true', apply fullscreen, otherwise default to not fullscreen applyMode(savedMode === 'true'); }); })();