Flarum 使用
在自定义页脚添加:
<script>
((n, c) => {
// 1. 注入 CSS:优化了过渡属性(transition: all .3s) 和 动画帧(仅保留 to 帧)
document.head.insertAdjacentHTML('beforeend', `
<style>
#app { display: flex!important; flex-direction: column!important; min-height: 100vh!important; padding-bottom: 0!important }
.m-f { margin-top: auto; display: flex; flex-direction: column; align-items: center; padding: 20px 0; gap: 8px; opacity: 0; transform: translateY(333px); animation: fU var(--anim-duration,4s) var(--anim-easing,cubic-bezier(.25,1,.5,1)) forwards }
@keyframes fU { to { opacity: 1; transform: translateY(0) } }
.m-f.svg { opacity: 1; transform: translateY(0); animation: none }
.m-f svg { display: flex; justify-content: center; width: 100%; transition: all .3s; filter: drop-shadow(0 8px 12px rgba(0,0,0,.1)); cursor: pointer }
.m-f svg:hover { transform: scale(1.05); filter: drop-shadow(0 12px 16px rgba(0,0,0,.15)) }
.m-f img { width: min(400px,85%) }
</style>
`);
const r = () => {
const a = document.getElementById('app');
// 如果存在 #app 且还没注入过 .m-f 容器
if (a && !a.querySelector('.m-f')) {
// 2. 注入 HTML,将冗余的 span 合并
a.insertAdjacentHTML('beforeend', `<div class="m-f"><a href="https://love4z.cn/moec/" target="_blank"></a><span style="font-size:12px;letter-spacing:1px;color:${c};font-weight:bold">MoeCounter</span></div>`);
// 3. 直接通过子节点引用提高效率,替代 querySelector
const m = a.lastChild;
const e = m.firstChild;
// 添加类名状态 (用 true 的等价物 1 替代)
m.addEventListener('animationend', () => m.classList.add('a'), { once: 1 });
// 4. Promise 链式短路请求替代 try/catch,更加清爽
fetch(`https://love4z.cn/moec/?name=${n}`)
.then(t => t.ok && t.text())
.then(t => t && (e.innerHTML = t))
.catch(t => console.error('L 404', t));
}
};
new MutationObserver(r).observe(document.body, { childList: 1, subtree: 1 });
r();
})('', '#ffb6c1');
</script>
最末端的 是自定义计数器名称,请自行替换
也可以替换成自己部署的
https://love4z.cn/moec
顺便解决了NT Firefox Nightly Gif动画静止的问题
https://discuss.flarum.org/d/39268-moecounterre