Refactor PiDay feature: clean up comments, adjust element creation, and add background mode support
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
// 1. Read Configuration
|
|
||||||
const config = window.SeasonalsPluginConfig?.PiDay || {};
|
const config = window.SeasonalsPluginConfig?.PiDay || {};
|
||||||
|
|
||||||
const enabled = config.EnablePiDay !== undefined ? config.EnablePiDay : true;
|
const enabled = config.EnablePiDay !== undefined ? config.EnablePiDay : true;
|
||||||
const maxTrails = config.SymbolCount || 25; // Directly mapped, smaller default
|
const maxTrails = config.SymbolCount || 25;
|
||||||
|
const backgroundMode = config.EnablePiDayBackground !== undefined ? config.EnablePiDayBackground : false;
|
||||||
|
|
||||||
let msgPrinted = false;
|
let msgPrinted = false;
|
||||||
let isHidden = false;
|
let isHidden = false;
|
||||||
|
|
||||||
// 2. Toggle Function
|
// Toggle Function
|
||||||
function togglePiDay() {
|
function togglePiDay() {
|
||||||
const container = document.querySelector('.piday-container');
|
const container = document.querySelector('.piday-container');
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
@@ -38,7 +38,6 @@ function togglePiDay() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. MutationObserver
|
|
||||||
const observer = new MutationObserver(togglePiDay);
|
const observer = new MutationObserver(togglePiDay);
|
||||||
observer.observe(document.body, {
|
observer.observe(document.body, {
|
||||||
childList: true,
|
childList: true,
|
||||||
@@ -46,13 +45,13 @@ observer.observe(document.body, {
|
|||||||
attributes: true
|
attributes: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// 4. Element Creation
|
|
||||||
function createElements() {
|
function createElements() {
|
||||||
const container = document.querySelector('.piday-container') || document.createElement('div');
|
const container = document.querySelector('.piday-container') || document.createElement('div');
|
||||||
|
|
||||||
if (!document.querySelector('.piday-container')) {
|
if (!document.querySelector('.piday-container')) {
|
||||||
container.className = 'piday-container';
|
container.className = 'piday-container';
|
||||||
container.setAttribute('aria-hidden', 'true');
|
container.setAttribute('aria-hidden', 'true');
|
||||||
|
if (backgroundMode) container.style.zIndex = '5';
|
||||||
document.body.appendChild(container);
|
document.body.appendChild(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +154,6 @@ function createElements() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Initialization
|
|
||||||
function initializePiDay() {
|
function initializePiDay() {
|
||||||
if (!enabled) return;
|
if (!enabled) return;
|
||||||
createElements();
|
createElements();
|
||||||
|
|||||||
Reference in New Issue
Block a user