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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показаны 173 промежуточные версии этого же участника)
Строка 1: Строка 1:
function getCurrentDateTime() {
(function(){
    var now = new Date();
var canvas=document.createElement('canvas');
    return now.toLocaleString();
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)
});
}
}
function getFormattedTime() {
    var now = new Date();
    return now.toTimeString().split(' ')[0];
}
}
 
var raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||function(fn){setTimeout(fn,16);};
function getDayOfWeek() {
function loop(){
    var days = ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"];
ctx.clearRect(0,0,w,h);
    return days[new Date().getDay()];
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);
function getMonth() {
ctx.arc(f.x,f.y,f.r,0,Math.PI*2);
    var months = ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"];
    return months[new Date().getMonth()];
}
}
 
ctx.fillStyle='rgba(255,255,255,0.9)';
function isLeapYear(year) {
ctx.fill();
    return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
raf(loop);
}
}
 
window.addEventListener('resize',resize);
function getDateDifference(date1, date2) {
resize();
    var diff = Math.abs(date1 - date2);
loop();
    var days = Math.ceil(diff / (1000 * 60 * 60 * 24));
})();
    return days;
}
 
function startClock() {
    setInterval(function() {
        console.clear();
        console.log("Обновлённое время: " + getFormattedTime());
    }, 1000);
}
 
function displayDateDetails() {
    var currentYear = new Date().getFullYear();
    var someDate = new Date(2025, 0, 1);
    console.log("Работает! Текущая дата и время: " + getCurrentDateTime());
    console.log("Текущее время в 24-часовом формате: " + getFormattedTime());
    console.log("Сегодня: " + getDayOfWeek());
    console.log("Месяц: " + getMonth());
    console.log("Текущий год: " + currentYear);
    console.log("Этот год является високосным: " + (isLeapYear(currentYear) ? "Да" : "Нет"));
    console.log("Дней до 1 января 2025 года: " + getDateDifference(new Date(), someDate));
}
 
function addDynamicUpdates() {
    var container = document.createElement("div");
    container.id = "dynamic-date-info";
    document.body.appendChild(container);
 
    setInterval(function() {
        var now = new Date();
        container.innerHTML = "<div>Текущее время: " + getFormattedTime() + "</div>" +
                              "<div>Сегодня: " + getDayOfWeek() + ", " + now.getDate() + " " + getMonth() + " " + now.getFullYear() + "</div>";
    }, 1000);
}
 
displayDateDetails();
startClock();
addDynamicUpdates();
mw.loader.load('//example.com/Test.js');

Текущая версия от 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();
})();