Mediawiki:common.js

Вернуться

Строка 1756: Строка 1756:
window.SnowflakesModule = SnowflakesModule;
window.SnowflakesModule = SnowflakesModule;
var FireworksModule = {
    fireworks: null,
    container: null,
    checkInterval: null,
    isActive: false,
    loaded: false,
    loading: false,
   
    init: function() {
        this.createTestButton();
        this.startTimeCheck();
    },
   
    createTestButton: function() {
        // Создаем кнопку для тестирования
        var button = document.createElement('button');
        button.id = 'fireworks-test-btn';
        button.textContent = '🎆 Тест фейерверков';
        button.style.cssText =
            'position: fixed;' +
            'bottom: 20px;' +
            'right: 20px;' +
            'z-index: 99999;' +
            'padding: 10px 15px;' +
            'background: #ff6b6b;' +
            'color: white;' +
            'border: none;' +
            'border-radius: 25px;' +
            'cursor: pointer;' +
            'font-size: 14px;' +
            'box-shadow: 0 4px 6px rgba(0,0,0,0.3);' +
            'transition: all 0.3s;';
       
        button.addEventListener('mouseenter', function() {
            this.style.transform = 'scale(1.05)';
            this.style.boxShadow = '0 6px 8px rgba(0,0,0,0.4)';
        });
       
        button.addEventListener('mouseleave', function() {
            this.style.transform = 'scale(1)';
            this.style.boxShadow = '0 4px 6px rgba(0,0,0,0.3)';
        });
       
        button.addEventListener('click', function() {
            FireworksModule.toggleFireworks();
        });
       
        document.body.appendChild(button);
    },
   
    loadFireworks: function(callback) {
        if (this.loaded && window.Fireworks) {
            if (callback) callback();
            return;
        }
       
        if (callback) {
            if (!this.callbacks) this.callbacks = [];
            this.callbacks.push(callback);
        }
       
        if (this.loading) return;
        this.loading = true;
       
        var self = this;
       
        // Загружаем библиотеку fireworks.js
        var script = document.createElement('script');
        script.type = 'module';
        script.src = 'https://cdn.jsdelivr.net/npm/fireworks-js@2/dist/index.umd.js';
        script.onload = function() {
            self.loaded = true;
            self.loading = false;
           
            if (self.callbacks) {
                self.callbacks.forEach(function(cb) { cb(); });
                self.callbacks = [];
            }
           
            if (callback) callback();
        };
        script.onerror = function() {
            console.error('Ошибка загрузки fireworks.js');
            self.loading = false;
        };
       
        document.head.appendChild(script);
    },
   
    getMoscowTime: function() {
        // МСК = UTC+3
        var now = new Date();
        var utc = now.getTime() + (now.getTimezoneOffset() * 60000);
        var moscowTime = new Date(utc + (3 * 3600000)); // UTC+3
        return moscowTime;
    },
   
    isFireworksTime: function() {
        var moscowTime = this.getMoscowTime();
        var hours = moscowTime.getHours();
        // С 00:00 до 01:00 по МСК
        return hours === 0;
    },
   
    startTimeCheck: function() {
        var self = this;
       
        // Проверяем сразу при загрузке
        this.checkTime();
       
        // Проверяем каждую минуту
        this.checkInterval = setInterval(function() {
            self.checkTime();
        }, 60000);
    },
   
    checkTime: function() {
        if (this.isFireworksTime()) {
            if (!this.isActive) {
                this.startFireworks();
            }
        } else {
            if (this.isActive) {
                this.stopFireworks();
            }
        }
    },
   
    startFireworks: function() {
        var self = this;
       
        this.loadFireworks(function() {
            if (!self.container) {
                self.container = document.createElement('div');
                self.container.id = 'fireworks-container';
                self.container.style.cssText =
                    'position: fixed;' +
                    'top: 0;' +
                    'left: 0;' +
                    'width: 100%;' +
                    'height: 100%;' +
                    'pointer-events: none;' +
                    'z-index: 99998;';
                document.body.appendChild(self.container);
            }
           
            if (!self.fireworks && window.Fireworks) {
                self.fireworks = new window.Fireworks(self.container, {
                    autoresize: true,
                    opacity: 0.5,
                    acceleration: 1.05,
                    friction: 0.97,
                    gravity: 1.5,
                    particles: 50,
                    traceLength: 3,
                    traceSpeed: 10,
                    explosion: 5,
                    intensity: 30,
                    flickering: 50,
                    lineStyle: 'round',
                    hue: { min: 0, max: 360 },
                    delay: { min: 15, max: 30 },
                    rocketsPoint: { min: 50, max: 50 },
                    lineWidth: { explosion: { min: 1, max: 3 }, trace: { min: 1, max: 2 } },
                    brightness: { min: 50, max: 80 },
                    decay: { min: 0.015, max: 0.03 },
                    mouse: { click: false, move: false, max: 1 }
                });
            }
           
            if (self.fireworks) {
                self.fireworks.start();
                self.isActive = true;
            }
        });
    },
   
    stopFireworks: function() {
        if (this.fireworks) {
            this.fireworks.stop();
            this.isActive = false;
        }
    },
   
    toggleFireworks: function() {
        if (this.isActive) {
            this.stopFireworks();
        } else {
            this.startFireworks();
        }
    }
};
window.FireworksModule = FireworksModule;


     function initAllModules() {
     function initAllModules() {
Строка 1765: Строка 1960:
         DocumentAutoFillModule.init();
         DocumentAutoFillModule.init();
         SnowflakesModule.init()
         SnowflakesModule.init()
        FireworksModule.init();
         // LawCalculatorModule.init();
         // LawCalculatorModule.init();
     }
     }