From a0e7398725b70e3c0e0364a3eb773915f3548639 Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Sun, 17 Dec 2023 13:20:49 +0100 Subject: [PATCH 01/11] Add TextEmoji plugin The plugin prevents Discord from replacing emoji with images, leaving it up to the browser to render them. --- src/plugins/textEmoji/index.ts | 42 ++++++++++++++++++++++++++++++++++ src/utils/constants.ts | 4 ++++ 2 files changed, 46 insertions(+) create mode 100644 src/plugins/textEmoji/index.ts diff --git a/src/plugins/textEmoji/index.ts b/src/plugins/textEmoji/index.ts new file mode 100644 index 000000000..7e8da3b8f --- /dev/null +++ b/src/plugins/textEmoji/index.ts @@ -0,0 +1,42 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 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 . +*/ + +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; + +export default definePlugin({ + name: "TextEmoji", + description: "Prevents Discord from replacing emoji with images, leaving it up to the browser to render them", + authors: [Devs.Grzesiek11], + patches: [ + { + find: "getSrc(){", + replacement: { + match: /(if\(null!=.{1,2}\))return .{1,2}\.default\.getURL\(.{1,2}\)/, + replace: "$1return null", + }, + }, + { + find: ",findInlineEmojisFromSurrogates:", + replacement: { + match: /if\(!0!==.{1,2}&&!.{1,2}\.test\(.{1,2}\)\)/, + replace: "", + }, + }, + ], +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 2962df06f..a94ba0fc3 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -399,6 +399,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "maisy", id: 257109471589957632n, }, + Grzesiek11: { + name: "Grzesiek11", + id: 368475654662127616n, + }, } satisfies Record); // iife so #__PURE__ works correctly From 14512a50eb880df5efc22398d2e735083f117d2f Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Fri, 22 Dec 2023 14:18:03 +0100 Subject: [PATCH 02/11] Fix reactions breaking on ZWJ Reactions with emoji that use ZWJ can break into multiple lines, due to the ZWJ being considered whitespace, and the container not being big enough to fit them. This commit fixes this by applying a white-space: nowrap declaration to the emoji container. --- src/plugins/textEmoji/index.ts | 2 ++ src/plugins/textEmoji/styles.css | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 src/plugins/textEmoji/styles.css diff --git a/src/plugins/textEmoji/index.ts b/src/plugins/textEmoji/index.ts index 7e8da3b8f..af792cb13 100644 --- a/src/plugins/textEmoji/index.ts +++ b/src/plugins/textEmoji/index.ts @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +import "./styles.css"; + import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; diff --git a/src/plugins/textEmoji/styles.css b/src/plugins/textEmoji/styles.css new file mode 100644 index 000000000..f08a7e9bf --- /dev/null +++ b/src/plugins/textEmoji/styles.css @@ -0,0 +1,3 @@ +.reaction_fef95b .emoji { + white-space: nowrap; +} From 47c33696fc8125028c3cd81ad7eb61aa41edf1e8 Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Fri, 22 Dec 2023 18:51:27 +0100 Subject: [PATCH 03/11] Use \i instead of .{1,2} to match identifiers --- src/plugins/textEmoji/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/textEmoji/index.ts b/src/plugins/textEmoji/index.ts index af792cb13..e022e9a4b 100644 --- a/src/plugins/textEmoji/index.ts +++ b/src/plugins/textEmoji/index.ts @@ -29,7 +29,7 @@ export default definePlugin({ { find: "getSrc(){", replacement: { - match: /(if\(null!=.{1,2}\))return .{1,2}\.default\.getURL\(.{1,2}\)/, + match: /(if\(null!=\i\))return \i\.default\.getURL\(\i\)/, replace: "$1return null", }, }, From 86a9a68ecaff2a4658bb28411262fd6d195d929f Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Fri, 22 Dec 2023 19:34:16 +0100 Subject: [PATCH 04/11] Match by partial class name in emoji container selector --- src/plugins/textEmoji/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/textEmoji/styles.css b/src/plugins/textEmoji/styles.css index f08a7e9bf..19818b878 100644 --- a/src/plugins/textEmoji/styles.css +++ b/src/plugins/textEmoji/styles.css @@ -1,3 +1,3 @@ -.reaction_fef95b .emoji { +[class^="reaction_"] .emoji { white-space: nowrap; } From d0e1791e6b10475cc312eab3a24bd6d6610cda8b Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Sun, 24 Dec 2023 13:15:33 +0100 Subject: [PATCH 05/11] Revert "Match by partial class name in emoji container selector" This reverts commit 86a9a68ecaff2a4658bb28411262fd6d195d929f. After thinking more about it, partial matching seems like a very bad idea. --- src/plugins/textEmoji/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/textEmoji/styles.css b/src/plugins/textEmoji/styles.css index 19818b878..f08a7e9bf 100644 --- a/src/plugins/textEmoji/styles.css +++ b/src/plugins/textEmoji/styles.css @@ -1,3 +1,3 @@ -[class^="reaction_"] .emoji { +.reaction_fef95b .emoji { white-space: nowrap; } From b692a6dd95c3639a2661ec6f539a17e98051ad19 Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Fri, 22 Dec 2023 19:34:16 +0100 Subject: [PATCH 06/11] Match by partial class name in emoji container selector --- src/plugins/textEmoji/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/textEmoji/styles.css b/src/plugins/textEmoji/styles.css index f08a7e9bf..19818b878 100644 --- a/src/plugins/textEmoji/styles.css +++ b/src/plugins/textEmoji/styles.css @@ -1,3 +1,3 @@ -.reaction_fef95b .emoji { +[class^="reaction_"] .emoji { white-space: nowrap; } From 86162b301a7d9704925c7d45f1f7c807754c8c30 Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Wed, 7 Feb 2024 00:25:25 +0100 Subject: [PATCH 07/11] Keep if statement after replacing --- src/plugins/textEmoji/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/textEmoji/index.ts b/src/plugins/textEmoji/index.ts index e022e9a4b..bfc5fc094 100644 --- a/src/plugins/textEmoji/index.ts +++ b/src/plugins/textEmoji/index.ts @@ -37,7 +37,7 @@ export default definePlugin({ find: ",findInlineEmojisFromSurrogates:", replacement: { match: /if\(!0!==.{1,2}&&!.{1,2}\.test\(.{1,2}\)\)/, - replace: "", + replace: "if(true)", }, }, ], From 54c9564894b8442ddbba9ec4e49f5ab5456e03ab Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Wed, 7 Feb 2024 00:26:20 +0100 Subject: [PATCH 08/11] Add comments to patches --- src/plugins/textEmoji/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/textEmoji/index.ts b/src/plugins/textEmoji/index.ts index bfc5fc094..503189ad7 100644 --- a/src/plugins/textEmoji/index.ts +++ b/src/plugins/textEmoji/index.ts @@ -26,6 +26,7 @@ export default definePlugin({ description: "Prevents Discord from replacing emoji with images, leaving it up to the browser to render them", authors: [Devs.Grzesiek11], patches: [ + // Reactions { find: "getSrc(){", replacement: { @@ -33,6 +34,7 @@ export default definePlugin({ replace: "$1return null", }, }, + // Messages { find: ",findInlineEmojisFromSurrogates:", replacement: { From b44513817c67deb658882ca2614efd09697a551b Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Wed, 7 Feb 2024 00:27:07 +0100 Subject: [PATCH 09/11] Use \i in second patch --- src/plugins/textEmoji/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/textEmoji/index.ts b/src/plugins/textEmoji/index.ts index 503189ad7..025064ea7 100644 --- a/src/plugins/textEmoji/index.ts +++ b/src/plugins/textEmoji/index.ts @@ -38,7 +38,7 @@ export default definePlugin({ { find: ",findInlineEmojisFromSurrogates:", replacement: { - match: /if\(!0!==.{1,2}&&!.{1,2}\.test\(.{1,2}\)\)/, + match: /if\(!0!==\i&&!\i\.test\(\i\)\)/, replace: "if(true)", }, }, From f6764a2a39f04a55aa002de4a093ae070769cf09 Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Mon, 24 Jun 2024 03:13:54 +0200 Subject: [PATCH 10/11] Fix on latest client version --- src/plugins/textEmoji/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/textEmoji/index.ts b/src/plugins/textEmoji/index.ts index 025064ea7..7ad4b9bd6 100644 --- a/src/plugins/textEmoji/index.ts +++ b/src/plugins/textEmoji/index.ts @@ -30,7 +30,7 @@ export default definePlugin({ { find: "getSrc(){", replacement: { - match: /(if\(null!=\i\))return \i\.default\.getURL\(\i\)/, + match: /(if\(null!=\i\))return \i\.\i\.getURL\(\i\)/, replace: "$1return null", }, }, From f38de5cd6bf0d86e55016b84815838c5ca554e65 Mon Sep 17 00:00:00 2001 From: Grzesiek11 Date: Tue, 25 Jun 2024 01:33:14 +0200 Subject: [PATCH 11/11] Add README --- src/plugins/textEmoji/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/plugins/textEmoji/README.md diff --git a/src/plugins/textEmoji/README.md b/src/plugins/textEmoji/README.md new file mode 100644 index 000000000..8850d0aba --- /dev/null +++ b/src/plugins/textEmoji/README.md @@ -0,0 +1,9 @@ +# TextEmoji + +Prevents Discord from replacing emoji with images, leaving it up to the browser +to render them + +![Chat with TextEmoji enabled, using the Noto Color Emoji font](https://github.com/Vendicated/Vencord/assets/33988779/464ec526-8ef7-4961-941f-a2a05642b0f7) + +Allows your browser to render emoji as regular text, using the system font, such +as Noto Color Emoji or Segoe UI Emoji.