forked from cccb-website-team/www
62 lines
2 KiB
JavaScript
62 lines
2 KiB
JavaScript
(function () {
|
||
'use strict';
|
||
|
||
var SVG = [
|
||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 80" width="40" height="80">',
|
||
// Exhaust flame
|
||
'<path d="M13,65 Q20,80 27,65" fill="#f97316" opacity="0.85"/>',
|
||
'<path d="M15,63 Q20,74 25,63" fill="#fbbf24"/>',
|
||
// Fins
|
||
'<path d="M11,53 L3,70 L14,58" fill="#a855f7"/>',
|
||
'<path d="M29,53 L37,70 L26,58" fill="#a855f7"/>',
|
||
// Body
|
||
'<ellipse cx="20" cy="42" rx="11" ry="22" fill="#e879f9"/>',
|
||
// Nose cone
|
||
'<path d="M20,10 L10,32 L30,32 Z" fill="#c026d3"/>',
|
||
// Window
|
||
'<circle cx="20" cy="44" r="7" fill="#0ea5e9" opacity="0.82"/>',
|
||
'<circle cx="22" cy="41" r="2.5" fill="white" opacity="0.35"/>',
|
||
// Body highlight
|
||
'<ellipse cx="15" cy="36" rx="3" ry="8" fill="white" opacity="0.15" transform="rotate(-15,15,36)"/>',
|
||
'</svg>'
|
||
].join('');
|
||
|
||
function isDark() {
|
||
return document.documentElement.classList.contains('dark');
|
||
}
|
||
|
||
function launch() {
|
||
if (!isDark()) { scheduleNext(); return; }
|
||
|
||
var goRight = Math.random() > 0.5;
|
||
var topPct = 6 + Math.random() * 72;
|
||
var duration = (3.5 + Math.random() * 4).toFixed(1);
|
||
|
||
var wrapper = document.createElement('div');
|
||
wrapper.className = 'fairydust-wrapper ' + (goRight ? 'go-right' : 'go-left');
|
||
wrapper.style.top = topPct + 'vh';
|
||
wrapper.style.setProperty('--fly-duration', duration + 's');
|
||
|
||
var rocket = document.createElement('div');
|
||
rocket.className = 'fairydust-rocket';
|
||
rocket.style.transform = 'rotate(' + (goRight ? 90 : -90) + 'deg)';
|
||
rocket.innerHTML = SVG;
|
||
|
||
wrapper.appendChild(rocket);
|
||
document.body.appendChild(wrapper);
|
||
|
||
wrapper.addEventListener('animationend', function (e) {
|
||
if (e.animationName === 'fairydust-fly-right' ||
|
||
e.animationName === 'fairydust-fly-left') {
|
||
wrapper.remove();
|
||
}
|
||
});
|
||
|
||
scheduleNext();
|
||
}
|
||
|
||
function scheduleNext() {
|
||
setTimeout(launch, 250000 + Math.random() * 950000); // 250–1200 s
|
||
}
|
||
|
||
})();
|