mirror of
https://github.com/meowarex/TidaLuna-Plugins.git
synced 2026-06-18 03:43:10 +10:00
Switch to StyleTags
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { LunaUnload, Tracer } from "@luna/core";
|
||||
import { StyleTag } from "@luna/lib";
|
||||
|
||||
// Import CSS directly using Luna's file:// syntax
|
||||
import unlockSelection from "file://styles.css?minify";
|
||||
@@ -8,13 +9,8 @@ export const { trace } = Tracer("[Copy Lyrics]");
|
||||
// clean up resources
|
||||
export const unloads = new Set<LunaUnload>();
|
||||
|
||||
function ApplyCSS(style: string): HTMLStyleElement {
|
||||
const styleElement = document.createElement("style");
|
||||
styleElement.type = "text/css";
|
||||
styleElement.textContent = style;
|
||||
document.head.appendChild(styleElement);
|
||||
return styleElement;
|
||||
}
|
||||
// StyleTag for lyrics selection styling
|
||||
const lyricsStyleTag = new StyleTag("Copy-Lyrics", unloads, unlockSelection);
|
||||
|
||||
function SetClipboard(text: string): void {
|
||||
const textarea = document.createElement("textarea");
|
||||
@@ -33,8 +29,6 @@ function SetClipboard(text: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
const styleElement = ApplyCSS(unlockSelection);
|
||||
|
||||
let isSelecting = false;
|
||||
|
||||
const onMouseDown = function (): void {
|
||||
@@ -117,10 +111,6 @@ document.addEventListener("mouseup", onMouseUp);
|
||||
|
||||
// Add cleanup to unloads
|
||||
unloads.add(() => {
|
||||
if (styleElement.parentNode) {
|
||||
styleElement.parentNode.removeChild(styleElement);
|
||||
}
|
||||
|
||||
// Remove event listeners
|
||||
document.removeEventListener("click", onClickHooked, true);
|
||||
document.removeEventListener("mousedown", onMouseDown);
|
||||
|
||||
Reference in New Issue
Block a user