Compare commits
22 commits
41702851c7
...
52c63bf13c
Author | SHA1 | Date | |
---|---|---|---|
52c63bf13c | |||
|
d919cd6bf1 | ||
|
c185f47f4d | ||
|
83d90f03ee | ||
|
0f8d21a846 | ||
|
2658459a98 | ||
|
f8b01c1a31 | ||
|
2382294e8b | ||
|
d47be6c017 | ||
|
6c12a33aa6 | ||
|
9cc42bf457 | ||
|
1bfdcf2697 | ||
|
3013c669c0 | ||
|
e460b5efb6 | ||
|
902a86c3b2 | ||
|
51ae019cd5 | ||
|
0f5cf37ef9 | ||
|
5c88284ed3 | ||
|
5e9a9fe836 | ||
|
bc801853e2 | ||
|
2044264729 | ||
|
3704c71ae1 |
40 changed files with 555 additions and 212 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "vencord",
|
"name": "vencord",
|
||||||
"private": "true",
|
"private": "true",
|
||||||
"version": "1.9.5",
|
"version": "1.9.7",
|
||||||
"description": "The cutest Discord client mod",
|
"description": "The cutest Discord client mod",
|
||||||
"homepage": "https://github.com/Vendicated/Vencord#readme",
|
"homepage": "https://github.com/Vendicated/Vencord#readme",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|
|
@ -15,9 +15,9 @@ export async function loadLazyChunks() {
|
||||||
try {
|
try {
|
||||||
LazyChunkLoaderLogger.log("Loading all chunks...");
|
LazyChunkLoaderLogger.log("Loading all chunks...");
|
||||||
|
|
||||||
const validChunks = new Set<string>();
|
const validChunks = new Set<number>();
|
||||||
const invalidChunks = new Set<string>();
|
const invalidChunks = new Set<number>();
|
||||||
const deferredRequires = new Set<string>();
|
const deferredRequires = new Set<number>();
|
||||||
|
|
||||||
let chunksSearchingResolve: (value: void | PromiseLike<void>) => void;
|
let chunksSearchingResolve: (value: void | PromiseLike<void>) => void;
|
||||||
const chunksSearchingDone = new Promise<void>(r => chunksSearchingResolve = r);
|
const chunksSearchingDone = new Promise<void>(r => chunksSearchingResolve = r);
|
||||||
|
@ -29,14 +29,14 @@ export async function loadLazyChunks() {
|
||||||
|
|
||||||
async function searchAndLoadLazyChunks(factoryCode: string) {
|
async function searchAndLoadLazyChunks(factoryCode: string) {
|
||||||
const lazyChunks = factoryCode.matchAll(LazyChunkRegex);
|
const lazyChunks = factoryCode.matchAll(LazyChunkRegex);
|
||||||
const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>();
|
const validChunkGroups = new Set<[chunkIds: number[], entryPoint: number]>();
|
||||||
|
|
||||||
// Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before
|
// Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before
|
||||||
// the chunk containing the component
|
// the chunk containing the component
|
||||||
const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT");
|
const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT");
|
||||||
|
|
||||||
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => {
|
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => {
|
||||||
const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => m[1]) : [];
|
const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => Number(m[1])) : [];
|
||||||
|
|
||||||
if (chunkIds.length === 0) {
|
if (chunkIds.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -61,7 +61,7 @@ export async function loadLazyChunks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!invalidChunkGroup) {
|
if (!invalidChunkGroup) {
|
||||||
validChunkGroups.add([chunkIds, entryPoint]);
|
validChunkGroups.add([chunkIds, Number(entryPoint)]);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -131,14 +131,14 @@ export async function loadLazyChunks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// All chunks Discord has mapped to asset files, even if they are not used anymore
|
// All chunks Discord has mapped to asset files, even if they are not used anymore
|
||||||
const allChunks = [] as string[];
|
const allChunks = [] as number[];
|
||||||
|
|
||||||
// Matches "id" or id:
|
// Matches "id" or id:
|
||||||
for (const currentMatch of wreq!.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) {
|
for (const currentMatch of wreq!.u.toString().matchAll(/(?:"([\deE]+?)")|(?:([\deE]+?):)/g)) {
|
||||||
const id = currentMatch[1] ?? currentMatch[2];
|
const id = currentMatch[1] ?? currentMatch[2];
|
||||||
if (id == null) continue;
|
if (id == null) continue;
|
||||||
|
|
||||||
allChunks.push(id);
|
allChunks.push(Number(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allChunks.length === 0) throw new Error("Failed to get all chunks");
|
if (allChunks.length === 0) throw new Error("Failed to get all chunks");
|
||||||
|
|
|
@ -35,7 +35,8 @@ export const ALLOWED_PROTOCOLS = [
|
||||||
"steam:",
|
"steam:",
|
||||||
"spotify:",
|
"spotify:",
|
||||||
"com.epicgames.launcher:",
|
"com.epicgames.launcher:",
|
||||||
"tidal:"
|
"tidal:",
|
||||||
|
"itunes:",
|
||||||
];
|
];
|
||||||
|
|
||||||
export const IS_VANILLA = /* @__PURE__ */ process.argv.includes("--vanilla");
|
export const IS_VANILLA = /* @__PURE__ */ process.argv.includes("--vanilla");
|
||||||
|
|
|
@ -27,12 +27,8 @@ export default definePlugin({
|
||||||
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL",
|
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL",
|
||||||
replacement: {
|
replacement: {
|
||||||
// foo && !bar ? createElement(reactionStuffs)... createElement(blah,...makeElement(reply-other))
|
// foo && !bar ? createElement(reactionStuffs)... createElement(blah,...makeElement(reply-other))
|
||||||
match: /\i&&!\i\?\(0,\i\.jsxs?\)\(.{0,200}renderEmojiPicker:.{0,500}\?(\i)\(\{key:"reply-other"/,
|
match: /\i&&!\i\?\(0,\i\.jsxs?\)\(.{0,200}renderEmojiPicker:.{0,500}\?(\i)\(\{key:"reply-other"(?<=message:(\i).+?)/,
|
||||||
replace: (m, makeElement) => {
|
replace: (m, makeElement, msg) => `...Vencord.Api.MessagePopover._buildPopoverElements(${msg},${makeElement}),${m}`
|
||||||
const msg = m.match(/message:(.{1,3}),/)?.[1];
|
|
||||||
if (!msg) throw new Error("Could not find message variable");
|
|
||||||
return `...Vencord.Api.MessagePopover._buildPopoverElements(${msg},${makeElement}),${m}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
|
|
|
@ -249,6 +249,10 @@ export default definePlugin({
|
||||||
dispatchingFoldersClose = false;
|
dispatchingFoldersClose = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
LOGOUT() {
|
||||||
|
closeFolders();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,9 @@ export default definePlugin({
|
||||||
description: "Upload with a single click, open menu with right click",
|
description: "Upload with a single click, open menu with right click",
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
find: "Messages.CHAT_ATTACH_UPLOAD_OR_INVITE",
|
find: '"ChannelAttachButton"',
|
||||||
replacement: {
|
replacement: {
|
||||||
// Discord merges multiple props here with Object.assign()
|
match: /\.attachButtonInner,"aria-label":.{0,50},onDoubleClick:(.+?:void 0),\.\.\.(\i),/,
|
||||||
// This patch passes a third object to it with which we override onClick and onContextMenu
|
|
||||||
match: /CHAT_ATTACH_UPLOAD_OR_INVITE,onDoubleClick:(.+?:void 0),\.\.\.(\i),/,
|
|
||||||
replace: "$&onClick:$1,onContextMenu:$2.onClick,",
|
replace: "$&onClick:$1,onContextMenu:$2.onClick,",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,7 +30,7 @@ function onPickColor(color: number) {
|
||||||
updateColorVars(hexColor);
|
updateColorVars(hexColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveClientTheme = findByCodeLazy('type:"UNSYNCED_USER_SETTINGS_UPDATE",settings:{useSystemTheme:"system"===');
|
const saveClientTheme = findByCodeLazy('type:"UNSYNCED_USER_SETTINGS_UPDATE', '"system"===');
|
||||||
|
|
||||||
function setTheme(theme: string) {
|
function setTheme(theme: string) {
|
||||||
saveClientTheme({ theme });
|
saveClientTheme({ theme });
|
||||||
|
|
|
@ -8,7 +8,7 @@ import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Flex } from "@components/Flex";
|
import { Flex } from "@components/Flex";
|
||||||
import { openInviteModal } from "@utils/discord";
|
import { openInviteModal } from "@utils/discord";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { classes } from "@utils/misc";
|
import { classes, copyWithToast } from "@utils/misc";
|
||||||
import { closeAllModals, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
import { closeAllModals, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||||
import { findComponentByCodeLazy } from "@webpack";
|
import { findComponentByCodeLazy } from "@webpack";
|
||||||
import { Alerts, Button, FluxDispatcher, Forms, GuildStore, NavigationRouter, Parser, Text, Tooltip, useEffect, UserStore, UserUtils, useState } from "@webpack/common";
|
import { Alerts, Button, FluxDispatcher, Forms, GuildStore, NavigationRouter, Parser, Text, Tooltip, useEffect, UserStore, UserUtils, useState } from "@webpack/common";
|
||||||
|
@ -45,7 +45,11 @@ interface Section {
|
||||||
authorIds?: string[];
|
authorIds?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function SectionHeader({ section }: { section: Section; }) {
|
interface SectionHeaderProps {
|
||||||
|
section: Section;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SectionHeader({ section }: SectionHeaderProps) {
|
||||||
const hasSubtitle = typeof section.subtitle !== "undefined";
|
const hasSubtitle = typeof section.subtitle !== "undefined";
|
||||||
const hasAuthorIds = typeof section.authorIds !== "undefined";
|
const hasAuthorIds = typeof section.authorIds !== "undefined";
|
||||||
|
|
||||||
|
@ -62,6 +66,7 @@ function SectionHeader({ section }: { section: Section; }) {
|
||||||
})();
|
})();
|
||||||
}, [section.authorIds]);
|
}, [section.authorIds]);
|
||||||
|
|
||||||
|
|
||||||
return <div>
|
return <div>
|
||||||
<Flex>
|
<Flex>
|
||||||
<Forms.FormTitle style={{ flexGrow: 1 }}>{section.title}</Forms.FormTitle>
|
<Forms.FormTitle style={{ flexGrow: 1 }}>{section.title}</Forms.FormTitle>
|
||||||
|
@ -74,8 +79,7 @@ function SectionHeader({ section }: { section: Section; }) {
|
||||||
size={16}
|
size={16}
|
||||||
showUserPopout
|
showUserPopout
|
||||||
className={Margins.bottom8}
|
className={Margins.bottom8}
|
||||||
/>
|
/>}
|
||||||
}
|
|
||||||
</Flex>
|
</Flex>
|
||||||
{hasSubtitle &&
|
{hasSubtitle &&
|
||||||
<Forms.FormText type="description" className={Margins.bottom8}>
|
<Forms.FormText type="description" className={Margins.bottom8}>
|
||||||
|
@ -204,7 +208,16 @@ function ChangeDecorationModal(props: ModalProps) {
|
||||||
{activeSelectedDecoration?.alt}
|
{activeSelectedDecoration?.alt}
|
||||||
</Text>
|
</Text>
|
||||||
}
|
}
|
||||||
{activeDecorationHasAuthor && <Text key={`createdBy-${activeSelectedDecoration.authorId}`}>Created by {Parser.parse(`<@${activeSelectedDecoration.authorId}>`)}</Text>}
|
{activeDecorationHasAuthor && (
|
||||||
|
<Text key={`createdBy-${activeSelectedDecoration.authorId}`}>
|
||||||
|
Created by {Parser.parse(`<@${activeSelectedDecoration.authorId}>`)}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
{isActiveDecorationPreset && (
|
||||||
|
<Button onClick={() => copyWithToast(activeDecorationPreset.id)}>
|
||||||
|
Copy Preset ID
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
|
|
|
@ -57,7 +57,7 @@ function decode(bio: string): Array<number> | null {
|
||||||
if (bio == null) return null;
|
if (bio == null) return null;
|
||||||
|
|
||||||
const colorString = bio.match(
|
const colorString = bio.match(
|
||||||
/\u{e005b}\u{e0023}([\u{e0061}-\u{e0066}\u{e0041}-\u{e0046}\u{e0030}-\u{e0039}]+?)\u{e002c}\u{e0023}([\u{e0061}-\u{e0066}\u{e0041}-\u{e0046}\u{e0030}-\u{e0039}]+?)\u{e005d}/u,
|
/\u{e005b}\u{e0023}([\u{e0061}-\u{e0066}\u{e0041}-\u{e0046}\u{e0030}-\u{e0039}]{1,6})\u{e002c}\u{e0023}([\u{e0061}-\u{e0066}\u{e0041}-\u{e0046}\u{e0030}-\u{e0039}]{1,6})\u{e005d}/u,
|
||||||
);
|
);
|
||||||
if (colorString != null) {
|
if (colorString != null) {
|
||||||
const parsed = [...colorString[0]]
|
const parsed = [...colorString[0]]
|
||||||
|
|
|
@ -171,7 +171,7 @@ export default definePlugin({
|
||||||
find: ".handleImageLoad)",
|
find: ".handleImageLoad)",
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
match: /placeholderVersion:\i,/,
|
match: /placeholderVersion:\i,(?=.{0,50}children:)/,
|
||||||
replace: "...$self.makeProps(this),$&"
|
replace: "...$self.makeProps(this),$&"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,21 @@
|
||||||
|
|
||||||
import "./styles.css";
|
import "./styles.css";
|
||||||
|
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { SelectedGuildStore, useState } from "@webpack/common";
|
import { SelectedGuildStore, useState } from "@webpack/common";
|
||||||
import { User } from "discord-types/general";
|
import { User } from "discord-types/general";
|
||||||
|
|
||||||
|
const settings = definePluginSettings({
|
||||||
|
showAtSymbol: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: "Whether the the @ symbol should be displayed",
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "MentionAvatars",
|
name: "MentionAvatars",
|
||||||
description: "Shows user avatars inside mentions",
|
description: "Shows user avatars inside mentions",
|
||||||
|
@ -25,11 +34,13 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
settings,
|
||||||
|
|
||||||
renderUsername: ErrorBoundary.wrap((props: { user: User, username: string; }) => {
|
renderUsername: ErrorBoundary.wrap((props: { user: User, username: string; }) => {
|
||||||
const { user, username } = props;
|
const { user, username } = props;
|
||||||
const [isHovering, setIsHovering] = useState(false);
|
const [isHovering, setIsHovering] = useState(false);
|
||||||
|
|
||||||
if (!user) return <>@{username}</>;
|
if (!user) return <>{getUsernameString(username)}</>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
|
@ -37,8 +48,15 @@ export default definePlugin({
|
||||||
onMouseLeave={() => setIsHovering(false)}
|
onMouseLeave={() => setIsHovering(false)}
|
||||||
>
|
>
|
||||||
<img src={user.getAvatarURL(SelectedGuildStore.getGuildId(), 16, isHovering)} className="vc-mentionAvatars-avatar" />
|
<img src={user.getAvatarURL(SelectedGuildStore.getGuildId(), 16, isHovering)} className="vc-mentionAvatars-avatar" />
|
||||||
@{username}
|
{getUsernameString(username)}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}, { noop: true })
|
}, { noop: true })
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getUsernameString(username: string) {
|
||||||
|
return settings.store.showAtSymbol
|
||||||
|
? `@${username}`
|
||||||
|
: username;
|
||||||
|
}
|
||||||
|
|
|
@ -151,6 +151,7 @@ export default definePlugin({
|
||||||
contextMenus: {
|
contextMenus: {
|
||||||
"message": patchMessageContextMenu,
|
"message": patchMessageContextMenu,
|
||||||
"channel-context": patchChannelContextMenu,
|
"channel-context": patchChannelContextMenu,
|
||||||
|
"thread-context": patchChannelContextMenu,
|
||||||
"user-context": patchChannelContextMenu,
|
"user-context": patchChannelContextMenu,
|
||||||
"gdm-context": patchChannelContextMenu
|
"gdm-context": patchChannelContextMenu
|
||||||
},
|
},
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default definePlugin({
|
||||||
find: ".Messages.MUTUAL_GUILDS_WITH_END_COUNT", // Note: the module is lazy-loaded
|
find: ".Messages.MUTUAL_GUILDS_WITH_END_COUNT", // Note: the module is lazy-loaded
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=\.tabBarItem.{0,50}MUTUAL_GUILDS.+?}\),)(?=.+?(\(0,\i\.jsxs?\)\(.{0,100}id:))/,
|
match: /(?<=\.tabBarItem.{0,50}MUTUAL_GUILDS.+?}\),)(?=.+?(\(0,\i\.jsxs?\)\(.{0,100}id:))/,
|
||||||
replace: '$self.isBotOrSelf(arguments[0].user)?null:$1"MUTUAL_GDMS",children:"Mutual Groups"}),'
|
replace: '$self.isBotOrSelf(arguments[0].user)?null:$1"MUTUAL_GDMS",children:$self.getMutualGDMCountText(arguments[0].user)}),'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -64,7 +64,7 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
match: /(?<=onItemSelect:\i,children:)(\i)\.map/,
|
match: /(?<=onItemSelect:\i,children:)(\i)\.map/,
|
||||||
replace: "[...$1, ...($self.isBotOrSelf(arguments[0].user) ? [] : [{section:'MUTUAL_GDMS',text:'Mutual Groups'}])].map"
|
replace: "[...$1, ...($self.isBotOrSelf(arguments[0].user) ? [] : [{section:'MUTUAL_GDMS',text:$self.getMutualGDMCountText(arguments[0].user)}])].map"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
match: /\(0,\i\.jsx\)\(\i,\{items:\i,section:(\i)/,
|
match: /\(0,\i\.jsx\)\(\i,\{items:\i,section:(\i)/,
|
||||||
|
@ -76,6 +76,11 @@ export default definePlugin({
|
||||||
|
|
||||||
isBotOrSelf: (user: User) => user.bot || user.id === UserStore.getCurrentUser().id,
|
isBotOrSelf: (user: User) => user.bot || user.id === UserStore.getCurrentUser().id,
|
||||||
|
|
||||||
|
getMutualGDMCountText: (user: User) => {
|
||||||
|
const count = ChannelStore.getSortedPrivateChannels().filter(c => c.isGroupDM() && c.recipients.includes(user.id)).length;
|
||||||
|
return `${count === 0 ? "No" : count} Mutual Group${count !== 1 ? "s" : ""}`;
|
||||||
|
},
|
||||||
|
|
||||||
renderMutualGDMs: ErrorBoundary.wrap(({ user, onClose }: { user: User, onClose: () => void; }) => {
|
renderMutualGDMs: ErrorBoundary.wrap(({ user, onClose }: { user: User, onClose: () => void; }) => {
|
||||||
const entries = ChannelStore.getSortedPrivateChannels().filter(c => c.isGroupDM() && c.recipients.includes(user.id)).map(c => (
|
const entries = ChannelStore.getSortedPrivateChannels().filter(c => c.isGroupDM() && c.recipients.includes(user.id)).map(c => (
|
||||||
<Clickable
|
<Clickable
|
||||||
|
|
11
src/plugins/openInApp/README.md
Normal file
11
src/plugins/openInApp/README.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# OpenInApp
|
||||||
|
|
||||||
|
Open links in their respective apps instead of your browser
|
||||||
|
|
||||||
|
## Currently supports:
|
||||||
|
|
||||||
|
- Spotify
|
||||||
|
- Steam
|
||||||
|
- EpicGames
|
||||||
|
- Tidal
|
||||||
|
- Apple Music (iTunes)
|
|
@ -18,46 +18,70 @@
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType, PluginNative } from "@utils/types";
|
import definePlugin, { OptionType, PluginNative, SettingsDefinition } from "@utils/types";
|
||||||
import { showToast, Toasts } from "@webpack/common";
|
import { showToast, Toasts } from "@webpack/common";
|
||||||
import type { MouseEvent } from "react";
|
import type { MouseEvent } from "react";
|
||||||
|
|
||||||
const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/;
|
interface URLReplacementRule {
|
||||||
const SpotifyMatcher = /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user|episode)\/(.+)(?:\?.+?)?$/;
|
match: RegExp;
|
||||||
const SteamMatcher = /^https:\/\/(steamcommunity\.com|(?:help|store)\.steampowered\.com)\/.+$/;
|
replace: (...matches: string[]) => string;
|
||||||
const EpicMatcher = /^https:\/\/store\.epicgames\.com\/(.+)$/;
|
description: string;
|
||||||
const TidalMatcher = /^https:\/\/tidal\.com\/browse\/(track|album|artist|playlist|user|video|mix)\/(.+)(?:\?.+?)?$/;
|
shortlinkMatch?: RegExp;
|
||||||
|
accountViewReplace?: (userId: string) => string;
|
||||||
|
}
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
// Do not forget to add protocols to the ALLOWED_PROTOCOLS constant
|
||||||
|
const UrlReplacementRules: Record<string, URLReplacementRule> = {
|
||||||
spotify: {
|
spotify: {
|
||||||
type: OptionType.BOOLEAN,
|
match: /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user|episode)\/(.+)(?:\?.+?)?$/,
|
||||||
|
replace: (_, type, id) => `spotify://${type}/${id}`,
|
||||||
description: "Open Spotify links in the Spotify app",
|
description: "Open Spotify links in the Spotify app",
|
||||||
default: true,
|
shortlinkMatch: /^https:\/\/spotify\.link\/.+$/,
|
||||||
|
accountViewReplace: userId => `spotify:user:${userId}`,
|
||||||
},
|
},
|
||||||
steam: {
|
steam: {
|
||||||
type: OptionType.BOOLEAN,
|
match: /^https:\/\/(steamcommunity\.com|(?:help|store)\.steampowered\.com)\/.+$/,
|
||||||
|
replace: match => `steam://openurl/${match}`,
|
||||||
description: "Open Steam links in the Steam app",
|
description: "Open Steam links in the Steam app",
|
||||||
default: true,
|
shortlinkMatch: /^https:\/\/s.team\/.+$/,
|
||||||
|
accountViewReplace: userId => `steam://openurl/https://steamcommunity.com/profiles/${userId}`,
|
||||||
},
|
},
|
||||||
epic: {
|
epic: {
|
||||||
type: OptionType.BOOLEAN,
|
match: /^https:\/\/store\.epicgames\.com\/(.+)$/,
|
||||||
|
replace: (_, id) => `com.epicgames.launcher://store/${id}`,
|
||||||
description: "Open Epic Games links in the Epic Games Launcher",
|
description: "Open Epic Games links in the Epic Games Launcher",
|
||||||
default: true,
|
|
||||||
},
|
},
|
||||||
tidal: {
|
tidal: {
|
||||||
type: OptionType.BOOLEAN,
|
match: /^https:\/\/tidal\.com\/browse\/(track|album|artist|playlist|user|video|mix)\/(.+)(?:\?.+?)?$/,
|
||||||
|
replace: (_, type, id) => `tidal://${type}/${id}`,
|
||||||
description: "Open Tidal links in the Tidal app",
|
description: "Open Tidal links in the Tidal app",
|
||||||
|
},
|
||||||
|
itunes: {
|
||||||
|
match: /^https:\/\/music\.apple\.com\/([a-z]{2}\/)?(album|artist|playlist|song|curator)\/([^/?#]+)\/?([^/?#]+)?(?:\?.*)?(?:#.*)?$/,
|
||||||
|
replace: (_, lang, type, name, id) => id ? `itunes://music.apple.com/us/${type}/${name}/${id}` : `itunes://music.apple.com/us/${type}/${name}`,
|
||||||
|
description: "Open Apple Music links in the iTunes app"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const pluginSettings = definePluginSettings(
|
||||||
|
Object.entries(UrlReplacementRules).reduce((acc, [key, rule]) => {
|
||||||
|
acc[key] = {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: rule.description,
|
||||||
default: true,
|
default: true,
|
||||||
}
|
};
|
||||||
});
|
return acc;
|
||||||
|
}, {} as SettingsDefinition)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
const Native = VencordNative.pluginHelpers.OpenInApp as PluginNative<typeof import("./native")>;
|
const Native = VencordNative.pluginHelpers.OpenInApp as PluginNative<typeof import("./native")>;
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "OpenInApp",
|
name: "OpenInApp",
|
||||||
description: "Open Spotify, Tidal, Steam and Epic Games URLs in their respective apps instead of your browser",
|
description: "Open links in their respective apps instead of your browser",
|
||||||
authors: [Devs.Ven],
|
authors: [Devs.Ven, Devs.surgedevs],
|
||||||
settings,
|
settings: pluginSettings,
|
||||||
|
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
|
@ -70,7 +94,7 @@ export default definePlugin({
|
||||||
// Make Spotify profile activity links open in app on web
|
// Make Spotify profile activity links open in app on web
|
||||||
{
|
{
|
||||||
find: "WEB_OPEN(",
|
find: "WEB_OPEN(",
|
||||||
predicate: () => !IS_DISCORD_DESKTOP && settings.store.spotify,
|
predicate: () => !IS_DISCORD_DESKTOP && pluginSettings.store.spotify,
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /\i\.\i\.isProtocolRegistered\(\)(.{0,100})window.open/g,
|
match: /\i\.\i\.isProtocolRegistered\(\)(.{0,100})window.open/g,
|
||||||
replace: "true$1VencordNative.native.openExternal"
|
replace: "true$1VencordNative.native.openExternal"
|
||||||
|
@ -79,8 +103,8 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".CONNECTED_ACCOUNT_VIEWED,",
|
find: ".CONNECTED_ACCOUNT_VIEWED,",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<=href:\i,onClick:\i=>\{)(?=.{0,10}\i=(\i)\.type,.{0,100}CONNECTED_ACCOUNT_VIEWED)/,
|
match: /(?<=href:\i,onClick:(\i)=>\{)(?=.{0,10}\i=(\i)\.type,.{0,100}CONNECTED_ACCOUNT_VIEWED)/,
|
||||||
replace: "$self.handleAccountView(arguments[0],$1.type,$1.id);"
|
replace: "if($self.handleAccountView($1,$2.type,$2.id)) return;"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -89,61 +113,25 @@ export default definePlugin({
|
||||||
if (!data) return false;
|
if (!data) return false;
|
||||||
|
|
||||||
let url = data.href;
|
let url = data.href;
|
||||||
if (!IS_WEB && ShortUrlMatcher.test(url)) {
|
if (!url) return false;
|
||||||
|
|
||||||
|
for (const [key, rule] of Object.entries(UrlReplacementRules)) {
|
||||||
|
if (!pluginSettings.store[key]) continue;
|
||||||
|
|
||||||
|
if (rule.shortlinkMatch?.test(url)) {
|
||||||
event?.preventDefault();
|
event?.preventDefault();
|
||||||
// CORS jumpscare
|
|
||||||
url = await Native.resolveRedirect(url);
|
url = await Native.resolveRedirect(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
spotify: {
|
if (rule.match.test(url)) {
|
||||||
if (!settings.store.spotify) break spotify;
|
showToast("Opened link in native app", Toasts.Type.SUCCESS);
|
||||||
|
|
||||||
const match = SpotifyMatcher.exec(url);
|
const newUrl = url.replace(rule.match, rule.replace);
|
||||||
if (!match) break spotify;
|
VencordNative.native.openExternal(newUrl);
|
||||||
|
|
||||||
const [, type, id] = match;
|
|
||||||
VencordNative.native.openExternal(`spotify:${type}:${id}`);
|
|
||||||
|
|
||||||
event?.preventDefault();
|
event?.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
steam: {
|
|
||||||
if (!settings.store.steam) break steam;
|
|
||||||
|
|
||||||
if (!SteamMatcher.test(url)) break steam;
|
|
||||||
|
|
||||||
VencordNative.native.openExternal(`steam://openurl/${url}`);
|
|
||||||
event?.preventDefault();
|
|
||||||
|
|
||||||
// Steam does not focus itself so show a toast so it's slightly less confusing
|
|
||||||
showToast("Opened link in Steam", Toasts.Type.SUCCESS);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
epic: {
|
|
||||||
if (!settings.store.epic) break epic;
|
|
||||||
|
|
||||||
const match = EpicMatcher.exec(url);
|
|
||||||
if (!match) break epic;
|
|
||||||
|
|
||||||
VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`);
|
|
||||||
event?.preventDefault();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
tidal: {
|
|
||||||
if (!settings.store.tidal) break tidal;
|
|
||||||
|
|
||||||
const match = TidalMatcher.exec(url);
|
|
||||||
if (!match) break tidal;
|
|
||||||
|
|
||||||
const [, type, id] = match;
|
|
||||||
VencordNative.native.openExternal(`tidal://${type}/${id}`);
|
|
||||||
|
|
||||||
event?.preventDefault();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case short url didn't end up being something we can handle
|
// in case short url didn't end up being something we can handle
|
||||||
|
@ -155,14 +143,12 @@ export default definePlugin({
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
handleAccountView(event: { preventDefault(): void; }, platformType: string, userId: string) {
|
handleAccountView(e: MouseEvent, platformType: string, userId: string) {
|
||||||
if (platformType === "spotify" && settings.store.spotify) {
|
const rule = UrlReplacementRules[platformType];
|
||||||
VencordNative.native.openExternal(`spotify:user:${userId}`);
|
if (rule?.accountViewReplace && pluginSettings.store[platformType]) {
|
||||||
event.preventDefault();
|
VencordNative.native.openExternal(rule.accountViewReplace(userId));
|
||||||
} else if (platformType === "steam" && settings.store.steam) {
|
e.preventDefault();
|
||||||
VencordNative.native.openExternal(`steam://openurl/https://steamcommunity.com/profiles/${userId}`);
|
return true;
|
||||||
showToast("Opened link in Steam", Toasts.Type.SUCCESS);
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,7 +30,7 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".nonMediaMosaicItem]",
|
find: ".nonMediaMosaicItem]",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /\.nonMediaMosaicItem\]:!(\i).{0,10}children:\[(\S)/,
|
match: /\.nonMediaMosaicItem\]:!(\i).{0,50}?children:\[(\S)/,
|
||||||
replace: "$&,$1&&$2&&$self.renderPiPButton(),"
|
replace: "$&,$1&&$2&&$self.renderPiPButton(),"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -211,9 +211,9 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: /\.BITE_SIZE,onOpenProfile:\i,usernameIcon:/,
|
find: '"BiteSizeProfileBody"',
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /currentUser:\i,guild:\i,onOpenProfile:.+?}\)(?=])(?<=user:(\i),bio:null==(\i)\?.+?)/,
|
match: /currentUser:\i,guild:\i}\)(?<=user:(\i),bio:null==(\i)\?.+?)/,
|
||||||
replace: "$&,$self.profilePopoutComponent({ user: $1, displayProfile: $2, simplified: true })"
|
replace: "$&,$self.profilePopoutComponent({ user: $1, displayProfile: $2, simplified: true })"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,7 +307,7 @@ export default definePlugin({
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: '+1]})},"overflow"))',
|
find: '})},"overflow"))',
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
// Create a variable for the channel prop
|
// Create a variable for the channel prop
|
||||||
|
|
|
@ -66,6 +66,15 @@ export default definePlugin({
|
||||||
replace: "return true",
|
replace: "return true",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// fixes a bug where Members page must be loaded to see highest role, why is Discord depending on MemberSafetyStore.getEnhancedMember for something that can be obtained here?
|
||||||
|
{
|
||||||
|
find: "Messages.GUILD_MEMBER_MOD_VIEW_PERMISSION_GRANTED_BY_ARIA_LABEL,allowOverflow",
|
||||||
|
predicate: () => settings.store.showModView,
|
||||||
|
replacement: {
|
||||||
|
match: /(role:)\i(?=,guildId.{0,100}role:(\i\[))/,
|
||||||
|
replace: "$1$2arguments[0].member.highestRoleId]",
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
find: "prod_discoverable_guilds",
|
find: "prod_discoverable_guilds",
|
||||||
predicate: () => settings.store.disableDiscoveryFilters,
|
predicate: () => settings.store.disableDiscoveryFilters,
|
||||||
|
|
|
@ -48,7 +48,7 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
find: '"AccountConnected"',
|
find: "this.isCopiedStreakGodlike",
|
||||||
replacement: {
|
replacement: {
|
||||||
// react.jsx)(AccountPanel, { ..., showTaglessAccountPanel: blah })
|
// react.jsx)(AccountPanel, { ..., showTaglessAccountPanel: blah })
|
||||||
match: /(?<=\i\.jsxs?\)\()(\i),{(?=[^}]*?userTag:\i,hidePrivateData:)/,
|
match: /(?<=\i\.jsxs?\)\()(\i),{(?=[^}]*?userTag:\i,hidePrivateData:)/,
|
||||||
|
|
|
@ -17,10 +17,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ChatBarButton } from "@api/ChatButtons";
|
import { ChatBarButton } from "@api/ChatButtons";
|
||||||
import { Margins } from "@utils/margins";
|
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
import { openModal } from "@utils/modal";
|
import { openModal } from "@utils/modal";
|
||||||
import { Alerts, Forms } from "@webpack/common";
|
import { Alerts, Forms, Tooltip, useEffect, useState } from "@webpack/common";
|
||||||
|
|
||||||
import { settings } from "./settings";
|
import { settings } from "./settings";
|
||||||
import { TranslateModal } from "./TranslateModal";
|
import { TranslateModal } from "./TranslateModal";
|
||||||
|
@ -39,9 +38,17 @@ export function TranslateIcon({ height = 24, width = 24, className }: { height?:
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let setShouldShowTranslateEnabledTooltip: undefined | ((show: boolean) => void);
|
||||||
|
|
||||||
export const TranslateChatBarIcon: ChatBarButton = ({ isMainChat }) => {
|
export const TranslateChatBarIcon: ChatBarButton = ({ isMainChat }) => {
|
||||||
const { autoTranslate, showChatBarButton } = settings.use(["autoTranslate", "showChatBarButton"]);
|
const { autoTranslate, showChatBarButton } = settings.use(["autoTranslate", "showChatBarButton"]);
|
||||||
|
|
||||||
|
const [shouldShowTranslateEnabledTooltip, setter] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
setShouldShowTranslateEnabledTooltip = setter;
|
||||||
|
return () => setShouldShowTranslateEnabledTooltip = undefined;
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (!isMainChat || !showChatBarButton) return null;
|
if (!isMainChat || !showChatBarButton) return null;
|
||||||
|
|
||||||
const toggle = () => {
|
const toggle = () => {
|
||||||
|
@ -52,21 +59,20 @@ export const TranslateChatBarIcon: ChatBarButton = ({ isMainChat }) => {
|
||||||
title: "Vencord Auto-Translate Enabled",
|
title: "Vencord Auto-Translate Enabled",
|
||||||
body: <>
|
body: <>
|
||||||
<Forms.FormText>
|
<Forms.FormText>
|
||||||
You just enabled auto translate (by right clicking the Translate icon). Any message you send will automatically be translated before being sent.
|
You just enabled Auto Translate! Any message <b>will automatically be translated</b> before being sent.
|
||||||
</Forms.FormText>
|
|
||||||
<Forms.FormText className={Margins.top16}>
|
|
||||||
If this was an accident, disable it again, or it will change your message content before sending.
|
|
||||||
</Forms.FormText>
|
</Forms.FormText>
|
||||||
</>,
|
</>,
|
||||||
cancelText: "Disable Auto-Translate",
|
confirmText: "Disable Auto-Translate",
|
||||||
confirmText: "Got it",
|
cancelText: "Got it",
|
||||||
secondaryConfirmText: "Don't show again",
|
secondaryConfirmText: "Don't show again",
|
||||||
onConfirmSecondary: () => settings.store.showAutoTranslateAlert = false,
|
onConfirmSecondary: () => settings.store.showAutoTranslateAlert = false,
|
||||||
onCancel: () => settings.store.autoTranslate = false
|
onConfirm: () => settings.store.autoTranslate = false,
|
||||||
|
// troll
|
||||||
|
confirmColor: "vc-notification-log-danger-btn",
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
const button = (
|
||||||
<ChatBarButton
|
<ChatBarButton
|
||||||
tooltip="Open Translate Modal"
|
tooltip="Open Translate Modal"
|
||||||
onClick={e => {
|
onClick={e => {
|
||||||
|
@ -76,7 +82,7 @@ export const TranslateChatBarIcon: ChatBarButton = ({ isMainChat }) => {
|
||||||
<TranslateModal rootProps={props} />
|
<TranslateModal rootProps={props} />
|
||||||
));
|
));
|
||||||
}}
|
}}
|
||||||
onContextMenu={() => toggle()}
|
onContextMenu={toggle}
|
||||||
buttonProps={{
|
buttonProps={{
|
||||||
"aria-haspopup": "dialog"
|
"aria-haspopup": "dialog"
|
||||||
}}
|
}}
|
||||||
|
@ -84,4 +90,13 @@ export const TranslateChatBarIcon: ChatBarButton = ({ isMainChat }) => {
|
||||||
<TranslateIcon className={cl({ "auto-translate": autoTranslate, "chat-button": true })} />
|
<TranslateIcon className={cl({ "auto-translate": autoTranslate, "chat-button": true })} />
|
||||||
</ChatBarButton>
|
</ChatBarButton>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (shouldShowTranslateEnabledTooltip && settings.store.showAutoTranslateTooltip)
|
||||||
|
return (
|
||||||
|
<Tooltip text="Auto Translate Enabled" forceOpen>
|
||||||
|
{() => button}
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
|
||||||
|
return button;
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,9 +20,8 @@ import { Margins } from "@utils/margins";
|
||||||
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot } from "@utils/modal";
|
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot } from "@utils/modal";
|
||||||
import { Forms, SearchableSelect, Switch, useMemo } from "@webpack/common";
|
import { Forms, SearchableSelect, Switch, useMemo } from "@webpack/common";
|
||||||
|
|
||||||
import { Languages } from "./languages";
|
|
||||||
import { settings } from "./settings";
|
import { settings } from "./settings";
|
||||||
import { cl } from "./utils";
|
import { cl, getLanguages } from "./utils";
|
||||||
|
|
||||||
const LanguageSettingKeys = ["receivedInput", "receivedOutput", "sentInput", "sentOutput"] as const;
|
const LanguageSettingKeys = ["receivedInput", "receivedOutput", "sentInput", "sentOutput"] as const;
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ function LanguageSelect({ settingsKey, includeAuto }: { settingsKey: typeof Lang
|
||||||
|
|
||||||
const options = useMemo(
|
const options = useMemo(
|
||||||
() => {
|
() => {
|
||||||
const options = Object.entries(Languages).map(([value, label]) => ({ value, label }));
|
const options = Object.entries(getLanguages()).map(([value, label]) => ({ value, label }));
|
||||||
if (!includeAuto)
|
if (!includeAuto)
|
||||||
options.shift();
|
options.shift();
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
import { Parser, useEffect, useState } from "@webpack/common";
|
import { Parser, useEffect, useState } from "@webpack/common";
|
||||||
import { Message } from "discord-types/general";
|
import { Message } from "discord-types/general";
|
||||||
|
|
||||||
import { Languages } from "./languages";
|
|
||||||
import { TranslateIcon } from "./TranslateIcon";
|
import { TranslateIcon } from "./TranslateIcon";
|
||||||
import { cl, TranslationValue } from "./utils";
|
import { cl, TranslationValue } from "./utils";
|
||||||
|
|
||||||
|
@ -59,7 +58,7 @@ export function TranslationAccessory({ message }: { message: Message; }) {
|
||||||
<TranslateIcon width={16} height={16} />
|
<TranslateIcon width={16} height={16} />
|
||||||
{Parser.parse(translation.text)}
|
{Parser.parse(translation.text)}
|
||||||
{" "}
|
{" "}
|
||||||
(translated from {Languages[translation.src] ?? translation.src} - <Dismiss onDismiss={() => setTranslation(undefined)} />)
|
(translated from {translation.sourceLanguage} - <Dismiss onDismiss={() => setTranslation(undefined)} />)
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import definePlugin from "@utils/types";
|
||||||
import { ChannelStore, Menu } from "@webpack/common";
|
import { ChannelStore, Menu } from "@webpack/common";
|
||||||
|
|
||||||
import { settings } from "./settings";
|
import { settings } from "./settings";
|
||||||
import { TranslateChatBarIcon, TranslateIcon } from "./TranslateIcon";
|
import { setShouldShowTranslateEnabledTooltip, TranslateChatBarIcon, TranslateIcon } from "./TranslateIcon";
|
||||||
import { handleTranslate, TranslationAccessory } from "./TranslationAccessory";
|
import { handleTranslate, TranslationAccessory } from "./TranslationAccessory";
|
||||||
import { translate } from "./utils";
|
import { translate } from "./utils";
|
||||||
|
|
||||||
|
@ -53,8 +53,8 @@ const messageCtxPatch: NavContextMenuPatchCallback = (children, { message }) =>
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "Translate",
|
name: "Translate",
|
||||||
description: "Translate messages with Google Translate",
|
description: "Translate messages with Google Translate or DeepL",
|
||||||
authors: [Devs.Ven],
|
authors: [Devs.Ven, Devs.AshtonMemer],
|
||||||
dependencies: ["MessageAccessoriesAPI", "MessagePopoverAPI", "MessageEventsAPI", "ChatInputButtonAPI"],
|
dependencies: ["MessageAccessoriesAPI", "MessagePopoverAPI", "MessageEventsAPI", "ChatInputButtonAPI"],
|
||||||
settings,
|
settings,
|
||||||
contextMenus: {
|
contextMenus: {
|
||||||
|
@ -83,11 +83,18 @@ export default definePlugin({
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let tooltipTimeout: any;
|
||||||
this.preSend = addPreSendListener(async (_, message) => {
|
this.preSend = addPreSendListener(async (_, message) => {
|
||||||
if (!settings.store.autoTranslate) return;
|
if (!settings.store.autoTranslate) return;
|
||||||
if (!message.content) return;
|
if (!message.content) return;
|
||||||
|
|
||||||
message.content = (await translate("sent", message.content)).text;
|
setShouldShowTranslateEnabledTooltip?.(true);
|
||||||
|
clearTimeout(tooltipTimeout);
|
||||||
|
tooltipTimeout = setTimeout(() => setShouldShowTranslateEnabledTooltip?.(false), 2000);
|
||||||
|
|
||||||
|
const trans = await translate("sent", message.content);
|
||||||
|
message.content = trans.text;
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,10 @@ copy(Object.fromEntries(
|
||||||
))
|
))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type Language = keyof typeof Languages;
|
export type GoogleLanguage = keyof typeof GoogleLanguages;
|
||||||
|
export type DeeplLanguage = keyof typeof DeeplLanguages;
|
||||||
|
|
||||||
export const Languages = {
|
export const GoogleLanguages = {
|
||||||
"auto": "Detect language",
|
"auto": "Detect language",
|
||||||
"af": "Afrikaans",
|
"af": "Afrikaans",
|
||||||
"sq": "Albanian",
|
"sq": "Albanian",
|
||||||
|
@ -169,3 +170,57 @@ export const Languages = {
|
||||||
"yo": "Yoruba",
|
"yo": "Yoruba",
|
||||||
"zu": "Zulu"
|
"zu": "Zulu"
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const DeeplLanguages = {
|
||||||
|
"": "Detect language",
|
||||||
|
"ar": "Arabic",
|
||||||
|
"bg": "Bulgarian",
|
||||||
|
"zh-hans": "Chinese (Simplified)",
|
||||||
|
"zh-hant": "Chinese (Traditional)",
|
||||||
|
"cs": "Czech",
|
||||||
|
"da": "Danish",
|
||||||
|
"nl": "Dutch",
|
||||||
|
"en-us": "English (American)",
|
||||||
|
"en-gb": "English (British)",
|
||||||
|
"et": "Estonian",
|
||||||
|
"fi": "Finnish",
|
||||||
|
"fr": "French",
|
||||||
|
"de": "German",
|
||||||
|
"el": "Greek",
|
||||||
|
"hu": "Hungarian",
|
||||||
|
"id": "Indonesian",
|
||||||
|
"it": "Italian",
|
||||||
|
"ja": "Japanese",
|
||||||
|
"ko": "Korean",
|
||||||
|
"lv": "Latvian",
|
||||||
|
"lt": "Lithuanian",
|
||||||
|
"nb": "Norwegian",
|
||||||
|
"pl": "Polish",
|
||||||
|
"pt-br": "Portuguese (Brazilian)",
|
||||||
|
"pt-pt": "Portuguese (European)",
|
||||||
|
"ro": "Romanian",
|
||||||
|
"ru": "Russian",
|
||||||
|
"sk": "Slovak",
|
||||||
|
"sl": "Slovenian",
|
||||||
|
"es": "Spanish",
|
||||||
|
"sv": "Swedish",
|
||||||
|
"tr": "Turkish",
|
||||||
|
"uk": "Ukrainian"
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export function deeplLanguageToGoogleLanguage(language: string) {
|
||||||
|
switch (language) {
|
||||||
|
case "": return "auto";
|
||||||
|
case "nb": return "no";
|
||||||
|
case "zh-hans": return "zh-CN";
|
||||||
|
case "zh-hant": return "zh-TW";
|
||||||
|
case "en-us":
|
||||||
|
case "en-gb":
|
||||||
|
return "en";
|
||||||
|
case "pt-br":
|
||||||
|
case "pt-pt":
|
||||||
|
return "pt";
|
||||||
|
default:
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
29
src/plugins/translate/native.ts
Normal file
29
src/plugins/translate/native.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { IpcMainInvokeEvent } from "electron";
|
||||||
|
|
||||||
|
export async function makeDeeplTranslateRequest(_: IpcMainInvokeEvent, pro: boolean, apiKey: string, payload: string) {
|
||||||
|
const url = pro
|
||||||
|
? "https://api.deepl.com/v2/translate"
|
||||||
|
: "https://api-free.deepl.com/v2/translate";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": `DeepL-Auth-Key ${apiKey}`
|
||||||
|
},
|
||||||
|
body: payload
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await res.text();
|
||||||
|
return { status: res.status, data };
|
||||||
|
} catch (e) {
|
||||||
|
return { status: -1, data: String(e) };
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,38 +22,76 @@ import { OptionType } from "@utils/types";
|
||||||
export const settings = definePluginSettings({
|
export const settings = definePluginSettings({
|
||||||
receivedInput: {
|
receivedInput: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Input language for received messages",
|
description: "Language that received messages should be translated from",
|
||||||
default: "auto",
|
default: "auto",
|
||||||
hidden: true
|
hidden: true
|
||||||
},
|
},
|
||||||
receivedOutput: {
|
receivedOutput: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Output language for received messages",
|
description: "Language that received messages should be translated to",
|
||||||
default: "en",
|
default: "en",
|
||||||
hidden: true
|
hidden: true
|
||||||
},
|
},
|
||||||
sentInput: {
|
sentInput: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Input language for sent messages",
|
description: "Language that your own messages should be translated from",
|
||||||
default: "auto",
|
default: "auto",
|
||||||
hidden: true
|
hidden: true
|
||||||
},
|
},
|
||||||
sentOutput: {
|
sentOutput: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Output language for sent messages",
|
description: "Language that your own messages should be translated to",
|
||||||
default: "en",
|
default: "en",
|
||||||
hidden: true
|
hidden: true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showChatBarButton: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
description: "Show translate button in chat bar",
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
service: {
|
||||||
|
type: OptionType.SELECT,
|
||||||
|
description: IS_WEB ? "Translation service (Not supported on Web!)" : "Translation service",
|
||||||
|
disabled: () => IS_WEB,
|
||||||
|
options: [
|
||||||
|
{ label: "Google Translate", value: "google", default: true },
|
||||||
|
{ label: "DeepL Free", value: "deepl" },
|
||||||
|
{ label: "DeepL Pro", value: "deepl-pro" }
|
||||||
|
] as const,
|
||||||
|
onChange: resetLanguageDefaults
|
||||||
|
},
|
||||||
|
deeplApiKey: {
|
||||||
|
type: OptionType.STRING,
|
||||||
|
description: "DeepL API key",
|
||||||
|
default: "",
|
||||||
|
placeholder: "Get your API key from https://deepl.com/your-account",
|
||||||
|
disabled: () => IS_WEB
|
||||||
|
},
|
||||||
autoTranslate: {
|
autoTranslate: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Automatically translate your messages before sending. You can also shift/right click the translate button to toggle this",
|
description: "Automatically translate your messages before sending. You can also shift/right click the translate button to toggle this",
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
showChatBarButton: {
|
showAutoTranslateTooltip: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Show translate button in chat bar",
|
description: "Show a tooltip on the ChatBar button whenever a message is automatically translated",
|
||||||
default: true
|
default: true
|
||||||
}
|
},
|
||||||
}).withPrivateSettings<{
|
}).withPrivateSettings<{
|
||||||
showAutoTranslateAlert: boolean;
|
showAutoTranslateAlert: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
export function resetLanguageDefaults() {
|
||||||
|
if (IS_WEB || settings.store.service === "google") {
|
||||||
|
settings.store.receivedInput = "auto";
|
||||||
|
settings.store.receivedOutput = "en";
|
||||||
|
settings.store.sentInput = "auto";
|
||||||
|
settings.store.sentOutput = "en";
|
||||||
|
} else {
|
||||||
|
settings.store.receivedInput = "";
|
||||||
|
settings.store.receivedOutput = "en-us";
|
||||||
|
settings.store.sentInput = "";
|
||||||
|
settings.store.sentOutput = "en-us";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,12 +17,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { classNameFactory } from "@api/Styles";
|
import { classNameFactory } from "@api/Styles";
|
||||||
|
import { onlyOnce } from "@utils/onlyOnce";
|
||||||
|
import { PluginNative } from "@utils/types";
|
||||||
|
import { showToast, Toasts } from "@webpack/common";
|
||||||
|
|
||||||
import { settings } from "./settings";
|
import { DeeplLanguages, deeplLanguageToGoogleLanguage, GoogleLanguages } from "./languages";
|
||||||
|
import { resetLanguageDefaults, settings } from "./settings";
|
||||||
|
|
||||||
export const cl = classNameFactory("vc-trans-");
|
export const cl = classNameFactory("vc-trans-");
|
||||||
|
|
||||||
interface TranslationData {
|
const Native = VencordNative.pluginHelpers.Translate as PluginNative<typeof import("./native")>;
|
||||||
|
|
||||||
|
interface GoogleData {
|
||||||
src: string;
|
src: string;
|
||||||
sentences: {
|
sentences: {
|
||||||
// 🏳️⚧️
|
// 🏳️⚧️
|
||||||
|
@ -30,15 +36,47 @@ interface TranslationData {
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DeeplData {
|
||||||
|
translations: {
|
||||||
|
detected_source_language: string;
|
||||||
|
text: string;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface TranslationValue {
|
export interface TranslationValue {
|
||||||
src: string;
|
sourceLanguage: string;
|
||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function translate(kind: "received" | "sent", text: string): Promise<TranslationValue> {
|
export const getLanguages = () => IS_WEB || settings.store.service === "google"
|
||||||
const sourceLang = settings.store[kind + "Input"];
|
? GoogleLanguages
|
||||||
const targetLang = settings.store[kind + "Output"];
|
: DeeplLanguages;
|
||||||
|
|
||||||
|
export async function translate(kind: "received" | "sent", text: string): Promise<TranslationValue> {
|
||||||
|
const translate = IS_WEB || settings.store.service === "google"
|
||||||
|
? googleTranslate
|
||||||
|
: deeplTranslate;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await translate(
|
||||||
|
text,
|
||||||
|
settings.store[`${kind}Input`],
|
||||||
|
settings.store[`${kind}Output`]
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
const userMessage = typeof e === "string"
|
||||||
|
? e
|
||||||
|
: "Something went wrong. If this issue persists, please check the console or ask for help in the support server.";
|
||||||
|
|
||||||
|
showToast(userMessage, Toasts.Type.FAILURE);
|
||||||
|
|
||||||
|
throw e instanceof Error
|
||||||
|
? e
|
||||||
|
: new Error(userMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function googleTranslate(text: string, sourceLang: string, targetLang: string): Promise<TranslationValue> {
|
||||||
const url = "https://translate.googleapis.com/translate_a/single?" + new URLSearchParams({
|
const url = "https://translate.googleapis.com/translate_a/single?" + new URLSearchParams({
|
||||||
// see https://stackoverflow.com/a/29537590 for more params
|
// see https://stackoverflow.com/a/29537590 for more params
|
||||||
// holy shidd nvidia
|
// holy shidd nvidia
|
||||||
|
@ -63,13 +101,69 @@ export async function translate(kind: "received" | "sent", text: string): Promis
|
||||||
+ `\n${res.status} ${res.statusText}`
|
+ `\n${res.status} ${res.statusText}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const { src, sentences }: TranslationData = await res.json();
|
const { src, sentences }: GoogleData = await res.json();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
src,
|
sourceLanguage: GoogleLanguages[src] ?? src,
|
||||||
text: sentences.
|
text: sentences.
|
||||||
map(s => s?.trans).
|
map(s => s?.trans).
|
||||||
filter(Boolean).
|
filter(Boolean).
|
||||||
join("")
|
join("")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fallbackToGoogle(text: string, sourceLang: string, targetLang: string): Promise<TranslationValue> {
|
||||||
|
return googleTranslate(
|
||||||
|
text,
|
||||||
|
deeplLanguageToGoogleLanguage(sourceLang),
|
||||||
|
deeplLanguageToGoogleLanguage(targetLang)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const showDeeplApiQuotaToast = onlyOnce(
|
||||||
|
() => showToast("Deepl API quota exceeded. Falling back to Google Translate", Toasts.Type.FAILURE)
|
||||||
|
);
|
||||||
|
|
||||||
|
async function deeplTranslate(text: string, sourceLang: string, targetLang: string): Promise<TranslationValue> {
|
||||||
|
if (!settings.store.deeplApiKey) {
|
||||||
|
showToast("DeepL API key is not set. Resetting to Google", Toasts.Type.FAILURE);
|
||||||
|
|
||||||
|
settings.store.service = "google";
|
||||||
|
resetLanguageDefaults();
|
||||||
|
|
||||||
|
return fallbackToGoogle(text, sourceLang, targetLang);
|
||||||
|
}
|
||||||
|
|
||||||
|
// CORS jumpscare
|
||||||
|
const { status, data } = await Native.makeDeeplTranslateRequest(
|
||||||
|
settings.store.service === "deepl-pro",
|
||||||
|
settings.store.deeplApiKey,
|
||||||
|
JSON.stringify({
|
||||||
|
text: [text],
|
||||||
|
target_lang: targetLang,
|
||||||
|
source_lang: sourceLang.split("-")[0]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
case 200:
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
throw "Failed to connect to DeepL API: " + data;
|
||||||
|
case 403:
|
||||||
|
throw "Invalid DeepL API key or version";
|
||||||
|
case 456:
|
||||||
|
showDeeplApiQuotaToast();
|
||||||
|
return fallbackToGoogle(text, sourceLang, targetLang);
|
||||||
|
default:
|
||||||
|
throw new Error(`Failed to translate "${text}" (${sourceLang} -> ${targetLang})\n${status} ${data}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { translations }: DeeplData = JSON.parse(data);
|
||||||
|
const src = translations[0].detected_source_language;
|
||||||
|
|
||||||
|
return {
|
||||||
|
sourceLanguage: DeeplLanguages[src] ?? src,
|
||||||
|
text: translations[0].text
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -189,7 +189,8 @@ export default definePlugin({
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /avatarSrc:(\i),eventHandlers:(\i).+?"div",{...\2,/,
|
match: /avatarSrc:(\i),eventHandlers:(\i).+?"div",{...\2,/,
|
||||||
replace: "$&style:{cursor:\"pointer\"},onClick:()=>{$self.openImage($1)},"
|
replace: "$&style:{cursor:\"pointer\"},onClick:()=>{$self.openImage($1)},"
|
||||||
}
|
},
|
||||||
|
all: true
|
||||||
},
|
},
|
||||||
// Old Profiles Modal pfp
|
// Old Profiles Modal pfp
|
||||||
{
|
{
|
||||||
|
|
|
@ -153,6 +153,7 @@ export default definePlugin({
|
||||||
contextMenus: {
|
contextMenus: {
|
||||||
"guild-context": MakeContextCallback("Guild"),
|
"guild-context": MakeContextCallback("Guild"),
|
||||||
"channel-context": MakeContextCallback("Channel"),
|
"channel-context": MakeContextCallback("Channel"),
|
||||||
|
"thread-context": MakeContextCallback("Channel"),
|
||||||
"user-context": MakeContextCallback("User")
|
"user-context": MakeContextCallback("User")
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
# XSOverlay Notifier
|
|
||||||
|
|
||||||
Sends Discord messages to [XSOverlay](https://store.steampowered.com/app/1173510/XSOverlay/) for easier viewing while using VR.
|
|
||||||
|
|
||||||
## Preview
|
|
||||||
|
|
||||||
![](https://github.com/Vendicated/Vencord/assets/24845294/205d2055-bb4a-44e4-b7e3-265391bccd40)
|
|
||||||
|
|
||||||
![](https://github.com/Vendicated/Vencord/assets/24845294/f15eff61-2d52-4620-bcab-808ecb1606d2)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
- Enable this plugin
|
|
||||||
- Set plugin settings as desired
|
|
||||||
- Open XSOverlay
|
|
||||||
- get ping spammed
|
|
|
@ -1,16 +0,0 @@
|
||||||
/*
|
|
||||||
* Vencord, a Discord client mod
|
|
||||||
* Copyright (c) 2023 Vendicated and contributors
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { createSocket, Socket } from "dgram";
|
|
||||||
|
|
||||||
let xsoSocket: Socket;
|
|
||||||
|
|
||||||
export function sendToOverlay(_, data: any) {
|
|
||||||
data.icon = Buffer.from(data.icon).toString("base64");
|
|
||||||
const json = JSON.stringify(data);
|
|
||||||
xsoSocket ??= createSocket("udp4");
|
|
||||||
xsoSocket.send(json, 42069, "127.0.0.1");
|
|
||||||
}
|
|
14
src/plugins/xsOverlay/README.md
Normal file
14
src/plugins/xsOverlay/README.md
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# XSOverlay Notifier
|
||||||
|
|
||||||
|
Sends Discord messages to [XSOverlay](https://store.steampowered.com/app/1173510/XSOverlay/) for easier viewing while using VR.
|
||||||
|
|
||||||
|
## Preview
|
||||||
|
|
||||||
|
![Resulting notification inside XSOverlay](https://github.com/Vendicated/Vencord/assets/24845294/205d2055-bb4a-44e4-b7e3-265391bccd40)
|
||||||
|
|
||||||
|
![Test notification inside XSOverlay](https://github.com/user-attachments/assets/d3b0c387-1d67-4697-a470-d4a927e228f4)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
- Enable this plugin
|
||||||
|
- Set port and plugin settings as desired (defaults should work fine)
|
||||||
|
- Open SteamVR and XSOverlay
|
|
@ -8,9 +8,9 @@ import { definePluginSettings } from "@api/Settings";
|
||||||
import { makeRange } from "@components/PluginSettings/components";
|
import { makeRange } from "@components/PluginSettings/components";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { Logger } from "@utils/Logger";
|
import { Logger } from "@utils/Logger";
|
||||||
import definePlugin, { OptionType, PluginNative, ReporterTestable } from "@utils/types";
|
import definePlugin, { OptionType, ReporterTestable } from "@utils/types";
|
||||||
import { findByCodeLazy, findLazy } from "@webpack";
|
import { findByCodeLazy, findLazy } from "@webpack";
|
||||||
import { ChannelStore, GuildStore, UserStore } from "@webpack/common";
|
import { Button, ChannelStore, GuildStore, UserStore } from "@webpack/common";
|
||||||
import type { Channel, Embed, GuildMember, MessageAttachment, User } from "discord-types/general";
|
import type { Channel, Embed, GuildMember, MessageAttachment, User } from "discord-types/general";
|
||||||
|
|
||||||
const ChannelTypes = findLazy(m => m.ANNOUNCEMENT_THREAD === 10);
|
const ChannelTypes = findLazy(m => m.ANNOUNCEMENT_THREAD === 10);
|
||||||
|
@ -68,10 +68,40 @@ interface Call {
|
||||||
ringing: string[];
|
ringing: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ApiObject {
|
||||||
|
sender: string,
|
||||||
|
target: string,
|
||||||
|
command: string,
|
||||||
|
jsonData: string,
|
||||||
|
rawData: string | null,
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NotificationObject {
|
||||||
|
type: number;
|
||||||
|
timeout: number;
|
||||||
|
height: number;
|
||||||
|
opacity: number;
|
||||||
|
volume: number;
|
||||||
|
audioPath: string;
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
useBase64Icon: boolean;
|
||||||
|
icon: ArrayBuffer | string;
|
||||||
|
sourceApp: string;
|
||||||
|
}
|
||||||
|
|
||||||
const notificationsShouldNotify = findByCodeLazy(".SUPPRESS_NOTIFICATIONS))return!1");
|
const notificationsShouldNotify = findByCodeLazy(".SUPPRESS_NOTIFICATIONS))return!1");
|
||||||
const XSLog = new Logger("XSOverlay");
|
const logger = new Logger("XSOverlay");
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
|
webSocketPort: {
|
||||||
|
type: OptionType.NUMBER,
|
||||||
|
description: "Websocket port",
|
||||||
|
default: 42070,
|
||||||
|
async onChange() {
|
||||||
|
await start();
|
||||||
|
}
|
||||||
|
},
|
||||||
botNotifications: {
|
botNotifications: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Allow bot notifications",
|
description: "Allow bot notifications",
|
||||||
|
@ -136,7 +166,17 @@ const settings = definePluginSettings({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const Native = VencordNative.pluginHelpers.XSOverlay as PluginNative<typeof import("./native")>;
|
let socket: WebSocket;
|
||||||
|
|
||||||
|
async function start() {
|
||||||
|
if (socket) socket.close();
|
||||||
|
socket = new WebSocket(`ws://127.0.0.1:${settings.store.webSocketPort ?? 42070}/?client=Vencord`);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
socket.onopen = resolve;
|
||||||
|
socket.onerror = reject;
|
||||||
|
setTimeout(reject, 3000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "XSOverlay",
|
name: "XSOverlay",
|
||||||
|
@ -248,7 +288,21 @@ export default definePlugin({
|
||||||
if (shouldIgnoreForChannelType(channel)) return;
|
if (shouldIgnoreForChannelType(channel)) return;
|
||||||
sendMsgNotif(titleString, finalMsg, message);
|
sendMsgNotif(titleString, finalMsg, message);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
|
start,
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
socket.close();
|
||||||
|
},
|
||||||
|
|
||||||
|
settingsAboutComponent: () => (
|
||||||
|
<>
|
||||||
|
<Button onClick={() => sendOtherNotif("This is a test notification! explode", "Hello from Vendor!")}>
|
||||||
|
Send test notification
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
function shouldIgnoreForChannelType(channel: Channel) {
|
function shouldIgnoreForChannelType(channel: Channel) {
|
||||||
|
@ -259,9 +313,8 @@ function shouldIgnoreForChannelType(channel: Channel) {
|
||||||
|
|
||||||
function sendMsgNotif(titleString: string, content: string, message: Message) {
|
function sendMsgNotif(titleString: string, content: string, message: Message) {
|
||||||
fetch(`https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.png?size=128`).then(response => response.arrayBuffer()).then(result => {
|
fetch(`https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.png?size=128`).then(response => response.arrayBuffer()).then(result => {
|
||||||
const msgData = {
|
const msgData: NotificationObject = {
|
||||||
messageType: 1,
|
type: 1,
|
||||||
index: 0,
|
|
||||||
timeout: settings.store.lengthBasedTimeout ? calculateTimeout(content) : settings.store.timeout,
|
timeout: settings.store.lengthBasedTimeout ? calculateTimeout(content) : settings.store.timeout,
|
||||||
height: calculateHeight(content),
|
height: calculateHeight(content),
|
||||||
opacity: settings.store.opacity,
|
opacity: settings.store.opacity,
|
||||||
|
@ -270,17 +323,17 @@ function sendMsgNotif(titleString: string, content: string, message: Message) {
|
||||||
title: titleString,
|
title: titleString,
|
||||||
content: content,
|
content: content,
|
||||||
useBase64Icon: true,
|
useBase64Icon: true,
|
||||||
icon: result,
|
icon: new TextDecoder().decode(result),
|
||||||
sourceApp: "Vencord"
|
sourceApp: "Vencord"
|
||||||
};
|
};
|
||||||
Native.sendToOverlay(msgData);
|
|
||||||
|
sendToOverlay(msgData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendOtherNotif(content: string, titleString: string) {
|
function sendOtherNotif(content: string, titleString: string) {
|
||||||
const msgData = {
|
const msgData: NotificationObject = {
|
||||||
messageType: 1,
|
type: 1,
|
||||||
index: 0,
|
|
||||||
timeout: settings.store.lengthBasedTimeout ? calculateTimeout(content) : settings.store.timeout,
|
timeout: settings.store.lengthBasedTimeout ? calculateTimeout(content) : settings.store.timeout,
|
||||||
height: calculateHeight(content),
|
height: calculateHeight(content),
|
||||||
opacity: settings.store.opacity,
|
opacity: settings.store.opacity,
|
||||||
|
@ -289,10 +342,22 @@ function sendOtherNotif(content: string, titleString: string) {
|
||||||
title: titleString,
|
title: titleString,
|
||||||
content: content,
|
content: content,
|
||||||
useBase64Icon: false,
|
useBase64Icon: false,
|
||||||
icon: null,
|
icon: "default",
|
||||||
sourceApp: "Vencord"
|
sourceApp: "Vencord"
|
||||||
};
|
};
|
||||||
Native.sendToOverlay(msgData);
|
sendToOverlay(msgData);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendToOverlay(notif: NotificationObject) {
|
||||||
|
const apiObject: ApiObject = {
|
||||||
|
sender: "Vencord",
|
||||||
|
target: "xsoverlay",
|
||||||
|
command: "SendNotification",
|
||||||
|
jsonData: JSON.stringify(notif),
|
||||||
|
rawData: null
|
||||||
|
};
|
||||||
|
if (socket.readyState !== socket.OPEN) await start();
|
||||||
|
socket.send(JSON.stringify(apiObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldNotify(message: Message, channel: string) {
|
function shouldNotify(message: Message, channel: string) {
|
|
@ -1,6 +1,7 @@
|
||||||
# WatchTogetherAdblock
|
# WatchTogetherAdblock
|
||||||
|
|
||||||
Block ads in the YouTube WatchTogether activity via AdGuard
|
Block ads in YouTube embeds and the WatchTogether activity via AdGuard
|
||||||
|
|
||||||
Note that this only works for yourself, other users in the activity will still see ads.
|
Note that this only works for yourself, other users in the activity will still see ads.
|
||||||
|
|
||||||
Powered by a modified version of [Adguard's BlockYoutubeAdsShortcut](https://github.com/AdguardTeam/BlockYouTubeAdsShortcut)
|
Powered by a modified version of [Adguard's BlockYoutubeAdsShortcut](https://github.com/AdguardTeam/BlockYouTubeAdsShortcut)
|
|
@ -4,12 +4,14 @@
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { migratePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
|
|
||||||
// The entire code of this plugin can be found in native.ts
|
// The entire code of this plugin can be found in native.ts
|
||||||
|
migratePluginSettings("YoutubeAdblock", "WatchTogetherAdblock");
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "WatchTogetherAdblock",
|
name: "YoutubeAdblock",
|
||||||
description: "Block ads in the YouTube WatchTogether activity via AdGuard",
|
description: "Block ads in YouTube embeds and the WatchTogether activity via AdGuard",
|
||||||
authors: [Devs.ImLvna],
|
authors: [Devs.ImLvna, Devs.Ven],
|
||||||
});
|
});
|
|
@ -11,9 +11,9 @@ import adguard from "file://adguard.js?minify";
|
||||||
app.on("browser-window-created", (_, win) => {
|
app.on("browser-window-created", (_, win) => {
|
||||||
win.webContents.on("frame-created", (_, { frame }) => {
|
win.webContents.on("frame-created", (_, { frame }) => {
|
||||||
frame.once("dom-ready", () => {
|
frame.once("dom-ready", () => {
|
||||||
if (frame.url.includes("discordsays") && frame.url.includes("youtube.com")) {
|
if (!RendererSettings.store.plugins?.YoutubeAdblock?.enabled) return;
|
||||||
if (!RendererSettings.store.plugins?.WatchTogetherAdblock?.enabled) return;
|
|
||||||
|
|
||||||
|
if (frame.url.includes("youtube.com/embed/") || (frame.url.includes("discordsays") && frame.url.includes("youtube.com"))) {
|
||||||
frame.executeJavaScript(adguard);
|
frame.executeJavaScript(adguard);
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -533,6 +533,18 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
||||||
Antti: {
|
Antti: {
|
||||||
name: "Antti",
|
name: "Antti",
|
||||||
id: 312974985876471810n
|
id: 312974985876471810n
|
||||||
|
},
|
||||||
|
Joona: {
|
||||||
|
name: "Joona",
|
||||||
|
id: 297410829589020673n
|
||||||
|
},
|
||||||
|
AshtonMemer: {
|
||||||
|
name: "AshtonMemer",
|
||||||
|
id: 373657230530052099n
|
||||||
|
},
|
||||||
|
surgedevs: {
|
||||||
|
name: "Chloe",
|
||||||
|
id: 1084592643784331324n
|
||||||
}
|
}
|
||||||
} satisfies Record<string, Dev>);
|
} satisfies Record<string, Dev>);
|
||||||
|
|
||||||
|
|
|
@ -544,7 +544,7 @@ export async function extractAndLoadChunks(code: CodeFilter, matcher: RegExp = D
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawChunkIds) {
|
if (rawChunkIds) {
|
||||||
const chunkIds = Array.from(rawChunkIds.matchAll(ChunkIdsRegex)).map((m: any) => m[1]);
|
const chunkIds = Array.from(rawChunkIds.matchAll(ChunkIdsRegex)).map((m: any) => Number(m[1]));
|
||||||
await Promise.all(chunkIds.map(id => wreq.e(id)));
|
await Promise.all(chunkIds.map(id => wreq.e(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,7 +559,7 @@ export async function extractAndLoadChunks(code: CodeFilter, matcher: RegExp = D
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wreq(entryPointId);
|
wreq(Number(entryPointId));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue