用户:Exschwasion/空山新雨后.js
来自EaseCation Wiki
更多操作
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
// 杂物间:空山新雨后.js
// 还原 https://www.bingzhuyetan.com/miss-you.html 的"我想你"蔓延效果
// 仅在杂物间:空山新雨后页面生效
(function() {
'use strict';
// 仅在指定页面运行
var pageName = mw.config.get('wgPageName');
if (pageName !== '杂物间:空山新雨后' && pageName !== '杂物间_空山新雨后') return;
// 等待页面内容加载完成
$(function() {
var $container = $('.miss-you-container');
var $overlay = $container.find('.miss-you-overlay');
var $final = $container.find('.miss-you-final');
var $blackout = $container.find('.miss-you-blackout');
if (!$overlay.length) 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[0].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 = '我想你';
// 随机大小
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[0].appendChild(word);
// 淡入
setTimeout(function() {
if (word.parentNode) {
word.style.opacity = '0.85';
}
}, 5);
// 限制数量
if ($overlay[0].children.length > 1500) {
var toRemove = $overlay[0].children.length - 1200;
for (var i = 0; i < toRemove; i++) {
if ($overlay[0].children[i]) {
$overlay[0].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[0].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);
}
// 黑色遮罩淡入
$blackout.addClass('show');
// 延迟显示红色大字
setTimeout(function() {
$final.addClass('show');
}, 800);
}
// 加速
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);
}
// 1秒后开始
setTimeout(function() {
if (!isFlooding && !isFinished) {
startFlooding();
}
}, 1000);
console.log('[空山新雨后] 蔓延效果已初始化');
});
})();