mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-07 21:53:04 -04:00
Move CopyStickerLinks + Fix Lint
This commit is contained in:
parent
09857174d0
commit
1c24c4d173
5 changed files with 142 additions and 166 deletions
135
src/equicordplugins/copyStickerLinks/index.tsx
Normal file
135
src/equicordplugins/copyStickerLinks/index.tsx
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2025 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
|
||||||
|
import { Devs } from "@utils/constants";
|
||||||
|
import { copyWithToast } from "@utils/misc";
|
||||||
|
import definePlugin from "@utils/types";
|
||||||
|
import { findStoreLazy } from "@webpack";
|
||||||
|
import { Menu, React } from "@webpack/common";
|
||||||
|
import { Promisable } from "type-fest";
|
||||||
|
|
||||||
|
const StickersStore = findStoreLazy("StickersStore");
|
||||||
|
|
||||||
|
interface Sticker {
|
||||||
|
t: "Sticker";
|
||||||
|
format_type: number;
|
||||||
|
id: string;
|
||||||
|
type: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StickerExt = ["png", "png", "json", "gif"] as const;
|
||||||
|
|
||||||
|
function getUrl(data: Sticker) {
|
||||||
|
if (data.format_type === 4)
|
||||||
|
return `https:${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.gif?size=4096&lossless=true`;
|
||||||
|
|
||||||
|
return `https://${window.GLOBAL_ENV.CDN_HOST}/stickers/${data.id}.${StickerExt[data.format_type]}?size=4096&lossless=true`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildMenuItem(Sticker, fetchData: () => Promisable<Omit<Sticker, "t">>) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Menu.MenuSeparator></Menu.MenuSeparator>
|
||||||
|
|
||||||
|
<Menu.MenuItem
|
||||||
|
id="copystickerurl"
|
||||||
|
key="copystickerurl"
|
||||||
|
label={"Copy URL"}
|
||||||
|
action={async () => {
|
||||||
|
const res = await fetchData();
|
||||||
|
const data = { t: Sticker, ...res } as Sticker;
|
||||||
|
const url = getUrl(data[0]);
|
||||||
|
copyWithToast(url, "Link copied!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Menu.MenuItem
|
||||||
|
id="openstickerlink"
|
||||||
|
key="openstickerlink"
|
||||||
|
label={"Open URL"}
|
||||||
|
action={async () => {
|
||||||
|
const res = await fetchData();
|
||||||
|
const data = { t: Sticker, ...res } as Sticker;
|
||||||
|
const url = getUrl(data[0]);
|
||||||
|
VencordNative.native.openExternal(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildMenuExpression(Sticker, fetchData: () => Promisable<Omit<Sticker, "t">>) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Menu.MenuSeparator></Menu.MenuSeparator>
|
||||||
|
<Menu.MenuItem
|
||||||
|
id="copystickerurl"
|
||||||
|
key="copystickerurl"
|
||||||
|
label={"Copy URL"}
|
||||||
|
action={async () => {
|
||||||
|
const res = await fetchData();
|
||||||
|
const data = { t: Sticker, ...res } as Sticker;
|
||||||
|
const url = getUrl(data);
|
||||||
|
copyWithToast(url, "Link copied!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Menu.MenuItem
|
||||||
|
id="openstickerlink"
|
||||||
|
key="openstickerlink"
|
||||||
|
label={"Open URL"}
|
||||||
|
action={async () => {
|
||||||
|
const res = await fetchData();
|
||||||
|
const data = { t: Sticker, ...res } as Sticker;
|
||||||
|
const url = getUrl(data);
|
||||||
|
VencordNative.native.openExternal(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => {
|
||||||
|
const { favoriteableId, favoriteableType } = props ?? {};
|
||||||
|
if (!favoriteableId) return;
|
||||||
|
const menuItem = (() => {
|
||||||
|
const sticker = props.message.stickerItems.find(s => s.id === favoriteableId);
|
||||||
|
if (sticker?.format_type === 3) return;
|
||||||
|
switch (favoriteableType) {
|
||||||
|
case "sticker":
|
||||||
|
return buildMenuItem("Sticker", () => props.message.stickerItems);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (menuItem)
|
||||||
|
findGroupChildrenByChildId("devmode-copy-id", children, true)?.push(menuItem);
|
||||||
|
};
|
||||||
|
|
||||||
|
const expressionPickerPatch: NavContextMenuPatchCallback = (children, props: { target: HTMLElement; }) => {
|
||||||
|
const { id } = props?.target?.dataset ?? {};
|
||||||
|
if (!id) return;
|
||||||
|
|
||||||
|
if (!props.target.className?.includes("lottieCanvas")) {
|
||||||
|
const stickerCache = StickersStore.getStickerById(id);
|
||||||
|
if (stickerCache) {
|
||||||
|
children.push(buildMenuExpression("Sticker", () => stickerCache));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default definePlugin({
|
||||||
|
name: "CopyStickerLinks",
|
||||||
|
description: "Adds the ability to copy and open sticker links to your browser",
|
||||||
|
authors: [Devs.Byeoon],
|
||||||
|
contextMenus: {
|
||||||
|
"message": messageContextMenuPatch,
|
||||||
|
"expression-picker": expressionPickerPatch
|
||||||
|
}
|
||||||
|
});
|
|
@ -55,7 +55,7 @@ interface ContextMenuProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ArrowsLeftRightIcon = findComponentByCodeLazy("18.58V3a1");
|
const ArrowsLeftRightIcon = findComponentByCodeLazy("18.58V3a1");
|
||||||
const XSmallIcon = findComponentByCodeLazy("12l4.94-4.94a1.5")
|
const XSmallIcon = findComponentByCodeLazy("12l4.94-4.94a1.5");
|
||||||
|
|
||||||
function MakeContextCallback(name: "user" | "channel"): NavContextMenuPatchCallback {
|
function MakeContextCallback(name: "user" | "channel"): NavContextMenuPatchCallback {
|
||||||
return (children, { user, channel, guildId }: ContextMenuProps) => {
|
return (children, { user, channel, guildId }: ContextMenuProps) => {
|
||||||
|
@ -149,7 +149,7 @@ export default definePlugin({
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<HeaderBarIcon
|
<HeaderBarIcon
|
||||||
icon={() => (<XSmallIcon style={{width: "24px",height: "24px"}} />)}
|
icon={() => (<XSmallIcon style={{ width: "24px",height: "24px" }} />)}
|
||||||
tooltip="Close Sidebar Chat"
|
tooltip="Close Sidebar Chat"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
FluxDispatcher.dispatch({
|
FluxDispatcher.dispatch({
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
/*
|
|
||||||
* Vencord, a modification for Discord's desktop app
|
|
||||||
* Copyright (c) 2025 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 { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
|
|
||||||
import { Devs } from "@utils/constants";
|
|
||||||
import { copyWithToast } from "@utils/misc";
|
|
||||||
import definePlugin from "@utils/types";
|
|
||||||
import { findStoreLazy } from "@webpack";
|
|
||||||
import { Menu, React } from "@webpack/common";
|
|
||||||
import { Promisable } from "type-fest";
|
|
||||||
|
|
||||||
const StickersStore = findStoreLazy("StickersStore");
|
|
||||||
|
|
||||||
interface Sticker {
|
|
||||||
t: "Sticker";
|
|
||||||
format_type: number;
|
|
||||||
id: string;
|
|
||||||
type: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const StickerExt = [, "png", "png", "json", "gif"] as const;
|
|
||||||
|
|
||||||
function getUrl(data: Sticker) {
|
|
||||||
if (data.format_type === 4)
|
|
||||||
return `https:${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.gif?size=4096&lossless=true`;
|
|
||||||
|
|
||||||
return `https://${window.GLOBAL_ENV.CDN_HOST}/stickers/${data.id}.${StickerExt[data.format_type]}?size=4096&lossless=true`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildMenuItem(Sticker, fetchData: () => Promisable<Omit<Sticker, "t">>) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Menu.MenuSeparator></Menu.MenuSeparator>
|
|
||||||
|
|
||||||
<Menu.MenuItem
|
|
||||||
id="copystickerurl"
|
|
||||||
key="copystickerurl"
|
|
||||||
label={"Copy URL"}
|
|
||||||
action={async () => {
|
|
||||||
const res = await fetchData();
|
|
||||||
const data = { t: Sticker, ...res } as Sticker;
|
|
||||||
const url = getUrl(data[0]);
|
|
||||||
copyWithToast(url, "Link copied!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Menu.MenuItem
|
|
||||||
id="openstickerlink"
|
|
||||||
key="openstickerlink"
|
|
||||||
label={"Open URL"}
|
|
||||||
action={async () => {
|
|
||||||
const res = await fetchData();
|
|
||||||
const data = { t: Sticker, ...res } as Sticker;
|
|
||||||
const url = getUrl(data[0]);
|
|
||||||
VencordNative.native.openExternal(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildMenuExpression(Sticker, fetchData: () => Promisable<Omit<Sticker, "t">>) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Menu.MenuSeparator></Menu.MenuSeparator>
|
|
||||||
<Menu.MenuItem
|
|
||||||
id="copystickerurl"
|
|
||||||
key="copystickerurl"
|
|
||||||
label={"Copy URL"}
|
|
||||||
action={async () => {
|
|
||||||
const res = await fetchData();
|
|
||||||
const data = { t: Sticker, ...res } as Sticker;
|
|
||||||
const url = getUrl(data);
|
|
||||||
copyWithToast(url, "Link copied!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Menu.MenuItem
|
|
||||||
id="openstickerlink"
|
|
||||||
key="openstickerlink"
|
|
||||||
label={"Open URL"}
|
|
||||||
action={async () => {
|
|
||||||
const res = await fetchData();
|
|
||||||
const data = { t: Sticker, ...res } as Sticker;
|
|
||||||
const url = getUrl(data);
|
|
||||||
VencordNative.native.openExternal(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => {
|
|
||||||
const { favoriteableId, favoriteableType } = props ?? {};
|
|
||||||
if (!favoriteableId) return;
|
|
||||||
const menuItem = (() => {
|
|
||||||
const sticker = props.message.stickerItems.find(s => s.id === favoriteableId);
|
|
||||||
if (sticker?.format_type === 3) return;
|
|
||||||
switch (favoriteableType) {
|
|
||||||
case "sticker":
|
|
||||||
return buildMenuItem("Sticker", () => props.message.stickerItems);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
if (menuItem)
|
|
||||||
findGroupChildrenByChildId("devmode-copy-id", children, true)?.push(menuItem);
|
|
||||||
};
|
|
||||||
|
|
||||||
const expressionPickerPatch: NavContextMenuPatchCallback = (children, props: { target: HTMLElement; }) => {
|
|
||||||
const { id } = props?.target?.dataset ?? {};
|
|
||||||
if (!id) return;
|
|
||||||
|
|
||||||
if (!props.target.className?.includes("lottieCanvas")) {
|
|
||||||
const stickerCache = StickersStore.getStickerById(id);
|
|
||||||
if (stickerCache) {
|
|
||||||
children.push(buildMenuExpression("Sticker", () => stickerCache));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default definePlugin({
|
|
||||||
name: "CopyStickerLinks",
|
|
||||||
description: "Adds the ability to copy and open sticker links to your browser",
|
|
||||||
authors: [Devs.Byeoon],
|
|
||||||
contextMenus: {
|
|
||||||
"message": messageContextMenuPatch,
|
|
||||||
"expression-picker": expressionPickerPatch
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -126,7 +126,7 @@ export function initWs(isManual = false) {
|
||||||
function reply(error?: string) {
|
function reply(error?: string) {
|
||||||
const toSend = { nonce: d.nonce, ok: !error } as Record<string, unknown>;
|
const toSend = { nonce: d.nonce, ok: !error } as Record<string, unknown>;
|
||||||
if (error) toSend.error = error;
|
if (error) toSend.error = error;
|
||||||
logger.debug(`Replying with:`, toSend);
|
logger.debug("Replying with:", toSend);
|
||||||
ws.send(JSON.stringify(toSend));
|
ws.send(JSON.stringify(toSend));
|
||||||
}
|
}
|
||||||
function replyData(data: OutgoingMessage) {
|
function replyData(data: OutgoingMessage) {
|
||||||
|
|
|
@ -1,20 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* Vencord, a modification for Discord's desktop app
|
* Vencord, a Discord client mod
|
||||||
* Copyright (c) 2022 Vendicated and contributors
|
* Copyright (c) 2025 Vendicated and contributors
|
||||||
*
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* 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 { definePluginSettings } from "@api/Settings";
|
||||||
import { disableStyle, enableStyle } from "@api/Styles";
|
import { disableStyle, enableStyle } from "@api/Styles";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue