mirror of
https://github.com/NeonGamerBot-QK/saahild.com.git
synced 2025-07-20 20:59:04 +00:00
enhancement(lint): Fix lint errors for lib/jsscripts/oneko.ts
Co-authored-by: NeonGamerBot-QK <neon@saahild.com> Signed-off-by: zeon-neon[bot] <136533918+zeon-neon[bot]@users.noreply.github.com>
This commit is contained in:
parent
3d5d7d0d02
commit
b0ac19a4f6
1 changed files with 288 additions and 287 deletions
|
@ -3,7 +3,8 @@
|
||||||
// oneko.js: https://github.com/adryd325/oneko.js
|
// oneko.js: https://github.com/adryd325/oneko.js
|
||||||
|
|
||||||
export function injectOneko() {
|
export function injectOneko() {
|
||||||
const isReducedMotion = window.matchMedia(`(prefers-reduced-motion: reduce)`).matches === true;
|
const isReducedMotion =
|
||||||
|
window.matchMedia(`(prefers-reduced-motion: reduce)`).matches === true;
|
||||||
|
|
||||||
if (isReducedMotion) return;
|
if (isReducedMotion) return;
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ export function injectOneko() {
|
||||||
|
|
||||||
let frameCount = 0;
|
let frameCount = 0;
|
||||||
let idleTime = 0;
|
let idleTime = 0;
|
||||||
let idleAnimation:any = null;
|
let idleAnimation: any = null;
|
||||||
let idleAnimationFrame = 0;
|
let idleAnimationFrame = 0;
|
||||||
|
|
||||||
const nekoSpeed = 10;
|
const nekoSpeed = 10;
|
||||||
|
@ -96,10 +97,10 @@ export function injectOneko() {
|
||||||
nekoEl.style.top = `${nekoPosY - 16}px`;
|
nekoEl.style.top = `${nekoPosY - 16}px`;
|
||||||
nekoEl.style.zIndex = "99999999";
|
nekoEl.style.zIndex = "99999999";
|
||||||
|
|
||||||
let nekoFile = "https://saahild.com/oneko.gif"
|
let nekoFile = "https://saahild.com/oneko.gif";
|
||||||
const curScript = document.currentScript
|
const curScript = document.currentScript;
|
||||||
if (curScript && curScript.dataset.cat) {
|
if (curScript && curScript.dataset.cat) {
|
||||||
nekoFile = curScript.dataset.cat
|
nekoFile = curScript.dataset.cat;
|
||||||
}
|
}
|
||||||
nekoEl.style.backgroundImage = `url(${nekoFile})`;
|
nekoEl.style.backgroundImage = `url(${nekoFile})`;
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ export function injectOneko() {
|
||||||
window.requestAnimationFrame(onAnimationFrame);
|
window.requestAnimationFrame(onAnimationFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
let lastFrameTimestamp: any ;
|
let lastFrameTimestamp: any;
|
||||||
|
|
||||||
function onAnimationFrame(timestamp: any) {
|
function onAnimationFrame(timestamp: any) {
|
||||||
// Stops execution if the neko element is removed from DOM
|
// Stops execution if the neko element is removed from DOM
|
||||||
|
@ -124,8 +125,8 @@ export function injectOneko() {
|
||||||
lastFrameTimestamp = timestamp;
|
lastFrameTimestamp = timestamp;
|
||||||
}
|
}
|
||||||
if (timestamp - lastFrameTimestamp > 100) {
|
if (timestamp - lastFrameTimestamp > 100) {
|
||||||
lastFrameTimestamp = timestamp
|
lastFrameTimestamp = timestamp;
|
||||||
frame()
|
frame();
|
||||||
}
|
}
|
||||||
window.requestAnimationFrame(onAnimationFrame);
|
window.requestAnimationFrame(onAnimationFrame);
|
||||||
}
|
}
|
||||||
|
@ -206,9 +207,9 @@ export function injectOneko() {
|
||||||
const centerY = rect.top + rect.height / 2 + scrollTop;
|
const centerY = rect.top + rect.height / 2 + scrollTop;
|
||||||
|
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
const heart = document.createElement('div');
|
const heart = document.createElement("div");
|
||||||
heart.className = 'heart';
|
heart.className = "heart";
|
||||||
heart.textContent = '❤';
|
heart.textContent = "❤";
|
||||||
const offsetX = (Math.random() - 0.5) * 50;
|
const offsetX = (Math.random() - 0.5) * 50;
|
||||||
const offsetY = (Math.random() - 0.5) * 50;
|
const offsetY = (Math.random() - 0.5) * 50;
|
||||||
heart.style.left = `${centerX + offsetX - 16}px`;
|
heart.style.left = `${centerX + offsetX - 16}px`;
|
||||||
|
@ -222,7 +223,7 @@ export function injectOneko() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const style = document.createElement('style');
|
const style = document.createElement("style");
|
||||||
style.innerHTML = `
|
style.innerHTML = `
|
||||||
@keyframes heartBurst {
|
@keyframes heartBurst {
|
||||||
0% { transform: scale(0); opacity: 1; }
|
0% { transform: scale(0); opacity: 1; }
|
||||||
|
@ -238,7 +239,7 @@ export function injectOneko() {
|
||||||
`;
|
`;
|
||||||
|
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
nekoEl.addEventListener('click', explodeHearts);
|
nekoEl.addEventListener("click", explodeHearts);
|
||||||
|
|
||||||
function frame() {
|
function frame() {
|
||||||
frameCount += 1;
|
frameCount += 1;
|
||||||
|
@ -283,5 +284,5 @@ export function injectOneko() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stopOneko() {
|
export function stopOneko() {
|
||||||
return document.getElementById('oneko')?.remove()
|
return document.getElementById("oneko")?.remove();
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue