This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/verticalsync/Suncord
- Loading branch information
Showing
31 changed files
with
6,284 additions
and
1 deletion.
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
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,88 @@ | ||
/* | ||
* Vencord, a modification for Discord's desktop app | ||
* Copyright (c) 2022 Vendicated and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { definePluginSettings } from "@api/Settings"; | ||
import { Devs } from "@utils/constants"; | ||
import definePlugin, { OptionType } from "@utils/types"; | ||
import { UserStore, useState } from "@webpack/common"; | ||
|
||
let avatarUrl = ""; | ||
|
||
const settings = definePluginSettings({ | ||
default: { | ||
type: OptionType.BOOLEAN, | ||
description: "Enable avatar preview by default.", | ||
default: true | ||
} | ||
}); | ||
|
||
function toggle(enabled: boolean) { | ||
const avatars = document.querySelectorAll(".shopCard__3d319 .avatarContainer_e11d35 .wrapper__3ed10 .mask_d5067d foreignObject .avatarStack__789b4"); | ||
|
||
for (const avatar of avatars) { | ||
const img = avatar.querySelector("img"); | ||
|
||
if (img) img.src = enabled ? avatarUrl : "https://canary.discord.com/assets/6d8f0708e196aaad2550.png"; | ||
} | ||
} | ||
|
||
const PreviewToggle = () => { | ||
const [enabled, setEnabled] = useState(settings.store.default); | ||
|
||
toggle(enabled); | ||
|
||
return ( | ||
<button type="button" className="fieldButton__1edf0 button__581d0 lookFilled__950dd colorPrimary_ebe632 sizeSmall_da7d10 grow__4c8a4" style={{ | ||
marginLeft: "8px" | ||
}} onClick={() => { | ||
setEnabled(!enabled); | ||
toggle(!enabled); | ||
}}> | ||
<div className="contents__322f4"> | ||
{enabled ? "Disable" : "Enable"} Avatar Preview | ||
</div> | ||
</button> | ||
); | ||
}; | ||
|
||
export default definePlugin({ | ||
name: "BetterShopPreview", | ||
description: "Uses your avatar for avatar decoration previews in the Discord Shop.", | ||
authors: [Devs.Tolgchu], | ||
settings, | ||
patches: [ | ||
{ | ||
find: "}),(0,l.jsx)(T.default.Title,{className:en.title,children:er.default.Messages.COLLECTIBLES_SHOP})]", | ||
replacement: [{ | ||
match: "{className:en.title,children:er.default.Messages.COLLECTIBLES_SHOP}", | ||
replace: "{className:en.title,children:[er.default.Messages.COLLECTIBLES_SHOP,$self.PreviewToggle()]}" | ||
}] | ||
} | ||
], | ||
PreviewToggle, | ||
async start() { | ||
const user = UserStore.getCurrentUser(); | ||
const url = `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.gif`; | ||
|
||
await fetch(url).then(response => { | ||
if (response.ok) avatarUrl = url; | ||
else avatarUrl = url.replace(".gif", ".png"); | ||
}); | ||
}, | ||
stop() { } | ||
}); |
220 changes: 220 additions & 0 deletions
220
src/suncordplugins/discordColorways/components/ColorPicker.tsx
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,220 @@ | ||
/* | ||
* Vencord, a Discord client mod | ||
* Copyright (c) 2023 Vendicated and contributors | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
import { Flex } from "@components/Flex"; | ||
import { CopyIcon } from "@components/Icons"; | ||
import { | ||
ModalProps, | ||
ModalRoot, | ||
} from "@utils/modal"; | ||
import { | ||
Button, | ||
Clipboard, | ||
ScrollerThin, | ||
TextInput, | ||
Toasts, | ||
useState, | ||
} from "@webpack/common"; | ||
|
||
import { colorVariables } from "../css"; | ||
|
||
interface ToolboxItem { | ||
title: string; | ||
onClick: () => void; | ||
id?: string; | ||
iconClassName?: string; | ||
} | ||
|
||
const ColorVarItems: ToolboxItem[] = colorVariables.map((colorVariable: string) => { | ||
return { | ||
title: "Copy " + colorVariable, | ||
onClick: () => { | ||
function getHex(str: string): string { return Object.assign(document.createElement("canvas").getContext("2d") as {}, { fillStyle: str }).fillStyle; } | ||
Clipboard.copy(getHex(getComputedStyle(document.body).getPropertyValue("--" + colorVariable))); | ||
Toasts.show({ message: "Color " + colorVariable + " copied to clipboard", id: "toolbox-color-var-copied", type: 1 }); | ||
}, | ||
id: colorVariable | ||
}; | ||
}); | ||
|
||
const ToolboxItems: ToolboxItem[] = [ | ||
{ | ||
title: "Copy Accent Color", | ||
onClick: () => { | ||
function getHex(str: string): string { | ||
return Object.assign( | ||
document.createElement("canvas").getContext("2d") as {}, | ||
{ fillStyle: str } | ||
).fillStyle; | ||
} | ||
Clipboard.copy( | ||
getHex( | ||
getComputedStyle(document.body).getPropertyValue( | ||
"--brand-experiment" | ||
) | ||
) | ||
); | ||
Toasts.show({ | ||
message: "Accent color copied to clipboard", | ||
id: "toolbox-accent-color-copied", | ||
type: 1, | ||
}); | ||
}, | ||
id: "colorways-toolbox_copy-accent", | ||
iconClassName: "copy", | ||
}, | ||
{ | ||
title: "Copy Primary Color", | ||
onClick: () => { | ||
function getHex(str: string): string { | ||
return Object.assign( | ||
document.createElement("canvas").getContext("2d") as {}, | ||
{ fillStyle: str } | ||
).fillStyle; | ||
} | ||
Clipboard.copy( | ||
getHex( | ||
getComputedStyle(document.body).getPropertyValue( | ||
"--background-primary" | ||
) | ||
) | ||
); | ||
Toasts.show({ | ||
message: "Primary color copied to clipboard", | ||
id: "toolbox-primary-color-copied", | ||
type: 1, | ||
}); | ||
}, | ||
id: "colorways-toolbox_copy-primary", | ||
iconClassName: "copy", | ||
}, | ||
{ | ||
title: "Copy Secondary Color", | ||
onClick: () => { | ||
function getHex(str: string): string { | ||
return Object.assign( | ||
document.createElement("canvas").getContext("2d") as {}, | ||
{ fillStyle: str } | ||
).fillStyle; | ||
} | ||
Clipboard.copy( | ||
getHex( | ||
getComputedStyle(document.body).getPropertyValue( | ||
"--background-secondary" | ||
) | ||
) | ||
); | ||
Toasts.show({ | ||
message: "Secondary color copied to clipboard", | ||
id: "toolbox-secondary-color-copied", | ||
type: 1, | ||
}); | ||
}, | ||
id: "colorways-toolbox_copy-secondary", | ||
iconClassName: "copy", | ||
}, | ||
{ | ||
title: "Copy Tertiary Color", | ||
onClick: () => { | ||
function getHex(str: string): string { | ||
return Object.assign( | ||
document.createElement("canvas").getContext("2d") as {}, | ||
{ fillStyle: str } | ||
).fillStyle; | ||
} | ||
Clipboard.copy( | ||
getHex( | ||
getComputedStyle(document.body).getPropertyValue( | ||
"--background-tertiary" | ||
) | ||
) | ||
); | ||
Toasts.show({ | ||
message: "Tertiary color copied to clipboard", | ||
id: "toolbox-tertiary-color-copied", | ||
type: 1, | ||
}); | ||
}, | ||
id: "colorways-toolbox_copy-tertiary", | ||
iconClassName: "copy", | ||
} | ||
]; | ||
|
||
export default function ({ modalProps }: { modalProps: ModalProps; }) { | ||
const [colorVarItems, setColorVarItems] = useState<ToolboxItem[]>(ColorVarItems); | ||
const [collapsedSettings, setCollapsedSettings] = useState<boolean>(true); | ||
let results: ToolboxItem[]; | ||
function searchToolboxItems(e: string) { | ||
results = []; | ||
ColorVarItems.find((ToolboxItem: ToolboxItem) => { | ||
if (ToolboxItem.title.toLowerCase().includes(e.toLowerCase())) { | ||
results.push(ToolboxItem); | ||
} | ||
}); | ||
setColorVarItems(results); | ||
} | ||
|
||
return ( | ||
<ModalRoot {...modalProps} className="colorwayColorpicker"> | ||
<Flex style={{ gap: "8px", marginBottom: "8px" }}> | ||
<TextInput | ||
className="colorwaysColorpicker-search" | ||
placeholder="Search for a color:" | ||
onChange={e => { | ||
searchToolboxItems(e); | ||
if (e) { | ||
setCollapsedSettings(false); | ||
} else { | ||
setCollapsedSettings(true); | ||
} | ||
}} | ||
/> | ||
<Button | ||
innerClassName="colorwaysSettings-iconButtonInner" | ||
size={Button.Sizes.ICON} | ||
color={Button.Colors.TRANSPARENT} | ||
onClick={() => setCollapsedSettings(!collapsedSettings)} | ||
> | ||
<svg width="32" height="24" viewBox="0 0 24 24" aria-hidden="true" role="img"> | ||
<path fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M7 10L12 15 17 10" aria-hidden="true" /> | ||
</svg> | ||
</Button> | ||
</Flex> | ||
<ScrollerThin style={{ color: "var(--text-normal)" }} orientation="vertical" className={collapsedSettings ? " colorwaysColorpicker-collapsed" : ""} paddingFix> | ||
{colorVarItems.map((toolboxItem: ToolboxItem) => { | ||
return ( | ||
<div | ||
id={ | ||
"colorways-colorstealer-item_" + | ||
toolboxItem.id | ||
} | ||
className="colorwaysCreator-settingItm colorwaysCreator-toolboxItm" | ||
onClick={toolboxItem.onClick} | ||
style={ | ||
{ | ||
"--brand-experiment": | ||
"var(--" + toolboxItem.id + ")", | ||
} as React.CSSProperties | ||
} | ||
> | ||
{toolboxItem.title} | ||
</div> | ||
); | ||
})} | ||
</ScrollerThin> | ||
<Flex style={{ justifyContent: "space-between", marginTop: "8px" }} wrap="wrap" className={collapsedSettings ? "" : " colorwaysColorpicker-collapsed"}> | ||
{ToolboxItems.map((toolboxItem: ToolboxItem, i: number) => <div | ||
id={toolboxItem.id || `colorways-toolbox_item-${i}`} | ||
className="colorwayToolbox-listItem" | ||
> | ||
<CopyIcon onClick={toolboxItem.onClick} width={20} height={20} className="colorwayToolbox-listItemSVG" /> | ||
<span className="colorwaysToolbox-label">{toolboxItem.title}</span> | ||
</div> | ||
)} | ||
</Flex> | ||
</ModalRoot> | ||
); | ||
} |
Oops, something went wrong.