From 5edc94062c2940a415edb8d66fe9fb346b9cb4fb Mon Sep 17 00:00:00 2001 From: V Date: Thu, 9 Nov 2023 02:42:24 +0100 Subject: [PATCH 01/20] make packageManager key less specific --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3307d7d..1bc2129f 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "typescript": "^5.0.4", "zip-local": "^0.3.5" }, - "packageManager": "pnpm@8.1.1", + "packageManager": "^pnpm@8.1.1", "pnpm": { "patchedDependencies": { "eslint-plugin-path-alias@1.0.0": "patches/eslint-plugin-path-alias@1.0.0.patch", From 9bd82943e3f178324e38eebe8a683cc1c1ded94c Mon Sep 17 00:00:00 2001 From: AM Date: Thu, 9 Nov 2023 03:42:35 +0000 Subject: [PATCH 02/20] [Plugin] Super Reaction Tweaks (#1958) Co-authored-by: V Co-authored-by: Jack Matthews --- src/plugins/superReactionTweaks/README.md | 11 ++++ src/plugins/superReactionTweaks/index.ts | 63 +++++++++++++++++++++++ src/utils/constants.ts | 4 ++ 3 files changed, 78 insertions(+) create mode 100644 src/plugins/superReactionTweaks/README.md create mode 100644 src/plugins/superReactionTweaks/index.ts diff --git a/src/plugins/superReactionTweaks/README.md b/src/plugins/superReactionTweaks/README.md new file mode 100644 index 00000000..624ab866 --- /dev/null +++ b/src/plugins/superReactionTweaks/README.md @@ -0,0 +1,11 @@ +# Super Reaction Tweaks + +This plugin applies configurable various tweaks to super reactions. + +![Screenshot](https://user-images.githubusercontent.com/22851444/281598795-58f07116-9f95-4f64-940b-23a5499f2302.png) + +## Features: + +**Super React By Default** - The reaction picker will default to super reactions instead of normal reactions. + +**Super Reaction Play Limit** - Allows you to decide how many super reaction animations can play at once, including removing the limit entirely. diff --git a/src/plugins/superReactionTweaks/index.ts b/src/plugins/superReactionTweaks/index.ts new file mode 100644 index 00000000..2652eef0 --- /dev/null +++ b/src/plugins/superReactionTweaks/index.ts @@ -0,0 +1,63 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated, ant0n, FieryFlames and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; + +export const settings = definePluginSettings({ + superReactByDefault: { + type: OptionType.BOOLEAN, + description: "Reaction picker will default to Super Reactions", + default: true, + }, + unlimitedSuperReactionPlaying: { + type: OptionType.BOOLEAN, + description: "Remove the limit on Super Reactions playing at once", + default: false, + }, + + superReactionPlayingLimit: { + description: "Max Super Reactions to play at once", + type: OptionType.SLIDER, + default: 20, + markers: [5, 10, 20, 40, 60, 80, 100], + stickToMarkers: true, + }, +}, { + superReactionPlayingLimit: { + disabled() { return this.store.unlimitedSuperReactionPlaying; }, + } +}); + +export default definePlugin({ + name: "SuperReactionTweaks", + description: "Customize the limit of Super Reactions playing at once, and super react by default", + authors: [Devs.FieryFlames, Devs.ant0n], + patches: [ + { + find: ",BURST_REACTION_EFFECT_PLAY", + replacement: { + match: /(?<=BURST_REACTION_EFFECT_PLAY:\i=>{.{50,100})(\i\(\i,\i\))>=\d+/, + replace: "!$self.shouldPlayBurstReaction($1)" + } + }, + { + find: ".hasAvailableBurstCurrency)", + replacement: { + match: /(?<=\.useBurstReactionsExperiment.{0,20})useState\(!1\)(?=.+?(\i===\i\.EmojiIntention.REACTION))/, + replace: "useState($self.settings.store.superReactByDefault && $1)" + } + } + ], + settings, + + shouldPlayBurstReaction(playingCount: number) { + if (settings.store.unlimitedSuperReactionPlaying) return true; + if (playingCount <= settings.store.superReactionPlayingLimit) return true; + return false; + } +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index aeadcdbf..3db2e64f 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -379,6 +379,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "ProffDea", id: 609329952180928513n }, + ant0n: { + name: "ant0n", + id: 145224646868860928n + }, } satisfies Record); // iife so #__PURE__ works correctly From 96126fa39f910960ec10ccc089fe17e91c1a2afe Mon Sep 17 00:00:00 2001 From: V Date: Thu, 9 Nov 2023 07:15:49 +0100 Subject: [PATCH 03/20] remove pipebomb from github actions (#1968) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1bc2129f..23d9dd27 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "typescript": "^5.0.4", "zip-local": "^0.3.5" }, - "packageManager": "^pnpm@8.1.1", + "packageManager": "pnpm@8.10.2", "pnpm": { "patchedDependencies": { "eslint-plugin-path-alias@1.0.0": "patches/eslint-plugin-path-alias@1.0.0.patch", From ea11f2244fde469ce308f8a4e7224430be62f8f1 Mon Sep 17 00:00:00 2001 From: V Date: Mon, 13 Nov 2023 01:37:15 +0100 Subject: [PATCH 04/20] README: Add sponsors --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index cd54fcdc..177e65be 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,14 @@ Visit https://vencord.dev/download https://discord.gg/D9uwnFnqmd +## Sponsors + +| **Thanks a lot to all Vencord [sponsors](https://github.com/sponsors/Vendicated)!!** | +|:--:| +| [![](https://meow.vendicated.dev/sponsors.png)](https://github.com/sponsors/Vendicated) | +| *generated using [github-sponsor-graph](https://github.com/Vendicated/github-sponsor-graph)* | + + ## Star History From 77d08c5c28121823dd5ba85265a9d09b832a2932 Mon Sep 17 00:00:00 2001 From: megumin Date: Sat, 11 Nov 2023 00:28:09 +0000 Subject: [PATCH 05/20] feat: Add Environment variable to disable updater auto-patching (#1971) --- src/main/patchWin32Updater.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/patchWin32Updater.ts b/src/main/patchWin32Updater.ts index ba7a9224..96717a5a 100644 --- a/src/main/patchWin32Updater.ts +++ b/src/main/patchWin32Updater.ts @@ -32,6 +32,8 @@ function isNewer($new: string, old: string) { } function patchLatest() { + if (process.env.DISABLE_UPDATER_AUTO_PATCHING) return; + try { const currentAppPath = dirname(process.execPath); const currentVersion = basename(currentAppPath); From fd25b5f2968385741e36b5a6624a80d7ef14b61f Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 12 Nov 2023 15:33:34 -0500 Subject: [PATCH 06/20] fix(dearrow): support DeArrow thumbnail submissions at 0 seconds (#1979) --- src/plugins/dearrow/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/dearrow/index.tsx b/src/plugins/dearrow/index.tsx index f6b9ef95..52cf1d53 100644 --- a/src/plugins/dearrow/index.tsx +++ b/src/plugins/dearrow/index.tsx @@ -50,7 +50,7 @@ async function embedDidMount(this: Component) { const { titles, thumbnails } = await res.json(); const hasTitle = titles[0]?.votes >= 0; - const hasThumb = thumbnails[0]?.votes >= 0; + const hasThumb = thumbnails[0]?.votes >= 0 && !thumbnails[0].original; if (!hasTitle && !hasThumb) return; @@ -58,12 +58,12 @@ async function embedDidMount(this: Component) { enabled: true }; - if (titles[0]?.votes >= 0) { + if (hasTitle) { embed.dearrow.oldTitle = embed.rawTitle; embed.rawTitle = titles[0].title; } - if (thumbnails[0]?.votes >= 0 && thumbnails[0].timestamp) { + if (hasThumb) { embed.dearrow.oldThumb = embed.thumbnail.proxyURL; embed.thumbnail.proxyURL = `https://dearrow-thumb.ajay.app/api/v1/getThumbnail?videoID=${videoId}&time=${thumbnails[0].timestamp}`; } From 7b248ee30952eccd880a93dfe1209d8da188b809 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:50:52 -0300 Subject: [PATCH 07/20] Fix SHC patches --- src/plugins/showHiddenChannels/index.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/plugins/showHiddenChannels/index.tsx b/src/plugins/showHiddenChannels/index.tsx index 95b16d62..4e275d64 100644 --- a/src/plugins/showHiddenChannels/index.tsx +++ b/src/plugins/showHiddenChannels/index.tsx @@ -68,7 +68,7 @@ export default definePlugin({ patches: [ { // RenderLevel defines if a channel is hidden, collapsed in category, visible, etc - find: ".CannotShow=", + find: '"placeholder-channel-id"', replacement: [ // Remove the special logic for channels we don't have access to { @@ -82,13 +82,8 @@ export default definePlugin({ }, // Make channels we dont have access to be the same level as normal ones { - match: /(?<=renderLevel:(\i\(this,\i\)\?\i\.Show:\i\.WouldShowIfUncollapsed).+?renderLevel:).+?(?=,)/, - replace: (_, renderLevelExpression) => renderLevelExpression - }, - // Make channels we dont have access to be the same level as normal ones - { - match: /(?<=activeJoinedRelevantThreads.+?renderLevel:.+?,threadIds:\i\(this.record.+?renderLevel:)(\i)\..+?(?=,)/, - replace: (_, RenderLevels) => `${RenderLevels}.Show` + match: /(activeJoinedRelevantThreads:.{0,50}VIEW_CHANNEL.+?renderLevel:(.+?),threadIds.+?renderLevel:).+?(?=,threadIds)/g, + replace: (_, rest, defaultRenderLevel) => `${rest}${defaultRenderLevel}` }, // Remove permission checking for getRenderLevel function { From af614465a49cdd70038cf089b195855a7fa1f18c Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:54:48 -0300 Subject: [PATCH 08/20] Remove obsolete experiments patch --- src/plugins/experiments/index.tsx | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/plugins/experiments/index.tsx b/src/plugins/experiments/index.tsx index 89fcf33e..f8ea4b04 100644 --- a/src/plugins/experiments/index.tsx +++ b/src/plugins/experiments/index.tsx @@ -77,15 +77,6 @@ export default definePlugin({ } ] }, - // Fix search history being disabled / broken with isStaff - { - find: '("showNewSearch")', - predicate: () => settings.store.enableIsStaff, - replacement: { - match: /(?<=showNewSearch"\);return)\s?/, - replace: "!1&&" - } - }, { find: 'H1,title:"Experiments"', replacement: { From 3ea6a967153db9150e809f2050b40fa5b4e54a00 Mon Sep 17 00:00:00 2001 From: Jack <30497388+FieryFlames@users.noreply.github.com> Date: Wed, 15 Nov 2023 13:01:50 -0500 Subject: [PATCH 09/20] chore: Fix PinDMs patch (#1981) --- src/plugins/pinDms/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/pinDms/index.tsx b/src/plugins/pinDms/index.tsx index ac5957b3..792bdab6 100644 --- a/src/plugins/pinDms/index.tsx +++ b/src/plugins/pinDms/index.tsx @@ -100,10 +100,10 @@ export default definePlugin({ }, { // Fix getRowHeight's check for whether this is the DMs section - // section === DMS - match: /===\i\.DMS&&0/, - // section -1 === DMS - replace: "-1$&" + // DMS (inlined) === section + match: /(?<=getRowHeight=\(.{2,50}?)1===\i/, + // DMS (inlined) === section - 1 + replace: "$&-1" }, { // Override scrollToChannel to properly account for pinned channels From c080a0eaacd34e813800db4f6b632d62a9633a3b Mon Sep 17 00:00:00 2001 From: Thoth <54485853+xero-lib@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:09:26 -0600 Subject: [PATCH 10/20] shikiCodeblocks: transform lang to lower case to avoid failing detection (#1990) --- src/plugins/shikiCodeblocks.desktop/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/shikiCodeblocks.desktop/index.ts b/src/plugins/shikiCodeblocks.desktop/index.ts index 12c8c858..f358497d 100644 --- a/src/plugins/shikiCodeblocks.desktop/index.ts +++ b/src/plugins/shikiCodeblocks.desktop/index.ts @@ -67,7 +67,7 @@ export default definePlugin({ createHighlighter, renderHighlighter: ({ lang, content }: { lang: string; content: string; }) => { return createHighlighter({ - lang, + lang: lang?.toLowerCase(), content, isPreview: false, }); From 6578eb487ea16e04fdf704f19a57268aa8078f11 Mon Sep 17 00:00:00 2001 From: AutumnVN Date: Thu, 16 Nov 2023 01:13:19 +0700 Subject: [PATCH 11/20] MessageLogger: fix attachment ignore (#1989) --- src/plugins/messageLogger/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx index 36f9ab3f..ac43a9f0 100644 --- a/src/plugins/messageLogger/index.tsx +++ b/src/plugins/messageLogger/index.tsx @@ -302,6 +302,7 @@ export default definePlugin({ match: /attachments:(\i)\((\i)\)/, replace: "attachments: $1((() => {" + + " if ($self.shouldIgnore($2)) return $2;" + " let old = arguments[1]?.attachments;" + " if (!old) return $2;" + " let new_ = $2.attachments?.map(a => a.id) ?? [];" + From 4a2657f928bdf88514eae707787f2b26d74da9db Mon Sep 17 00:00:00 2001 From: megumin Date: Wed, 15 Nov 2023 18:15:43 +0000 Subject: [PATCH 12/20] fix(channeltags): message author should be clyde (#644) (#1986) --- src/plugins/messageTags/index.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/plugins/messageTags/index.ts b/src/plugins/messageTags/index.ts index d65c388c..66de9d66 100644 --- a/src/plugins/messageTags/index.ts +++ b/src/plugins/messageTags/index.ts @@ -25,10 +25,6 @@ import definePlugin, { OptionType } from "@utils/types"; const EMOTE = "<:luna:1035316192220553236>"; const DATA_KEY = "MessageTags_TAGS"; const MessageTagsMarker = Symbol("MessageTags"); -const author = { - id: "821472922140803112", - bot: false -}; interface Tag { name: string; @@ -59,14 +55,12 @@ function createTagCommand(tag: Tag) { execute: async (_, ctx) => { if (!await getTag(tag.name)) { sendBotMessage(ctx.channel.id, { - author, content: `${EMOTE} The tag **${tag.name}** does not exist anymore! Please reload ur Discord to fix :)` }); return { content: `/${tag.name}` }; } if (Settings.plugins.MessageTags.clyde) sendBotMessage(ctx.channel.id, { - author, content: `${EMOTE} The tag **${tag.name}** has been sent!` }); return { content: tag.message.replaceAll("\\n", "\n") }; @@ -162,7 +156,6 @@ export default definePlugin({ if (await getTag(name)) return sendBotMessage(ctx.channel.id, { - author, content: `${EMOTE} A Tag with the name **${name}** already exists!` }); @@ -176,7 +169,6 @@ export default definePlugin({ await addTag(tag); sendBotMessage(ctx.channel.id, { - author, content: `${EMOTE} Successfully created the tag **${name}**!` }); break; // end 'create' @@ -186,7 +178,6 @@ export default definePlugin({ if (!await getTag(name)) return sendBotMessage(ctx.channel.id, { - author, content: `${EMOTE} A Tag with the name **${name}** does not exist!` }); @@ -194,14 +185,12 @@ export default definePlugin({ await removeTag(name); sendBotMessage(ctx.channel.id, { - author, content: `${EMOTE} Successfully deleted the tag **${name}**!` }); break; // end 'delete' } case "list": { sendBotMessage(ctx.channel.id, { - author, embeds: [ { // @ts-ignore @@ -224,12 +213,10 @@ export default definePlugin({ if (!tag) return sendBotMessage(ctx.channel.id, { - author, content: `${EMOTE} A Tag with the name **${name}** does not exist!` }); sendBotMessage(ctx.channel.id, { - author, content: tag.message.replaceAll("\\n", "\n") }); break; // end 'preview' @@ -237,7 +224,6 @@ export default definePlugin({ default: { sendBotMessage(ctx.channel.id, { - author, content: "Invalid sub-command" }); break; From 45aa9fbb6d1dadcc1746a5a197a6812b41e3215c Mon Sep 17 00:00:00 2001 From: Justice Almanzar Date: Wed, 15 Nov 2023 18:30:31 +0000 Subject: [PATCH 13/20] Fix hljs find (#1983) --- src/webpack/common/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index 04df3c07..8376925e 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -31,7 +31,7 @@ waitFor(["ComponentDispatch", "ComponentDispatcher"], m => ComponentDispatch = m export const RestAPI: t.RestAPI = findByPropsLazy("getAPIBaseURL", "get"); export const moment: typeof import("moment") = findByPropsLazy("parseTwoDigitYear"); -export const hljs: typeof import("highlight.js") = findByPropsLazy("highlight"); +export const hljs: typeof import("highlight.js") = findByPropsLazy("highlight", "registerLanguage"); export const lodash: typeof import("lodash") = findByPropsLazy("debounce", "cloneDeep"); From 77749ed5e1e913d0c5c8ce0995a9fdc12cde7ccb Mon Sep 17 00:00:00 2001 From: adryd Date: Wed, 15 Nov 2023 19:26:35 -0500 Subject: [PATCH 14/20] oneko: update script version (#1994) --- src/plugins/oneko/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/plugins/oneko/index.ts b/src/plugins/oneko/index.ts index d95ba2bc..c5de470e 100644 --- a/src/plugins/oneko/index.ts +++ b/src/plugins/oneko/index.ts @@ -26,15 +26,13 @@ export default definePlugin({ authors: [Devs.Ven, Devs.adryd], start() { - fetch("https://raw.githubusercontent.com/adryd325/oneko.js/5977144dce83e4d71af1de005d16e38eebeb7b72/oneko.js") + fetch("https://raw.githubusercontent.com/adryd325/oneko.js/8fa8a1864aa71cd7a794d58bc139e755e96a236c/oneko.js") .then(x => x.text()) .then(s => s.replace("./oneko.gif", "https://raw.githubusercontent.com/adryd325/oneko.js/14bab15a755d0e35cd4ae19c931d96d306f99f42/oneko.gif")) .then(eval); }, stop() { - clearInterval(window.onekoInterval); - delete window.onekoInterval; document.getElementById("oneko")?.remove(); } }); From 4a5371a746c03125eefb8d5a35a6037ac56c0439 Mon Sep 17 00:00:00 2001 From: V Date: Thu, 16 Nov 2023 05:40:50 +0100 Subject: [PATCH 15/20] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 177e65be..8611babd 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ The cutest Discord client mod -![image](https://github.com/Vendicated/Vencord/assets/45497981/706722b1-32de-4d99-bee9-93993b504334) +| ![image](https://github.com/Vendicated/Vencord/assets/45497981/706722b1-32de-4d99-bee9-93993b504334) | +|:--:| +| A screenshot of vencord showcasing the [vencord-theme](https://github.com/synqat/vencord-theme) | ## Features From 9980c0d04f7fe5ac8002988b4ae29edb1b514b32 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 18 Nov 2023 22:53:50 -0300 Subject: [PATCH 16/20] IgnoreActivities: fix and improvements --- src/plugins/ignoreActivities/index.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/plugins/ignoreActivities/index.tsx b/src/plugins/ignoreActivities/index.tsx index 0b42a8b0..4e747f36 100644 --- a/src/plugins/ignoreActivities/index.tsx +++ b/src/plugins/ignoreActivities/index.tsx @@ -8,7 +8,6 @@ import * as DataStore from "@api/DataStore"; import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; -import { useForceUpdater } from "@utils/react"; import definePlugin from "@utils/types"; import { findStoreLazy } from "@webpack"; import { StatusSettingsStores, Tooltip } from "webpack/common"; @@ -27,14 +26,12 @@ interface IgnoredActivity { const RunningGameStore = findStoreLazy("RunningGameStore"); function ToggleIcon(activity: IgnoredActivity, tooltipText: string, path: string, fill: string) { - const forceUpdate = useForceUpdater(); - return ( {tooltipProps => ( + ) + } +}); + +export default definePlugin({ + name: "ClientTheme", + authors: [Devs.F53], + description: "Recreation of the old client theme experiment. Add a color to your Discord client theme", + settings, + + patches: [ + { + find: "Could not find app-mount", + replacement: { + match: /(?<=Could not find app-mount"\))/, + replace: ",$self.addThemeInitializer()" + } + } + ], + + addThemeInitializer() { + document.addEventListener("DOMContentLoaded", this.themeInitializer = () => { + updateColorVars(settings.store.color); + generateColorOffsets(); + }); + }, + + stop() { + document.removeEventListener("DOMContentLoaded", this.themeInitializer); + document.getElementById("clientThemeVars")?.remove(); + document.getElementById("clientThemeOffsets")?.remove(); + } +}); + +async function generateColorOffsets() { + const variableRegex = /(--primary-[5-9]\d{2}-hsl):.*?(\S*)%;/g; + + const styleLinkNodes = document.querySelectorAll('link[rel="stylesheet"]'); + const variableLightness = {} as Record; + + // Search all stylesheets for color variables + for (const styleLinkNode of styleLinkNodes) { + const cssLink = styleLinkNode.getAttribute("href"); + if (!cssLink) continue; + + const res = await fetch(cssLink); + const cssString = await res.text(); + + // Get lightness values of --primary variables >=500 + let variableMatch = variableRegex.exec(cssString); + while (variableMatch !== null) { + const [, variable, lightness] = variableMatch; + variableLightness[variable] = parseFloat(lightness); + variableMatch = variableRegex.exec(cssString); + } + } + + // Generate offsets + const lightnessOffsets = Object.entries(variableLightness) + .map(([key, lightness]) => { + const lightnessOffset = lightness - variableLightness["--primary-600-hsl"]; + const plusOrMinus = lightnessOffset >= 0 ? "+" : "-"; + return `${key}: var(--theme-h) var(--theme-s) calc(var(--theme-l) ${plusOrMinus} ${Math.abs(lightnessOffset).toFixed(2)}%);`; + }) + .join("\n"); + + const style = document.createElement("style"); + style.setAttribute("id", "clientThemeOffsets"); + style.textContent = `:root:root { + ${lightnessOffsets} + }`; + document.head.appendChild(style); +} + +function updateColorVars(color: string) { + const { hue, saturation, lightness } = hexToHSL(color); + + let style = document.getElementById("clientThemeVars"); + if (!style) { + style = document.createElement("style"); + style.setAttribute("id", "clientThemeVars"); + document.head.appendChild(style); + } + + style.textContent = `:root { + --theme-h: ${hue}; + --theme-s: ${saturation}%; + --theme-l: ${lightness}%; + }`; +} + +// https://css-tricks.com/converting-color-spaces-in-javascript/ +function hexToHSL(hexCode: string) { + // Hex => RGB normalized to 0-1 + const r = parseInt(hexCode.substring(0, 2), 16) / 255; + const g = parseInt(hexCode.substring(2, 4), 16) / 255; + const b = parseInt(hexCode.substring(4, 6), 16) / 255; + + // RGB => HSL + const cMax = Math.max(r, g, b); + const cMin = Math.min(r, g, b); + const delta = cMax - cMin; + + let hue: number, saturation: number, lightness: number; + + lightness = (cMax + cMin) / 2; + + if (delta === 0) { + // If r=g=b then the only thing that matters is lightness + hue = 0; + saturation = 0; + } else { + // Magic + saturation = delta / (1 - Math.abs(2 * lightness - 1)); + + if (cMax === r) + hue = ((g - b) / delta) % 6; + else if (cMax === g) + hue = (b - r) / delta + 2; + else + hue = (r - g) / delta + 4; + hue *= 60; + if (hue < 0) + hue += 360; + } + + // Move saturation and lightness from 0-1 to 0-100 + saturation *= 100; + lightness *= 100; + + return { hue, saturation, lightness }; +} + +// Minimized math just for lightness, lowers lag when changing colors +function hexToLightness(hexCode) { + // Hex => RGB normalized to 0-1 + const r = parseInt(hexCode.substring(0, 2), 16) / 255; + const g = parseInt(hexCode.substring(2, 4), 16) / 255; + const b = parseInt(hexCode.substring(4, 6), 16) / 255; + + const cMax = Math.max(r, g, b); + const cMin = Math.min(r, g, b); + + const lightness = 100 * ((cMax + cMin) / 2); + + return lightness; +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 3db2e64f..7f555d32 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -267,6 +267,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "Dziurwa", id: 1001086404203389018n }, + F53: { + name: "F53", + id: 280411966126948353n + }, AutumnVN: { name: "AutumnVN", id: 393694671383166998n