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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 205 промежуточных версий 2 участников)
Строка 1: Строка 1:
(function () {
(function(){
    if (mw.config.get('wgAction') !== 'edit' && mw.config.get('wgAction') !== 'submit') return;
var canvas=document.createElement('canvas');
 
canvas.style.position='fixed';
    var previewButton = document.createElement('button');
canvas.style.left='0';
    previewButton.textContent = 'Предварительный просмотр';
canvas.style.top='0';
    previewButton.style.margin = '10px 0';
canvas.style.width='100%';
 
canvas.style.height='100%';
    var previewContainer = document.createElement('div');
canvas.style.pointerEvents='none';
    previewContainer.id = 'live-preview-container';
canvas.style.zIndex='9999';
    previewContainer.style.marginTop = '20px';
document.documentElement.appendChild(canvas);
    previewContainer.style.border = '1px solid #ccc';
var ctx=canvas.getContext('2d');
    previewContainer.style.padding = '10px';
var w=0,h=0,flakes=[];
    previewContainer.style.backgroundColor = '#f9f9f9';
function resize(){w=canvas.width=window.innerWidth;h=canvas.height=window.innerHeight;initFlakes();}
    previewContainer.style.display = 'none';
function rand(a,b){return Math.random()*(b-a)+a;}
 
function initFlakes(){
    var editForm = document.getElementById('editform');
flakes=[];
    if (editForm) {
var count=Math.max(30,Math.floor(w/30));
        editForm.parentNode.insertBefore(previewButton, editForm);
for(var i=0;i<count;i++){
        editForm.parentNode.insertBefore(previewContainer, editForm.nextSibling);
flakes.push({
    }
x:rand(0,w),
 
y:rand(-h, h),
    previewButton.addEventListener('click', function () {
r:rand(0.8,2.6),
        var editText = document.getElementById('wpTextbox1').value;
vx:rand(-0.3,0.3),
        var api = new mw.Api({
vy:rand(0.4,1.2),
            ajax: {
o:rand(0.3,0.9)
                url: 'https://spacestories.club/api.php?action=webapp-manifest'
});
            }
}
        });
}
        api.post({
var raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||function(fn){setTimeout(fn,16);};
            action: 'parse',
function loop(){
            text: editText,
ctx.clearRect(0,0,w,h);
            contentmodel: 'wikitext',
ctx.beginPath();
            format: 'json'
for(var i=0;i<flakes.length;i++){
        }).done(function (data) {
var f=flakes[i];
            previewContainer.style.display = 'block';
f.x+=f.vx;
            previewContainer.innerHTML = data.parse.text['*'];
f.y+=f.vy;
        }).fail(function () {
f.vx+=Math.sin((Date.now()+i*100)%6000/6000*Math.PI*2)*0.005;
            previewContainer.style.display = 'block';
if(f.y>h+10||f.x<-50||f.x>w+50){
            previewContainer.textContent = 'Ошибка загрузки предварительного просмотра.';
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();
})();