// ==UserScript==
// @name 超绝鼠标烟花特效【过年辣!】
// @namespace http://tampermonkey.net/
// @version 2.2
// @description 鼠标单击生成小烟花,长按生成大烟花,长按时间越长烟花越大
// @match *://*/*
// @grant none
// @author Nuclear_Fish_cyq
// @license MIT
// @downloadURL https://update.greasyfork.icu/scripts/564979/%E8%B6%85%E7%BB%9D%E9%BC%A0%E6%A0%87%E7%83%9F%E8%8A%B1%E7%89%B9%E6%95%88%E3%80%90%E8%BF%87%E5%B9%B4%E8%BE%A3%EF%BC%81%E3%80%91.user.js
// @updateURL https://update.greasyfork.icu/scripts/564979/%E8%B6%85%E7%BB%9D%E9%BC%A0%E6%A0%87%E7%83%9F%E8%8A%B1%E7%89%B9%E6%95%88%E3%80%90%E8%BF%87%E5%B9%B4%E8%BE%A3%EF%BC%81%E3%80%91.meta.js
// ==/UserScript==
(function() {
'use strict';
// 配置参数
const config = {
minLongPressTime: 300, // 最小长按时间(ms)
maxLongPressTime: 1500, // 最大长按时间(ms)
smallFirework: {
particleCount: 25, // 小烟花粒子数
spread: 60, // 小烟花扩散范围
size: 3, // 小烟花粒子大小
duration: 1800, // 小烟花持续时间(ms) - 增加时间
speed: 0.6 // 小烟花速度系数 (降低)
},
maxLargeFirework: {
particleCount: 120, // 大烟花最大粒子数
spread: 200, // 大烟花最大扩散范围
size: 8, // 大烟花最大粒子大小
duration: 2800, // 大烟花持续时间(ms) - 增加时间
speed: 0.8 // 大烟花速度系数 (降低)
},
colors: [
"#FF0000", // 红色
"#FF6B35", // 橙红色
"#FFD700", // 金色
"#FFA500", // 橙色
"#FFFF00", // 黄色
"#FF1493", // 深粉色
"#DC143C" // 深红色
],
specialChars: ["福", "春", "吉", "祥", "囍", "财", "运", "發"]
};
// 状态变量
let mouseDownTime = 0;
let longPressActive = false;
let longPressTimer = null;
let liftParticle = null; // 升起粒子
let liftStartY = 0; // 升起粒子起始位置
// 创建烟花容器
const container = document.createElement('div');
container.id = 'fireworks-container';
container.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 999999;
overflow: hidden;
`;
document.body.appendChild(container);
// 添加全局样式
const style = document.createElement('style');
style.textContent = `
.firework-particle {
position: absolute;
border-radius: 50%;
pointer-events: none;
}
.special-particle {
position: absolute;
font-size: 20px;
font-weight: bold;
color: #FFD700;
text-shadow: 0 0 5px #FF0000;
pointer-events: none;
font-family: 'Microsoft YaHei', sans-serif;
z-index: 2;
}
.firework-center {
position: absolute;
border-radius: 50%;
pointer-events: none;
box-shadow: 0 0 15px 5px rgba(255, 215, 0, 0.7);
z-index: 1;
}
.lift-particle {
position: absolute;
border-radius: 50%;
pointer-events: none;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
z-index: 1;
}
.lift-trail {
position: absolute;
border-radius: 50%;
pointer-events: none;
opacity: 0.6;
z-index: 0;
}
.progress-indicator {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
width: 200px;
height: 10px;
background: rgba(0, 0, 0, 0.5);
border-radius: 5px;
border: 1px solid #FFD700;
overflow: hidden;
z-index: 1000000;
display: none;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #FF0000, #FFD700);
border-radius: 5px;
width: 0%;
transition: width 0.1s;
}
.instruction-panel {
position: fixed;
bottom: 20px;
right: 20px;
background: rgba(0, 0, 0, 0.7);
color: #FFD700;
padding: 12px 16px;
border-radius: 10px;
font-family: Arial, sans-serif;
font-size: 14px;
border: 2px solid #FF0000;
box-shadow: 0 0 15px rgba(255, 0, 0, 0.5);
z-index: 1000000;
max-width: 250px;
backdrop-filter: blur(5px);
}
.instruction-panel h3 {
margin: 0 0 8px 0;
color: #FFFFFF;
font-size: 16px;
text-align: center;
}
.instruction-item {
margin: 6px 0;
display: flex;
align-items: center;
}
.instruction-icon {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 8px;
}
.small-firework-icon {
background: #FF0000;
box-shadow: 0 0 8px #FF0000;
}
.large-firework-icon {
background: #FFD700;
box-shadow: 0 0 8px #FFD700;
}
`;
document.head.appendChild(style);
// 创建进度指示器
const progressIndicator = document.createElement('div');
progressIndicator.className = 'progress-indicator';
const progressFill = document.createElement('div');
progressFill.className = 'progress-fill';
progressIndicator.appendChild(progressFill);
document.body.appendChild(progressIndicator);
// 创建说明面板
function createInstructionPanel() {
const panel = document.createElement('div');
panel.className = 'instruction-panel';
panel.innerHTML = `
🎆 鼠标烟花特效加载完毕 🎆
单击:生成小烟花
长按:生成大烟花(按住越久越大)
长按时会有粒子从底部升起
`;
document.body.appendChild(panel);
// 8秒后自动隐藏说明面板
setTimeout(() => {
panel.style.opacity = '0';
panel.style.transition = 'opacity 1s';
setTimeout(() => {
if (panel.parentNode) {
panel.parentNode.removeChild(panel);
}
}, 1000);
}, 8000);
}
// 更新进度指示器
function updateProgressIndicator(progress) {
progressIndicator.style.display = 'block';
progressFill.style.width = `${progress}%`;
}
// 隐藏进度指示器
function hideProgressIndicator() {
progressIndicator.style.display = 'none';
progressFill.style.width = '0%';
}
// 创建升起粒子
function createLiftParticle(x, y) {
// 移除现有的升起粒子
if (liftParticle) {
if (liftParticle.element && liftParticle.element.parentNode) {
liftParticle.element.parentNode.removeChild(liftParticle.element);
}
clearInterval(liftParticle.trailTimer);
}
// 创建新的升起粒子
liftStartY = window.innerHeight;
const liftElement = document.createElement('div');
liftElement.className = 'lift-particle';
liftElement.style.cssText = `
left: ${x}px;
top: ${liftStartY}px;
width: 8px;
height: 8px;
background: linear-gradient(135deg, #FF0000, #FFD700);
transform: translate(-50%, -50%);
`;
container.appendChild(liftElement);
// 创建轨迹粒子
const trailTimer = setInterval(() => {
const trail = document.createElement('div');
trail.className = 'lift-trail';
trail.style.cssText = `
left: ${x}px;
top: ${liftStartY}px;
width: 4px;
height: 4px;
background: rgba(255, 215, 0, 0.4);
transform: translate(-50%, -50%);
animation: trailFade 1.5s forwards;
`;
document.head.insertAdjacentHTML('beforeend', `
`);
container.appendChild(trail);
// 1.5秒后移除轨迹粒子
setTimeout(() => {
if (trail.parentNode) {
trail.parentNode.removeChild(trail);
}
}, 1500);
}, 80); // 减慢轨迹生成频率
// 动画升起粒子
const startTime = Date.now();
const duration = 1200; // 增加升起动画持续时间
const targetY = y;
function animateLift() {
const elapsed = Date.now() - startTime;
const progress = Math.min(elapsed / duration, 1);
// 计算当前位置(使用缓动函数使动画更自然)
const currentY = liftStartY - (liftStartY - targetY) * easeOutCubic(progress);
liftElement.style.top = `${currentY}px`;
// 根据进度调整粒子大小
const size = 8 + progress * 12; // 减小大小变化
liftElement.style.width = `${size}px`;
liftElement.style.height = `${size}px`;
// 根据进度改变颜色
const redValue = Math.floor(255 - progress * 100);
const goldValue = Math.floor(215 - progress * 100);
liftElement.style.background = `linear-gradient(135deg, rgb(255, ${redValue}, 0), rgb(255, ${goldValue}, 0))`;
if (progress < 1 && longPressActive) {
requestAnimationFrame(animateLift);
} else {
// 动画完成或长按结束
liftElement.style.top = `${targetY}px`;
}
}
animateLift();
// 保存升起粒子信息
liftParticle = {
element: liftElement,
trailTimer: trailTimer,
startX: x,
startY: liftStartY,
targetX: x,
targetY: y
};
return liftParticle;
}
// 缓动函数 - 三次缓出
function easeOutCubic(t) {
return 1 - Math.pow(1 - t, 3);
}
// 缓动函数 - 二次缓出(用于粒子爆炸)
function easeOutQuad(t) {
return t * (2 - t);
}
// 创建烟花中心点
function createFireworkCenter(x, y, size) {
const center = document.createElement('div');
center.className = 'firework-center';
center.style.cssText = `
left: ${x}px;
top: ${y}px;
width: ${size}px;
height: ${size}px;
background: radial-gradient(circle, #FFD700, #FF0000);
transform: translate(-50%, -50%);
animation: centerExplode 0.5s ease-out forwards;
`;
document.head.insertAdjacentHTML('beforeend', `
`);
container.appendChild(center);
setTimeout(() => {
if (center.parentNode) {
center.parentNode.removeChild(center);
}
}, 500);
}
// 创建有抛物线效果的粒子(优化速度)
function createParticleWithParabola(x, y, isLarge, size, duration, speedFactor, isSpecial = false) {
if (isSpecial) {
// 创建特殊字符粒子
const char = config.specialChars[Math.floor(Math.random() * config.specialChars.length)];
const particle = document.createElement('div');
particle.className = 'special-particle';
particle.textContent = char;
// 随机角度和距离
const angle = Math.random() * Math.PI * 2;
// 抛物线参数 - 降低速度
const speed = (0.4 + Math.random() * 0.3) * speedFactor; // 降低速度
const gravity = 0.02; // 减小重力
const angleX = Math.cos(angle) * speed;
const angleY = Math.sin(angle) * speed;
// 初始位置
let posX = 0;
let posY = 0;
let velocityY = angleY;
const startTime = Date.now();
particle.style.cssText = `
left: ${x}px;
top: ${y}px;
font-size: ${size * 3}px;
transform: translate(-50%, -50%);
opacity: 0.9;
`;
container.appendChild(particle);
// 动画循环
function animate() {
const elapsed = Date.now() - startTime;
const progress = elapsed / duration;
if (progress >= 1) {
// 动画结束
if (particle.parentNode) {
particle.parentNode.removeChild(particle);
}
return;
}
// 使用缓动函数降低速度变化
const easeProgress = easeOutQuad(progress);
// 更新位置 - 降低移动速度
posX += angleX * 8 * (1 - easeProgress * 0.5); // 随着时间减慢
velocityY += gravity;
posY += velocityY * 8 * (1 - easeProgress * 0.3); // 随着时间减慢
// 应用位置
particle.style.left = `${x + posX}px`;
particle.style.top = `${y + posY}px`;
// 根据进度调整透明度(更缓慢)
particle.style.opacity = 0.9 - easeProgress * 0.8;
// 根据进度调整大小(轻微缩小)
const scale = 1 - easeProgress * 0.3;
particle.style.transform = `translate(-50%, -50%) scale(${scale})`;
// 继续动画
requestAnimationFrame(animate);
}
animate();
return particle;
} else {
// 创建普通粒子
const particle = document.createElement('div');
particle.className = 'firework-particle';
// 随机颜色
const color = config.colors[Math.floor(Math.random() * config.colors.length)];
// 随机角度和距离
const angle = Math.random() * Math.PI * 2;
// 抛物线参数 - 降低速度
const speed = (0.3 + Math.random() * 0.4) * speedFactor; // 降低速度
const gravity = 0.02; // 减小重力
const angleX = Math.cos(angle) * speed;
const angleY = Math.sin(angle) * speed;
// 初始位置
let posX = 0;
let posY = 0;
let velocityY = angleY;
const startTime = Date.now();
// 粒子大小
const particleSize = size * (0.7 + Math.random() * 0.6);
particle.style.cssText = `
left: ${x}px;
top: ${y}px;
width: ${particleSize}px;
height: ${particleSize}px;
background: ${color};
box-shadow: 0 0 ${particleSize}px ${color};
transform: translate(-50%, -50%);
opacity: 0.9;
`;
container.appendChild(particle);
// 动画循环
function animate() {
const elapsed = Date.now() - startTime;
const progress = elapsed / duration;
if (progress >= 1) {
// 动画结束
if (particle.parentNode) {
particle.parentNode.removeChild(particle);
}
return;
}
// 使用缓动函数降低速度变化
const easeProgress = easeOutQuad(progress);
// 更新位置 - 降低移动速度
posX += angleX * 10 * (1 - easeProgress * 0.6); // 随着时间显著减慢
velocityY += gravity;
posY += velocityY * 10 * (1 - easeProgress * 0.4); // 随着时间减慢
// 应用位置
particle.style.left = `${x + posX}px`;
particle.style.top = `${y + posY}px`;
// 根据进度调整透明度(更缓慢)
particle.style.opacity = 0.9 - easeProgress * 0.85;
// 根据进度调整大小(缓慢缩小)
const scale = 1 - easeProgress * 0.4;
particle.style.transform = `translate(-50%, -50%) scale(${scale})`;
// 继续动画
requestAnimationFrame(animate);
}
animate();
return particle;
}
}
// 创建小烟花
function createSmallFirework(x, y) {
// 创建中心点
createFireworkCenter(x, y, 10);
// 延迟爆炸效果
setTimeout(() => {
// 创建粒子
for (let i = 0; i < config.smallFirework.particleCount; i++) {
setTimeout(() => {
createParticleWithParabola(
x, y,
false,
config.smallFirework.size,
config.smallFirework.duration,
config.smallFirework.speed,
Math.random() < 0.1 // 10%几率生成特殊粒子
);
}, i * 15); // 增加粒子生成间隔
}
}, 50);
}
// 创建大烟花
function createLargeFirework(x, y, pressDuration) {
// 计算烟花大小基于长按时间
const progress = Math.min((pressDuration - config.minLongPressTime) /
(config.maxLongPressTime - config.minLongPressTime), 1);
// 根据进度计算参数
const particleCount = Math.floor(
config.smallFirework.particleCount +
(config.maxLargeFirework.particleCount - config.smallFirework.particleCount) * progress
);
const size = config.smallFirework.size +
(config.maxLargeFirework.size - config.smallFirework.size) * progress;
const duration = config.smallFirework.duration +
(config.maxLargeFirework.duration - config.smallFirework.duration) * progress;
const speedFactor = config.smallFirework.speed +
(config.maxLargeFirework.speed - config.smallFirework.speed) * progress;
// 创建中心点
const centerSize = 10 + progress * 20;
createFireworkCenter(x, y, centerSize);
// 显示提示
const char = config.specialChars[Math.floor(Math.random() * config.specialChars.length)];
showHint(char, x, y, 20 + progress * 12);
// 延迟爆炸效果
setTimeout(() => {
// 创建普通粒子
for (let i = 0; i < particleCount; i++) {
setTimeout(() => {
createParticleWithParabola(
x, y,
true,
size,
duration,
speedFactor,
Math.random() < 0.15 // 15%几率生成特殊粒子
);
}, i * 8); // 增加粒子生成间隔
}
}, 50);
}
// 显示提示
function showHint(text, x, y, fontSize = 20) {
const hint = document.createElement('div');
hint.textContent = text;
hint.style.cssText = `
position: fixed;
left: ${x}px;
top: ${y}px;
color: #FFD700;
font-weight: bold;
font-size: ${fontSize}px;
text-shadow: 0 0 5px #FF0000;
pointer-events: none;
z-index: 999999;
transform: translate(-50%, -50%);
animation: floatUp 2s ease-out forwards;
font-family: 'Microsoft YaHei', sans-serif;
opacity: 0.9;
`;
document.head.insertAdjacentHTML('beforeend', `
`);
document.body.appendChild(hint);
setTimeout(() => {
if (hint.parentNode) {
hint.parentNode.removeChild(hint);
}
}, 2000);
}
// 事件监听器
document.addEventListener('mousedown', function(e) {
// 只响应左键点击
if (e.button !== 0) return;
mouseDownTime = Date.now();
longPressActive = true;
// 创建升起粒子
createLiftParticle(e.clientX, e.clientY);
// 更新进度指示器
updateProgressIndicator(0);
// 设置长按定时器
longPressTimer = setInterval(() => {
const elapsed = Date.now() - mouseDownTime;
const progress = Math.min(elapsed / config.maxLongPressTime, 1) * 100;
updateProgressIndicator(progress);
}, 50);
});
document.addEventListener('mousemove', function(e) {
if (longPressActive && liftParticle) {
// 更新升起粒子的目标位置
liftParticle.targetX = e.clientX;
liftParticle.targetY = e.clientY;
// 更新升起粒子的水平位置
const currentX = parseFloat(liftParticle.element.style.left);
const newX = currentX + (e.clientX - currentX) * 0.08; // 更平滑的跟随
liftParticle.element.style.left = `${newX}px`;
}
});
document.addEventListener('mouseup', function(e) {
// 只响应左键释放
if (e.button !== 0) return;
const pressDuration = Date.now() - mouseDownTime;
// 清除长按定时器
if (longPressTimer) {
clearInterval(longPressTimer);
longPressTimer = null;
}
// 隐藏进度指示器
hideProgressIndicator();
// 移除升起粒子
if (liftParticle) {
if (liftParticle.element && liftParticle.element.parentNode) {
liftParticle.element.parentNode.removeChild(liftParticle.element);
}
clearInterval(liftParticle.trailTimer);
liftParticle = null;
}
// 判断是否为长按
if (pressDuration >= config.minLongPressTime) {
// 长按:生成大烟花,按住时间越长烟花越大
createLargeFirework(e.clientX, e.clientY, pressDuration);
} else {
// 短按:生成小烟花
createSmallFirework(e.clientX, e.clientY);
}
longPressActive = false;
});
// 鼠标移出窗口时结束长按
document.addEventListener('mouseleave', function() {
if (longPressActive) {
longPressActive = false;
if (longPressTimer) {
clearInterval(longPressTimer);
longPressTimer = null;
}
hideProgressIndicator();
// 移除升起粒子
if (liftParticle) {
if (liftParticle.element && liftParticle.element.parentNode) {
liftParticle.element.parentNode.removeChild(liftParticle.element);
}
clearInterval(liftParticle.trailTimer);
liftParticle = null;
}
}
});
// 页面加载完成后添加说明面板
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', createInstructionPanel);
} else {
createInstructionPanel();
}
// 防止脚本重复加载
if (window.hasEnhancedFireworkScript) {
return;
}
window.hasEnhancedFireworkScript = true;
console.log('🎆 优化版鼠标烟花特效已加载!粒子速度已调整。');
})();