Skip to content

Commit

Permalink
Themer - Add theming plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Jun 20, 2024
1 parent dd53d87 commit 7b34f74
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 39 deletions.
13 changes: 13 additions & 0 deletions lib/css/setStyle.ts
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);
5 changes: 4 additions & 1 deletion lib/css/settings.js → lib/css/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const settingsCSS = `
import { setStyle } from "./setStyle";

const settingsStyles = `
.settings-section {
color: #ffffff;
padding: 20px;
Expand All @@ -18,3 +20,4 @@ export const settingsCSS = `
margin-bottom: 15px;
}
`;
setStyle(settingsStyles, "neptune-settings");
6 changes: 0 additions & 6 deletions plugins/AlwaysExclusive/package-lock.json

This file was deleted.

1 change: 0 additions & 1 deletion plugins/AlwaysExclusive/package.json

This file was deleted.

6 changes: 0 additions & 6 deletions plugins/LastFM/package-lock.json

This file was deleted.

1 change: 0 additions & 1 deletion plugins/LastFM/package.json

This file was deleted.

1 change: 1 addition & 0 deletions plugins/LastFM/src/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html } from "@neptune/voby";
// @ts-expect-error Remove this when types are available
import { storage } from "@plugin";
import "../../../lib/css/settings";

storage.displaySkippedScrobbles ??= true;
export const Settings = () => {
Expand Down
6 changes: 0 additions & 6 deletions plugins/RealMAX/package-lock.json

This file was deleted.

1 change: 0 additions & 1 deletion plugins/RealMAX/package.json

This file was deleted.

2 changes: 2 additions & 0 deletions plugins/Shazam/src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { html } from "@neptune/voby";
// @ts-expect-error Remove this when types are available
import { storage } from "@plugin";

import "../../../lib/css/settings";

storage.exitOnFirstMatch ??= true;
storage.startInMiddle ??= true;
export const Settings = () => {
Expand Down
1 change: 1 addition & 0 deletions plugins/SongDownloader/src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { html } from "@neptune/voby";
// @ts-expect-error Remove this when types are available
import { storage } from "@plugin";
import { AudioQualityInverse, AudioQuality, validQualitiesSettings } from "../../../lib/AudioQualityTypes";
import { setStyle } from "../../../lib/css/setStyle";

storage.desiredDownloadQuality ??= AudioQuality.HiRes;
storage.defaultDownloadPath ??= "";
Expand Down
11 changes: 6 additions & 5 deletions plugins/SongDownloader/src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { appendStyle } from "@neptune/utils";
import { settingsCSS } from "../../../lib/css/settings";
import { setStyle } from "../../../lib/css/setStyle";
import "../../../lib/css/settings";

appendStyle(`
${settingsCSS}
const styles = `
.download-button {
align-items: center;
display: flex;
Expand Down Expand Up @@ -55,4 +54,6 @@ ${settingsCSS}
outline: none;
border-color: #4f4f4f;
}
`);
`;

setStyle(styles, "neptune-downloader");
6 changes: 0 additions & 6 deletions plugins/Testing/package-lock.json

This file was deleted.

1 change: 0 additions & 1 deletion plugins/Testing/package.json

This file was deleted.

6 changes: 6 additions & 0 deletions plugins/Themer/plugin.json
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"
}
41 changes: 41 additions & 0 deletions plugins/Themer/src/getDraggable.ts
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;
};
32 changes: 32 additions & 0 deletions plugins/Themer/src/index.ts
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();
};
11 changes: 6 additions & 5 deletions plugins/TidalTags/src/style.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { appendStyle } from "@neptune/utils";
import { settingsCSS } from "../../../lib/css/settings";
import { setStyle } from "../../../lib/css/setStyle";
import "../../../lib/css/settings";

appendStyle(`
${settingsCSS}
const styles = `
span[class^="titleText--"] {
max-width: 190px;
}
Expand Down Expand Up @@ -68,4 +67,6 @@ input:checked + .slider {
input:checked + .slider:before {
transform: translateX(26px);
}
`);
`;

setStyle(styles, "tidal-tags-styles");

0 comments on commit 7b34f74

Please sign in to comment.