generated from replugged-org/plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Catalyst4222/main
lint: re-enable and fix linting
- Loading branch information
Showing
5 changed files
with
68 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,79 @@ | ||
import { Injector, Logger, webpack } from "replugged"; | ||
import { Logger } from "replugged"; | ||
|
||
const inject = new Injector(); | ||
const logger = Logger.plugin("ThemeHooker"); | ||
|
||
export async function start(): Promise<void> { | ||
console.log(`[ThemeHooker] ThemeHooker has now started.`) | ||
const ThemeNames: string[] = [ | ||
"mint-apple", | ||
"citrus-sherbert", | ||
"retro-raincloud", | ||
"hanami", | ||
"sunrise", | ||
"cotton-candy", //Candyfloss | ||
"lofi-vibes", | ||
"desert-khaki", | ||
"sunset", | ||
"chroma-glow", | ||
"forest", | ||
"crimson-moon", | ||
"midnight-burple", | ||
"mars", | ||
"dusk", | ||
"under-the-sea", | ||
"retro-storm", | ||
"neon-lights", | ||
"strawberry-lemonade", | ||
"aurora", | ||
"sepia", | ||
"easter-egg", //Memory Lane | ||
]; | ||
|
||
const html = document.documentElement; | ||
const {body} = document; | ||
let ThemeNames: string[] = [ | ||
"mint-apple", | ||
"citrus-sherbert", | ||
"retro-raincloud", | ||
"hanami", | ||
"sunrise", | ||
"cotton-candy", //Candyfloss | ||
"lofi-vibes", | ||
"desert-khaki", | ||
"sunset", | ||
"chroma-glow", | ||
"forest", | ||
"crimson-moon", | ||
"midnight-burple", | ||
"mars", | ||
"dusk", | ||
"under-the-sea", | ||
"retro-storm", | ||
"neon-lights", | ||
"strawberry-lemonade", | ||
"aurora", | ||
"sepia", | ||
"easter-egg" //Memory Lane | ||
] | ||
|
||
html.setAttribute("theme-hooker", "theme-null"); | ||
console.log(`[ThemeHooker] Added "theme-hooker" to the <html> tag.`); | ||
function setTheme(): void { | ||
const { body, documentElement: html } = document; | ||
|
||
detectTheme(); | ||
|
||
function detectTheme() { | ||
for (let ThemeNumber in ThemeNames) { | ||
try { | ||
if(document.querySelector('style[data-client-themes="true"]').textContent.includes(ThemeNames[ThemeNumber])) { | ||
console.log(`[ThemeHooker] Detected Theme: "${ ThemeNames[ThemeNumber] }".`) | ||
html.setAttribute("theme-hooker", `theme-${ ThemeNames[ThemeNumber]}`); | ||
body.setAttribute("theme-hooker", `theme-${ ThemeNames[ThemeNumber]}`); | ||
break | ||
} | ||
} | ||
catch { | ||
html.setAttribute("theme-hooker", `theme-null`); | ||
body.setAttribute("theme-hooker", `theme-null`); | ||
for (const Theme of ThemeNames) { | ||
try { | ||
if ( | ||
document.querySelector?.('style[data-client-themes="true"]')?.textContent?.includes?.(Theme) | ||
) { | ||
logger.log(`Detected Theme: "${Theme}".`); | ||
html.setAttribute("theme-hooker", `theme-${Theme}`); | ||
body.setAttribute("theme-hooker", `theme-${Theme}`); | ||
break; | ||
} | ||
} catch { | ||
html.setAttribute("theme-hooker", `theme-null`); | ||
body.setAttribute("theme-hooker", `theme-null`); | ||
} | ||
} | ||
} | ||
|
||
export function start(): void { | ||
logger.log(`ThemeHooker has now started.`); | ||
|
||
const html = document.documentElement; | ||
|
||
html.setAttribute("theme-hooker", "theme-null"); | ||
logger.log(`Added "theme-hooker" to the <html> tag.`); | ||
|
||
setTheme(); | ||
|
||
const TrackedMutation = document.head; | ||
const MutationConfig = { attributes: true, childList: true, subtree: true }; | ||
|
||
const TrackerReaction = (mutationList, Tracking) => { | ||
const Tracking = new MutationObserver((mutationList) => { | ||
for (const mutation of mutationList) { | ||
if (mutation.type === "childList") { | ||
console.log("[ThemeHooker] Child List Modification detected, trying to detect the current theme."); | ||
detectTheme(); | ||
logger.log("Child List Modification detected, trying to detect the current theme."); | ||
setTheme(); | ||
} else if (mutation.type === "attributes") { | ||
console.log(`[ThemeHooker] Attribute Modification detected, trying to detect the current theme.`); | ||
detectTheme(); | ||
logger.log(`Attribute Modification detected, trying to detect the current theme.`); | ||
setTheme(); | ||
// @ts-expect-error Probably included for a reason? | ||
} else if (mutation.type === "subtree") { | ||
console.log(`[ThemeHooker] Subtree Modification detected, trying to detect the current theme.`); | ||
detectTheme(); | ||
logger.log(`Subtree Modification detected, trying to detect the current theme.`); | ||
setTheme(); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const Tracking = new MutationObserver(TrackerReaction); | ||
Tracking.observe(TrackedMutation, MutationConfig); | ||
|
||
} | ||
|
||
export function stop(): void { | ||
inject.uninjectAll(); | ||
Tracking.observe(document.head, MutationConfig); | ||
} | ||
|