generated from uwu/neptune-template
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
112 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const setStyle = (cssString: string, styleId: string) => { | ||
// Check if the style tag already exists | ||
let styleTag = document.getElementById(styleId); | ||
// If the style tag doesn't exist, create it | ||
if (!styleTag) { | ||
styleTag = document.createElement("style"); | ||
styleTag.id = styleId; | ||
document.head.appendChild(styleTag); | ||
} | ||
// Update the content of the style tag | ||
styleTag.innerHTML = cssString; | ||
}; | ||
export const getStyle = (styleId: string) => document.getElementById(styleId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "Themer", | ||
"description": "Create your own themes!", | ||
"author": "Inrixia", | ||
"main": "./src/index.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { getStyle, setStyle } from "../../../lib/css/setStyle"; | ||
|
||
// @ts-expect-error Remove this when types are available | ||
import { storage } from "@plugin"; | ||
|
||
export const draggableId = "__Themer__Draggable"; | ||
export const draggableStyleId = `${draggableId}__Style`; | ||
export const getDraggable = () => { | ||
let draggable = document.getElementById(draggableId); | ||
if (!draggable) { | ||
draggable = document.createElement("div"); | ||
draggable.id = draggableId; | ||
draggable.style.width = "300px"; | ||
draggable.style.height = "200px"; | ||
draggable.style.position = "absolute"; | ||
draggable.style.top = "100px"; | ||
draggable.style.left = "100px"; | ||
draggable.style.border = "1px solid #ccc"; | ||
draggable.style.backgroundColor = "#f9f9f9"; | ||
draggable.style.resize = "both"; | ||
draggable.style.overflow = "auto"; | ||
draggable.style.padding = "10px"; | ||
draggable.style.cursor = "move"; | ||
draggable.style.zIndex = "1000"; | ||
|
||
// Create and style the textarea | ||
let textarea = document.createElement("textarea"); | ||
textarea.style.width = "100%"; | ||
textarea.style.height = "100%"; | ||
textarea.style.boxSizing = "border-box"; | ||
textarea.rows = 10; | ||
textarea.cols = 50; | ||
textarea.placeholder = "Enter css styles here..."; | ||
textarea.value = storage.css; | ||
textarea.addEventListener("keyup", (e) => setStyle((storage.css = (<HTMLTextAreaElement>e.target).value), draggableStyleId)); | ||
|
||
draggable.appendChild(textarea); | ||
document.body.appendChild(draggable); | ||
} | ||
return draggable; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getStyle } from "../../../lib/css/setStyle"; | ||
import { draggableId, draggableStyleId, getDraggable } from "./getDraggable"; | ||
|
||
const draggable = getDraggable(); | ||
// Make the container draggable | ||
let isDragging = false; | ||
let offsetX: number, offsetY: number; | ||
|
||
const onMouseDown = (e: MouseEvent) => { | ||
isDragging = true; | ||
offsetX = e.clientX - draggable.getBoundingClientRect().left; | ||
offsetY = e.clientY - draggable.getBoundingClientRect().top; | ||
}; | ||
const onMouseMove = (e: MouseEvent) => { | ||
if (!isDragging) return; | ||
draggable.style.left = `${e.clientX - offsetX}px`; | ||
draggable.style.top = `${e.clientY - offsetY}px`; | ||
}; | ||
const onMouseUp = () => { | ||
isDragging = false; | ||
}; | ||
|
||
draggable.addEventListener("mousedown", onMouseDown); | ||
document.addEventListener("mousemove", onMouseMove); | ||
document.addEventListener("mouseup", onMouseUp); | ||
export const onUnload = () => { | ||
draggable.removeEventListener("mousedown", onMouseDown); | ||
document.removeEventListener("mousemove", onMouseMove); | ||
document.removeEventListener("mouseup", onMouseUp); | ||
draggable.remove(); | ||
getStyle(draggableStyleId)?.remove(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters