MediaWiki:Test.js: различия между версиями

Страница интерфейса MediaWiki
Нет описания правки
Метка: ручная отмена
Нет описания правки
Строка 1: Строка 1:
(function() {
(function() {
    if (window.innerWidth < 1024 || /Mobi|Android|iPhone|iPad|iPod|Tablet/i.test(navigator.userAgent)) return;
    if (localStorage.getItem('halloweenThemeDisabled') === 'true') return;
     var today = new Date();
     var today = new Date();
     var month = today.getMonth() + 1;
     var month = today.getMonth() + 1;
Строка 25: Строка 29:
         function createFragmentElements(count, createFn) {
         function createFragmentElements(count, createFn) {
             var frag = document.createDocumentFragment();
             var frag = document.createDocumentFragment();
             for (var i = 0; i < count; i++) {
             for (var i = 0; i < count; i++) frag.appendChild(createFn(i));
                frag.appendChild(createFn(i));
            }
             return frag;
             return frag;
         }
         }
Строка 34: Строка 36:
             var leaves = document.createElement('div');
             var leaves = document.createElement('div');
             leaves.className = 'halloween-leaves';
             leaves.className = 'halloween-leaves';
             var frag = createFragmentElements(config.leavesCount, function() {
             leaves.appendChild(createFragmentElements(config.leavesCount, function() {
                 var leaf = document.createElement('span');
                 var leaf = document.createElement('span');
                 leaf.className = 'halloween-leaf';
                 leaf.className = 'halloween-leaf';
Строка 44: Строка 46:
                 leaf.style.transform = 'rotate(' + (Math.random() * 360) + 'deg)';
                 leaf.style.transform = 'rotate(' + (Math.random() * 360) + 'deg)';
                 return leaf;
                 return leaf;
             });
             }));
            leaves.appendChild(frag);
             body.appendChild(leaves);
             body.appendChild(leaves);
         }
         }
Строка 52: Строка 53:
             var heading = document.getElementById('firstHeading');
             var heading = document.getElementById('firstHeading');
             if (!heading) return;
             if (!heading) return;
             for (var i = 0; i < config.pumpkinsCount; i++) {
             for (var i = 0; i < config.pumpkinsCount; i++) {
                 var pumpkin = document.createElement('span');
                 var pumpkin = document.createElement('span');
Строка 60: Строка 60:
                 pumpkin.style.fontSize = (config.pumpkinMinSize + Math.random() * (config.pumpkinMaxSize - config.pumpkinMinSize)) + 'px';
                 pumpkin.style.fontSize = (config.pumpkinMinSize + Math.random() * (config.pumpkinMaxSize - config.pumpkinMinSize)) + 'px';
                 heading.appendChild(pumpkin);
                 heading.appendChild(pumpkin);
                 floatPumpkin(pumpkin);
                 (function(el){
            }
                    var pos = 0, dir = 1;
 
                    setInterval(function() {
            function floatPumpkin(el) {
                        pos += dir*0.3;
                var pos = 0, dir = 1;
                        if(pos>5||pos<0) dir*=-1;
                setInterval(function() {
                        el.style.transform = 'translateY(' + pos + 'px)';
                    pos += dir * 0.3;
                    },30);
                    if(pos > 5 || pos < 0) dir *= -1;
                })(pumpkin);
                    el.style.transform = 'translateY(' + pos + 'px)';
                }, 30);
             }
             }
         }
         }


         function initLinksEffect() {
         function initLinksEffect() {
             body.addEventListener('mouseover', function(e) {
             body.addEventListener('mouseover', function(e){
                 if (e.target.tagName.toLowerCase() === 'a') {
                 if(e.target.tagName.toLowerCase()==='a'){
                     e.target.style.color = '#ffa500';
                     e.target.style.color='#ffa500';
                     e.target.style.textShadow = '0 0 8px #ffa500, 0 0 15px #ff7518';
                     e.target.style.textShadow='0 0 8px #ffa500, 0 0 15px #ff7518';
                 }
                 }
             });
             });
             body.addEventListener('mouseout', function(e) {
             body.addEventListener('mouseout', function(e){
                 if (e.target.tagName.toLowerCase() === 'a') {
                 if(e.target.tagName.toLowerCase()==='a'){
                     e.target.style.color = '';
                     e.target.style.color='';
                     e.target.style.textShadow = '';
                     e.target.style.textShadow='';
                 }
                 }
             });
             });
Строка 89: Строка 87:


         function initBats() {
         function initBats() {
             var frag = createFragmentElements(config.batsCount, function() {
             body.appendChild(createFragmentElements(config.batsCount, function(){
                 var bat = document.createElement('div');
                 var bat=document.createElement('div');
                 bat.className = 'halloween-bat';
                 bat.className='halloween-bat';
                 bat.style.top = (Math.random() * 50) + 'vh';
                 bat.style.top=(Math.random()*50)+'vh';
                 bat.style.left = (-50 + Math.random() * 100) + 'px';
                 bat.style.left=(-50+Math.random()*100)+'px';
                 bat.style.animationDuration = (8 + Math.random() * 6) + 's';
                 bat.style.animationDuration=(8+Math.random()*6)+'s';
                 return bat;
                 return bat;
             });
             }));
            body.appendChild(frag);
         }
         }


         function initWebs() {
         function initWebs() {
             var frag = createFragmentElements(config.websCount, function() {
             body.appendChild(createFragmentElements(config.websCount, function(){
                 var web = document.createElement('div');
                 var web=document.createElement('div');
                 web.className = 'spider-web';
                 web.className='spider-web';
                 web.style.top = (Math.random() * 80) + 'vh';
                 web.style.top=(Math.random()*80)+'vh';
                 web.style.left = (Math.random() * 90) + 'vw';
                 web.style.left=(Math.random()*90)+'vw';
                 web.style.transform = 'rotate(' + (Math.random() * 360) + 'deg)';
                 web.style.transform='rotate('+(Math.random()*360)+'deg)';
                 return web;
                 return web;
            }));
        }
        function addDisableButton() {
            var btn=document.createElement('div');
            btn.innerText='Отключить хэллоуинскую тему';
            btn.style.position='fixed';
            btn.style.bottom='10px';
            btn.style.right='10px';
            btn.style.padding='6px 12px';
            btn.style.background='var(--pumpkin-orange)';
            btn.style.color='var(--ghost-white)';
            btn.style.cursor='pointer';
            btn.style.borderRadius='6px';
            btn.style.zIndex=9999;
            btn.style.boxShadow='0 0 8px var(--pumpkin-orange)';
            btn.addEventListener('click', function(){
                localStorage.setItem('halloweenThemeDisabled','true');
                location.reload();
             });
             });
             body.appendChild(frag);
             body.appendChild(btn);
         }
         }


Строка 118: Строка 134:
             initBats();
             initBats();
             initWebs();
             initWebs();
            addDisableButton();
         }
         }


        // Delay start for smoother load
         setTimeout(init, 500);
         setTimeout(init, 500);
     });
     });
})();
})();

