微件:空山新雨后
来自EaseCation Wiki
更多操作
<script> (function() {
'use strict';
function waitForjQuery(callback, attempts) {
if (typeof jQuery !== 'undefined' && typeof $ !== 'undefined') {
callback();
} else if (attempts < 50) {
setTimeout(function() { waitForjQuery(callback, attempts + 1); }, 100);
}
}
waitForjQuery(function() {
$(document).ready(function() {
var container = document.querySelector('.miss-you-container');
var overlay = container ? container.querySelector('.miss-you-overlay') : null;
var finalEl = container ? container.querySelector('.miss-you-final') : null;
if (!overlay) return;
var isFlooding = false;
var isFinished = false;
var currentSpeed = 600;
var speedLevel = 0;
var addInterval = null;
var speedTimer = null;
var batchFastInterval = null;
var coverCheckInterval = null;
function getBounds() {
var rect = overlay.getBoundingClientRect();
return { width: rect.width, height: rect.height };
}
function addMissWord() {
if (isFinished) return;
var bounds = getBounds();
if (bounds.width <= 0 || bounds.height <= 0) return;
var word = document.createElement('div');
word.className = 'miss-word';
word.textContent = '\u6211\u60f3\u4f60';
var rand = Math.random();
var fontSize;
if (rand < 0.5) fontSize = 12 + Math.random() * 20;
else if (rand < 0.8) fontSize = 32 + Math.random() * 40;
else fontSize = 72 + Math.random() * 58;
word.style.fontSize = fontSize + 'px';
var left = Math.random() * (bounds.width - Math.min(150, bounds.width - 10));
var top = Math.random() * (bounds.height - 50);
word.style.left = left + 'px';
word.style.top = top + 'px';
word.style.color = '#000000';
word.style.opacity = '0';
overlay.appendChild(word);
setTimeout(function() {
if (word.parentNode) word.style.opacity = '0.85';
}, 5);
if (overlay.children.length > 1500) {
var toRemove = overlay.children.length - 1200;
for (var i = 0; i < toRemove; i++) {
if (overlay.children[i]) overlay.children[i].remove();
}
}
}
function addBatch(count) {
for (var i = 0; i < count; i++) {
(function(idx) { setTimeout(function() { addMissWord(); }, idx * 15); })(i);
}
}
function checkCoverageAndFinish() {
if (isFinished || !isFlooding) return;
var count = overlay.children.length;
if (count >= 600 || (currentSpeed <= 30 && count >= 350)) {
finishAndBlackout();
}
}
function finishAndBlackout() {
if (isFinished) return;
isFinished = true;
isFlooding = false;
clearInterval(addInterval);
clearInterval(coverCheckInterval);
clearInterval(speedTimer);
if (batchFastInterval) clearInterval(batchFastInterval);
for (var i = 0; i < 100; i++) {
(function(idx) { setTimeout(function() { addMissWord(); }, idx * 8); })(i);
}
// 直接给body加class,让整个页面变黑
document.body.classList.add('miss-black-mode');
// 延迟后显示红字
setTimeout(function() {
if (finalEl) finalEl.classList.add('show');
}, 1000);
}
function increaseSpeed() {
if (!isFlooding || isFinished) return;
speedLevel++;
if (speedLevel <= 20) currentSpeed = Math.max(25, currentSpeed * 0.85);
else if (speedLevel <= 40) currentSpeed = Math.max(12, currentSpeed * 0.92);
else currentSpeed = Math.max(6, currentSpeed * 0.95);
clearInterval(addInterval);
addInterval = setInterval(function() {
if (isFlooding && !isFinished) {
addMissWord();
if (Math.random() < 0.25) setTimeout(function() { addMissWord(); }, 8);
}
}, currentSpeed);
if (currentSpeed < 40 && isFlooding && !isFinished) {
if (batchFastInterval) clearInterval(batchFastInterval);
batchFastInterval = setInterval(function() {
if (isFlooding && !isFinished) {
for (var i = 0; i < 4; i++) {
(function(idx) { setTimeout(function() { addMissWord(); }, idx * 10); })(i);
}
}
}, 1200);
}
}
function startFlooding() {
if (isFlooding || isFinished) return;
isFlooding = true;
addBatch(25);
currentSpeed = 550;
addInterval = setInterval(function() {
if (isFlooding && !isFinished) {
addMissWord();
if (Math.random() < 0.2) setTimeout(function() { addMissWord(); }, 8);
}
}, currentSpeed);
speedTimer = setInterval(function() {
if (isFlooding && !isFinished) increaseSpeed();
else clearInterval(speedTimer);
}, 1000);
coverCheckInterval = setInterval(function() {
checkCoverageAndFinish();
}, 300);
}
setTimeout(function() {
if (!isFlooding && !isFinished) startFlooding();
}, 1000);
});
}, 0);
})(); </script>