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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 130 промежуточных версий этого же участника)
Строка 1: Строка 1:
$(function () {
(function(){
    var players = document.getElementsByClassName('audio-player');
var canvas=document.createElement('canvas');
    for (var i = 0; i < players.length; i++) {
canvas.style.position='fixed';
        (function (container) {
canvas.style.left='0';
            var src = container.getAttribute('data-src');
canvas.style.top='0';
            if (!src) return;
canvas.style.width='100%';
 
canvas.style.height='100%';
            var audio = document.createElement('audio');
canvas.style.pointerEvents='none';
            audio.src = src;
canvas.style.zIndex='9999';
 
document.documentElement.appendChild(canvas);
            var wrapper = document.createElement('div');
var ctx=canvas.getContext('2d');
            wrapper.className = 'custom-audio-wrapper';
var w=0,h=0,flakes=[];
 
function resize(){w=canvas.width=window.innerWidth;h=canvas.height=window.innerHeight;initFlakes();}
            var playBtn = document.createElement('button');
function rand(a,b){return Math.random()*(b-a)+a;}
            playBtn.className = 'custom-audio-play';
function initFlakes(){
            playBtn.innerHTML = '';
flakes=[];
 
var count=Math.max(30,Math.floor(w/30));
            var progress = document.createElement('input');
for(var i=0;i<count;i++){
            progress.setAttribute('type', 'range');
flakes.push({
            progress.className = 'custom-audio-progress';
x:rand(0,w),
            progress.setAttribute('min', 0);
y:rand(-h, h),
            progress.value = 0;
r:rand(0.8,2.6),
            progress.step = 0.01;
vx:rand(-0.3,0.3),
 
vy:rand(0.4,1.2),
            var time = document.createElement('span');
o:rand(0.3,0.9)
            time.className = 'custom-audio-time';
            time.innerHTML = '0:00';
 
            // Добавляем кнопку громкости
            var volumeBtn = document.createElement('button');
            volumeBtn.className = 'custom-audio-volume-btn';
            volumeBtn.innerHTML = '🔊';
 
            // Блок для ползунка громкости с подсветкой
            var volumeControlWrapper = document.createElement('div');
            volumeControlWrapper.className = 'custom-audio-volume-wrapper';
 
            // Ползунок громкости
            var volumeControl = document.createElement('input');
            volumeControl.setAttribute('type', 'range');
            volumeControl.setAttribute('min', 0);
            volumeControl.setAttribute('max', 1);
            volumeControl.setAttribute('step', 0.01);
            volumeControl.setAttribute('value', 1);
            volumeControl.className = 'custom-audio-volume';
            volumeControl.style.transform = 'rotate(270deg)';  // Вертикальный ползунок
 
            volumeControlWrapper.appendChild(volumeControl);
 
            wrapper.appendChild(playBtn);
            wrapper.appendChild(progress);
            wrapper.appendChild(time);
            wrapper.appendChild(volumeBtn);
            wrapper.appendChild(volumeControlWrapper);
            container.appendChild(wrapper);
 
            playBtn.onclick = function () {
                if (audio.paused) {
                    audio.play();
                    playBtn.innerHTML = '⏸';
                } else {
                    audio.pause();
                    playBtn.innerHTML = '▶';
                }
            };
 
            // Исправим ситуацию, если duration ещё не прогрузилась
            audio.addEventListener('loadedmetadata', function () {
                progress.max = audio.duration;
            });
 
            audio.addEventListener('timeupdate', function () {
                progress.value = audio.currentTime;
                if (!isNaN(audio.duration)) {
                    progress.max = audio.duration;
                }
                time.innerHTML = formatTime(audio.currentTime);
            });
 
            progress.addEventListener('input', function () {
                audio.currentTime = parseFloat(progress.value);
            });
 
            volumeControl.addEventListener('input', function () {
                audio.volume = volumeControl.value;
            });
 
            volumeBtn.onclick = function () {
                // Переключаем видимость блока с ползунком громкости
                if (volumeControlWrapper.style.display === 'none' || volumeControlWrapper.style.display === '') {
                    volumeControlWrapper.style.display = 'block';
                } else {
                    volumeControlWrapper.style.display = 'none';
                }
            };
 
            function formatTime(seconds) {
                var mins = Math.floor(seconds / 60);
                var secs = Math.floor(seconds % 60);
                if (secs < 10) secs = '0' + secs;
                return mins + ':' + secs;
            }
        })(players[i]);
    }
});
});
}
}
var raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||function(fn){setTimeout(fn,16);};
function loop(){
ctx.clearRect(0,0,w,h);
ctx.beginPath();
for(var i=0;i<flakes.length;i++){
var f=flakes[i];
f.x+=f.vx;
f.y+=f.vy;
f.vx+=Math.sin((Date.now()+i*100)%6000/6000*Math.PI*2)*0.005;
if(f.y>h+10||f.x<-50||f.x>w+50){
f.x=rand(0,w);
f.y=-10;
f.vx=rand(-0.3,0.3);
f.vy=rand(0.4,1.2);
}
ctx.moveTo(f.x,f.y);
ctx.arc(f.x,f.y,f.r,0,Math.PI*2);
}
ctx.fillStyle='rgba(255,255,255,0.9)';
ctx.fill();
raf(loop);
}
window.addEventListener('resize',resize);
resize();
loop();
})();

Текущая версия от 23:41, 22 ноября 2025

(function(){
var canvas=document.createElement('canvas');
canvas.style.position='fixed';
canvas.style.left='0';
canvas.style.top='0';
canvas.style.width='100%';
canvas.style.height='100%';
canvas.style.pointerEvents='none';
canvas.style.zIndex='9999';
document.documentElement.appendChild(canvas);
var ctx=canvas.getContext('2d');
var w=0,h=0,flakes=[];
function resize(){w=canvas.width=window.innerWidth;h=canvas.height=window.innerHeight;initFlakes();}
function rand(a,b){return Math.random()*(b-a)+a;}
function initFlakes(){
flakes=[];
var count=Math.max(30,Math.floor(w/30));
for(var i=0;i<count;i++){
flakes.push({
x:rand(0,w),
y:rand(-h, h),
r:rand(0.8,2.6),
vx:rand(-0.3,0.3),
vy:rand(0.4,1.2),
o:rand(0.3,0.9)
});
}
}
var raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||function(fn){setTimeout(fn,16);};
function loop(){
ctx.clearRect(0,0,w,h);
ctx.beginPath();
for(var i=0;i<flakes.length;i++){
var f=flakes[i];
f.x+=f.vx;
f.y+=f.vy;
f.vx+=Math.sin((Date.now()+i*100)%6000/6000*Math.PI*2)*0.005;
if(f.y>h+10||f.x<-50||f.x>w+50){
f.x=rand(0,w);
f.y=-10;
f.vx=rand(-0.3,0.3);
f.vy=rand(0.4,1.2);
}
ctx.moveTo(f.x,f.y);
ctx.arc(f.x,f.y,f.r,0,Math.PI*2);
}
ctx.fillStyle='rgba(255,255,255,0.9)';
ctx.fill();
raf(loop);
}
window.addEventListener('resize',resize);
resize();
loop();
})();