Версия от 20:03, 23 октября 2025

(function() {
    if (window.innerWidth < 1024 || /Mobi|Android|iPhone|iPad|iPod|Tablet/i.test(navigator.userAgent)) return;

    if (localStorage.getItem('halloweenThemeDisabled') === 'true') return;

    var today = new Date();
    var month = today.getMonth() + 1;
    if (month !== 10 && month !== 11) return;

    mw.loader.load('/w/index.php?title=MediaWiki:Test.css&action=raw&ctype=text/css');

    mw.hook('wikipage.content').add(function($content) {

        var config = {
            leavesCount: 50,
            batsCount: 8,
            websCount: 5,
            pumpkinsCount: 3,
            leafIcons: ['🍂','🍁','🦇','🕸️'],
            pumpkinIcon: '🎃',
            leafMinSize: 14,
            leafMaxSize: 42,
            pumpkinMinSize: 24,
            pumpkinMaxSize: 36
        };

        var body = document.body;

        function createFragmentElements(count, createFn) {
            var frag = document.createDocumentFragment();
            for (var i = 0; i < count; i++) frag.appendChild(createFn(i));
            return frag;
        }

        function initLeaves() {
            var leaves = document.createElement('div');
            leaves.className = 'halloween-leaves';
            leaves.appendChild(createFragmentElements(config.leavesCount, function() {
                var leaf = document.createElement('span');
                leaf.className = 'halloween-leaf';
                leaf.innerHTML = config.leafIcons[Math.floor(Math.random() * config.leafIcons.length)];
                leaf.style.left = (Math.random() * 100) + '%';
                leaf.style.animationDelay = (Math.random() * 10) + 's';
                leaf.style.fontSize = (config.leafMinSize + Math.random() * (config.leafMaxSize - config.leafMinSize)) + 'px';
                leaf.style.opacity = Math.random() * 0.7 + 0.3;
                leaf.style.transform = 'rotate(' + (Math.random() * 360) + 'deg)';
                return leaf;
            }));
            body.appendChild(leaves);
        }

        function initPumpkins() {
            var heading = document.getElementById('firstHeading');
            if (!heading) return;
            for (var i = 0; i < config.pumpkinsCount; i++) {
                var pumpkin = document.createElement('span');
                pumpkin.className = 'halloween-pumpkin';
                pumpkin.innerHTML = config.pumpkinIcon;
                pumpkin.style.margin = '0 2px';
                pumpkin.style.fontSize = (config.pumpkinMinSize + Math.random() * (config.pumpkinMaxSize - config.pumpkinMinSize)) + 'px';
                heading.appendChild(pumpkin);
                (function(el){
                    var pos = 0, dir = 1;
                    setInterval(function() {
                        pos += dir*0.3;
                        if(pos>5||pos<0) dir*=-1;
                        el.style.transform = 'translateY(' + pos + 'px)';
                    },30);
                })(pumpkin);
            }
        }

        function initLinksEffect() {
            body.addEventListener('mouseover', function(e){
                if(e.target.tagName.toLowerCase()==='a'){
                    e.target.style.color='#ffa500';
                    e.target.style.textShadow='0 0 8px #ffa500, 0 0 15px #ff7518';
                }
            });
            body.addEventListener('mouseout', function(e){
                if(e.target.tagName.toLowerCase()==='a'){
                    e.target.style.color='';
                    e.target.style.textShadow='';
                }
            });
        }

        function initBats() {
            body.appendChild(createFragmentElements(config.batsCount, function(){
                var bat=document.createElement('div');
                bat.className='halloween-bat';
                bat.style.top=(Math.random()*50)+'vh';
                bat.style.left=(-50+Math.random()*100)+'px';
                bat.style.animationDuration=(8+Math.random()*6)+'s';
                return bat;
            }));
        }

        function initWebs() {
            body.appendChild(createFragmentElements(config.websCount, function(){
                var web=document.createElement('div');
                web.className='spider-web';
                web.style.top=(Math.random()*80)+'vh';
                web.style.left=(Math.random()*90)+'vw';
                web.style.transform='rotate('+(Math.random()*360)+'deg)';
                return web;
            }));
        }

        function addDisableButton() {
            var btn=document.createElement('div');
            btn.innerText='Отключить хэллоуинскую тему';
            btn.style.position='fixed';
            btn.style.bottom='10px';
            btn.style.right='10px';
            btn.style.padding='6px 12px';
            btn.style.background='var(--pumpkin-orange)';
            btn.style.color='var(--ghost-white)';
            btn.style.cursor='pointer';
            btn.style.borderRadius='6px';
            btn.style.zIndex=9999;
            btn.style.boxShadow='0 0 8px var(--pumpkin-orange)';
            btn.addEventListener('click', function(){
                localStorage.setItem('halloweenThemeDisabled','true');
                location.reload();
            });
            body.appendChild(btn);
        }

        function init() {
            initLeaves();
            initPumpkins();
            initLinksEffect();
            initBats();
            initWebs();
            addDisableButton();
        }

        setTimeout(init, 500);
    });
})();