要新年了,这不必须来个插件庆祝庆祝春节啊。
提示
使用 SATA 协议!请注意分寸!
壹、构思
加点什么喜庆的元素呢?
烟花,灯笼,春联,窗花?
春联与窗花貌似不太适合作为网页摆设。
于是选择烟花与灯笼,这片文章也只实现烟花与灯笼。
贰、烟花
众所周知,有个东西叫做 Fireworks.js,做出来的还蛮好看的。
一不小心玩上了。
看文档,我们可以直接 require,new Fireworks(container, {...}).start()。
然后好了。
叁、灯笼
自己写肯定不好看呢,于是找到了 https://www.cnblogs.com/zhangapple/p/18520514。
甚是好看,不过位置得条条。
然后好了。
肆、代码
代码
// ==UserScript==
// @name Amazing Luogu 新春祝福
// @namespace https://amlg.top/
// @version 1.2
// @description Amazing Luogu 新春祝福
// @author zym2013
// @match *://*.luogu.com.cn/*
// @grant GM_setValue
// @grant GM_getValue
// @require https://cdn.jsdmirror.com/npm/fireworks-js@latest/dist/fireworks.js
// @connect cdn.jsdmirror.com
// @run-at document-end
// ==/UserScript==
(function () {
'use strict';
function createDengContainer() {
const container = document.createElement('div');
container.className = 'deng-container';
const defaultText = "新春快乐";
const texts = defaultText.split('');
texts.forEach((text, index) => {
if (index >= 4) return;
const box = document.createElement('div');
box.className = `deng-box deng-box${index + 1}`;
const deng = document.createElement('div');
deng.className = 'deng';
const xian = document.createElement('div');
xian.className = 'xian';
const dengA = document.createElement('div');
dengA.className = 'deng-a';
const dengB = document.createElement('div');
dengB.className = 'deng-b';
const dengT = document.createElement('div');
dengT.className = 'deng-t';
dengT.textContent = text;
dengB.appendChild(dengT);
dengA.appendChild(dengB);
deng.appendChild(xian);
deng.appendChild(dengA);
const shuiA = document.createElement('div');
shuiA.className = 'shui shui-a';
const shuiC = document.createElement('div');
shuiC.className = 'shui-c';
const shuiB = document.createElement('div');
shuiB.className = 'shui-b';
shuiA.appendChild(shuiC);
shuiA.appendChild(shuiB);
deng.appendChild(shuiA);
box.appendChild(deng);
container.appendChild(box);
});
document.body.appendChild(container);
}
function addStyles() {
const style = document.createElement('style');
style.type = 'text/css';
style.textContent = `
.deng-container {
position: relative;
top: 10px;
opacity: 0.9;
z-index: 9999;
pointer-events: none;
}
.deng-box {
position: fixed;
right: 10px;
}
.deng-box1 { position: fixed; top: 15px; left: 10px; }
.deng-box2 { position: fixed; top: 12px; left: 140px; }
.deng-box3 { position: fixed; top: 10px; right: 140px; }
.deng-box4 { position: fixed; top: 10px; right: 10px; }
.deng {
position: relative;
width: 120px;
height: 90px;
background: rgba(216, 0, 15, .8);
border-radius: 50% 50%;
animation: swing 3s infinite ease-in-out;
box-shadow: -5px 5px 50px 4px #fa6c00;
}
.deng-a {
width: 100px;
height: 90px;
background: rgba(216, 0, 15, .1);
border-radius: 50%;
border: 2px solid #dc8f03;
margin-left: 7px;
display: flex;
justify-content: center;
}
.deng-b {
width: 65px;
height: 83px;
background: rgba(216, 0, 15, .1);
border-radius: 60%;
border: 2px solid #dc8f03;
}
.xian {
position: absolute;
top: -20px;
left: 60px;
width: 2px;
height: 20px;
background: #dc8f03;
}
.shui-a {
position: relative;
width: 5px;
height: 20px;
margin: -5px 0 0 59px;
animation: swing 4s infinite ease-in-out;
transform-origin: 50% -45px;
background: orange;
border-radius: 0 0 5px 5px;
}
.shui-b {
position: absolute;
top: 14px;
left: -2px;
width: 10px;
height: 10px;
background: #dc8f03;
border-radius: 50%;
}
.shui-c {
position: absolute;
top: 18px;
left: -2px;
width: 10px;
height: 35px;
background: orange;
border-radius: 0 0 0 5px;
}
.deng:before, .deng:after {
content: " ";
display: block;
position: absolute;
border-radius: 5px;
border: solid 1px #dc8f03;
background: linear-gradient(to right, #dc8f03, orange, #dc8f03, orange, #dc8f03);
}
.deng:before {
top: -7px; left: 29px; height: 12px; width: 60px; z-index: 999;
}
.deng:after {
bottom: -7px; left: 10px; height: 12px; width: 60px; margin-left: 20px;
}
.deng-t {
font-family: '华文行楷', Arial, Lucida Grande, Tahoma, sans-serif;
font-size: 3.2rem;
color: #dc8f03;
font-weight: 700;
line-height: 85px;
text-align: center;
}
@media (max-width: 768px) {
.deng-t { font-size: 2.5rem; }
.deng-box { transform: scale(0.5); top: -15px; }
.deng-box1 { left: -22%; }
.deng-box2 { left: 0px; }
.deng-box3 { right: 50px; }
.deng-box4 { right: -10px; }
}
@keyframes swing {
0% { transform: rotate(-10deg); }
50% { transform: rotate(10deg); }
100% { transform: rotate(-10deg); }
}
`;
document.head.appendChild(style);
}
function createBlessingBox() {
if(GM_getValue('blessingBox')) return;
const overlay = document.createElement('div');
overlay.className = 'al-blessing-overlay';
overlay.innerHTML = `
<div class="al-blessing-box">
<div class="al-blessing-header">
<h1>🎉 来自 Amazing Luogu 的祝福 ~~~ 🎉</h1>
</div>
<div class="al-blessing-body">
<div class="al-greeting">
<p class="al-big-text">代码无 Bug,Rating 日日升</p>
<p class="al-sub-text">AC 不停,排名周周前</p>
</div>
<div class="al-divider"></div>
<div class="al-wishes">
<p class="al-wish-title">🏮 Amazing Luogu 还祝你: 🏮</p>
<p>一帆风顺 · 二龙腾飞 · 三阳开泰 · 四季平安</p>
<p>五福临门 · 六六大顺 · 七星高照 · 八方来财</p>
<p>九九同心 · 十全十美</p>
</div>
<div class="al-footer">
<p>✨ 感谢一路相伴,Amazing Luogu 与你共赴星辰 ✨</p>
<p class="al-close-hint"> 点击 <span class="al-close-icon">✕</span> 关闭,脚本停用即可去除灯笼与烟花。</p>
<p class="al-copyright">© 2026 Amazing Luogu</p>
</div>
</div>
<button class="al-close-btn" aria-label="关闭祝福框">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 16 16"><path fill="currentColor" d="M5.28 4.22a.75.75 0 0 0-1.06 1.06L6.94 8l-2.72 2.72a.75.75 0 1 0 1.06 1.06L8 9.06l2.72 2.72a.75.75 0 1 0 1.06-1.06L9.06 8l2.72-2.72a.75.75 0 0 0-1.06-1.06L8 6.94z"/></svg>
</button>
</div>
`;
document.body.appendChild(overlay);
const style = document.createElement('style');
style.textContent = `
@import url('https://cdn.jsdmirror.com/npm/lxgw-wenkai-screen-webfont@1.7.0/style.min.css');
.al-blessing-overlay {
position: fixed;
inset: 0;
background: rgba(10, 8, 15, 0.75);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
display: flex;
justify-content: center;
align-items: center;
z-index: 10001;
animation: al-fadeIn 0.5s cubic-bezier(0.23, 1, 0.32, 1);
}
.al-blessing-box {
background: radial-gradient(circle at 20% 30%, #ff8a5c, #b71c1c);
border: 4px solid rgba(255, 215, 0, 0.9);
border-radius: 48px 48px 32px 32px;
padding: 32px 36px;
max-width: 600px;
width: 85%;
text-align: center;
box-shadow:
0 20px 40px rgba(0, 0, 0, 0.6),
0 0 0 2px rgba(255, 230, 100, 0.3),
0 0 40px rgba(255, 180, 40, 0.7);
position: relative;
color: #fffbe3;
font-family: 'LXGW Wenkai Screen', 'Noto Serif SC', serif;
animation: al-popIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
transform-origin: center;
backdrop-filter: blur(4px);
border-bottom: 8px solid #ffb347;
}
.al-blessing-header h1 {
font-size: 32px;
margin: 0 0 16px;
font-weight: 800;
color: #ffecaa;
text-shadow: 0 2px 6px #a83232;
-webkit-background-clip: text;
background-clip: text;
}
.al-greeting {
margin: 16px 0 20px;
}
.al-big-text {
font-size: 26px;
font-weight: 700;
margin: 0 0 6px;
color: #ffecaa;
text-shadow: 0 2px 6px #a83232;
line-height: 1.3;
}
.al-sub-text {
font-size: 20px;
margin: 4px 0;
color: #ffdab3;
opacity: 0.95;
letter-spacing: 2px;
}
.al-divider {
width: 80px;
height: 3px;
background: linear-gradient(to right, transparent, #ffe48f, #ffb84d, #ffe48f, transparent);
margin: 20px auto;
border-radius: 4px;
}
.al-wishes {
background: rgba(30, 12, 8, 0.45);
backdrop-filter: blur(2px);
padding: 20px 16px;
border-radius: 36px 12px 36px 12px;
border: 1px solid rgba(255, 210, 90, 0.8);
box-shadow: inset 0 0 20px rgba(255, 215, 0, 0.3);
margin: 16px 0 12px;
}
.al-wish-title {
font-size: 20px;
font-weight: bold;
margin: 0 0 12px;
color: #ffec9e;
letter-spacing: 4px;
text-shadow: 0 0 4px #ff6700;
}
.al-wishes p {
font-size: 17px;
margin: 8px 0;
color: #fff4cc;
font-weight: 500;
text-shadow: 0 1px 3px #4a1e1e;
line-height: 1.6;
}
.al-footer {
margin-top: 24px;
}
.al-footer p {
font-size: 16px;
margin: 8px 0;
color: #ffeab5;
}
.al-close-hint {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
background: rgba(255, 255, 220, 0.18);
padding: 8px 18px;
border-radius: 60px;
border: 1px solid #ffbe5c;
font-size: 15px;
margin: 16px 0 4px;
backdrop-filter: blur(4px);
}
.al-close-icon {
display: inline-flex;
background: #ffad5c;
color: #2f0a0a;
width: 22px;
height: 22px;
border-radius: 50%;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 14px;
}
.al-copyright {
opacity: 0.8;
font-size: 14px;
letter-spacing: 2px;
margin-top: 12px;
border-top: 1px dashed #ffb677;
padding-top: 12px;
}
.al-close-btn {
position: absolute;
top: 16px;
right: 16px;
width: 40px;
height: 40px;
background: rgba(0,0,0,0.25);
color: #ffecaa;
border: 2px solid #ffbf5e;
border-radius: 50%;
font-size: 20px;
cursor: pointer;
transition: all 0.25s ease;
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(10px);
padding: 0;
}
.al-close-btn:hover {
background: #ff8c5a;
color: #1e0e0a;
border-color: #ffdb8e;
transform: rotate(90deg) scale(1.1);
box-shadow: 0 0 18px #ffa55c;
}
.al-close-btn svg {
width: 18px;
height: 18px;
fill: currentColor;
}
@keyframes al-fadeIn {
0% { opacity: 0; backdrop-filter: blur(0); }
100% { opacity: 1; backdrop-filter: blur(12px); }
}
@keyframes al-popIn {
0% { transform: scale(0.5) translateY(40px); opacity: 0; }
80% { transform: scale(1.02); }
100% { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes al-fadeOut {
to { opacity: 0; backdrop-filter: blur(0); transform: scale(0.9); }
}
@media (max-width: 540px) {
.al-blessing-box { padding: 24px 18px; width: 90%; }
.al-blessing-header h1 { font-size: 24px; }
.al-big-text { font-size: 22px; }
}
`;
document.head.appendChild(style);
overlay.querySelector('.al-close-btn').addEventListener('click', () => {
overlay.style.animation = 'al-fadeOut 0.35s forwards';
GM_setValue('blessingBox', 1);
setTimeout(() => overlay.remove(), 400);
});
}
async function init() {
addStyles();
createDengContainer();
const container = document.createElement('div');
container.id = 'fireworks-container';
Object.assign(container.style, {
position: 'fixed',
top: '0',
left: '0',
width: '100%',
height: '100%',
pointerEvents: 'none',
zIndex: '9998'
});
document.body.appendChild(container);
new Fireworks(container, {
hue: { min: 0, max: 360 },
delay: { min: 20, max: 40 },
rocketsPoint: '100%',
speed: 1.2,
acceleration: 1.02,
friction: 0.95,
gravity: 1.1,
particles: 70,
traceLength: 3,
traceSpeed: 8,
explosion: 5,
autoresize: true,
brightness: { min: 50, max: 80 },
boundaries: { visible: false },
sound: { enabled: false }
}).start();
setTimeout(createBlessingBox, 1200);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();