This commit is contained in:
SethBurkart123
2025-03-30 10:41:19 +11:00
parent e3f4b59d9c
commit 19cc1a5600
17 changed files with 361 additions and 159 deletions
@@ -0,0 +1,72 @@
import type { Plugin } from '../../core/types';
import styles from './styles.css?inline';
import { BasePlugin, NumberSetting } from '../../core/settings';
class AnimatedBackgroundPluginClass extends BasePlugin {
@NumberSetting({
default: 1,
title: "Animation Speed",
description: "Controls the speed of the animated background",
min: 0.1,
max: 2
})
speed!: number;
}
const settingsInstance = new AnimatedBackgroundPluginClass();
const animatedBackgroundPlugin: Plugin<typeof settingsInstance.settings> = {
id: 'animated-background',
name: 'Animated Background',
description: 'Adds an animated background to BetterSEQTA+',
version: '1.0.0',
disableToggle: true,
styles,
settings: settingsInstance.settings,
run: async (api) => {
// Create the background elements
const container = document.getElementById("container");
const menu = document.getElementById("menu");
if (!container || !menu) {
return () => {};
}
const backgrounds = [
{ classes: ["bg"] },
{ classes: ["bg", "bg2"] },
{ classes: ["bg", "bg3"] }
];
backgrounds.forEach(({ classes }) => {
const bk = document.createElement("div");
classes.forEach(cls => bk.classList.add(cls));
container.insertBefore(bk, menu);
});
// Set initial speed
updateAnimationSpeed(api.settings.speed);
// Listen for speed changes
const speedUnregister = api.settings.onChange('speed', updateAnimationSpeed);
// Return cleanup function
return () => {
speedUnregister.unregister();
// Remove background elements
const backgrounds = document.getElementsByClassName('bg');
Array.from(backgrounds).forEach(element => element.remove());
};
}
};
function updateAnimationSpeed(speed: number) {
const bgElements = document.getElementsByClassName('bg');
Array.from(bgElements).forEach((element, index) => {
const baseSpeed = index === 0 ? 3 : index === 1 ? 4 : 5;
(element as HTMLElement).style.animationDuration = `${baseSpeed / speed}s`;
});
}
export default animatedBackgroundPlugin;
@@ -0,0 +1,31 @@
.bg {
animation: slide 3s ease-in-out infinite alternate;
background: var(--better-main);
bottom: 0;
left: -50%;
opacity: 0.5;
position: fixed;
right: -50%;
top: 0;
z-index: 0 !important;
overflow: hidden;
scale: 1.5;
}
.bg2 {
animation-direction: alternate-reverse;
animation-duration: 4s;
}
.bg3 {
animation-duration: 5s;
}
@keyframes slide {
0% {
transform: translate(50%) rotate(-60deg);
}
100% {
transform: translateX(5%) rotate(-60deg);
}
}
@@ -0,0 +1,24 @@
export function CreateBackground() {
const bkCheck = document.getElementsByClassName("bg");
if (bkCheck.length !== 0) {
return;
}
// Creating and inserting 3 divs containing the background applied to the pages
const container = document.getElementById("container");
const menu = document.getElementById("menu");
if (!container || !menu) return;
const backgrounds = [
{ classes: ["bg"] },
{ classes: ["bg", "bg2"] },
{ classes: ["bg", "bg3"] }
];
backgrounds.forEach(({ classes }) => {
const bk = document.createElement("div");
classes.forEach(cls => bk.classList.add(cls));
container.insertBefore(bk, menu);
});
}
@@ -0,0 +1,6 @@
export function RemoveBackground() {
const backgrounds = document.getElementsByClassName("bg");
// Convert HTMLCollection to Array and remove each element
Array.from(backgrounds).forEach(element => element.remove());
}