diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1eae0cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist/ +node_modules/ diff --git a/plugins/removeChannelEmojis/Settings.tsx b/plugins/removeChannelEmojis/Settings.tsx new file mode 100644 index 0000000..7f26de3 --- /dev/null +++ b/plugins/removeChannelEmojis/Settings.tsx @@ -0,0 +1,26 @@ +import { components, settings, util } from "replugged"; +const { SwitchItem, FormNotice } = components; + +interface Settings { + unicode?: boolean; +} + +export const pSettings = await settings.init("dev.alyxia.removeChannelEmojis"); + +export function Settings(): React.ReactElement { + return ( + <> + + + Remove Unicode emojis + + + ); +} diff --git a/plugins/removeChannelEmojis/index.ts b/plugins/removeChannelEmojis/index.ts new file mode 100644 index 0000000..842e72b --- /dev/null +++ b/plugins/removeChannelEmojis/index.ts @@ -0,0 +1,18 @@ +export { Settings } from "./Settings"; + +interface IChannel { + name: string; +} +export function transformName(channel: IChannel): IChannel { + if (channel != null) + if (channel.name) { + channel.name = channel.name + .replace( + /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, + "", + ) + .replace(/\s+/g, " ") + .trim(); + } + return channel; +} diff --git a/plugins/removeChannelEmojis/manifest.json b/plugins/removeChannelEmojis/manifest.json index e84bd4f..d0ecad8 100644 --- a/plugins/removeChannelEmojis/manifest.json +++ b/plugins/removeChannelEmojis/manifest.json @@ -7,12 +7,13 @@ "discordID": "952185386350829688", "github": "lexisother" }, - "version": "1.1.1", + "version": "1.2.0", "updater": { "type": "store", "id": "dev.alyxia.removeChannelEmojis" }, "license": "Apache-2.0", "type": "replugged-plugin", + "renderer": "index.ts", "plaintextPatches": "plaintextPatches.ts" } diff --git a/plugins/removeChannelEmojis/plaintextPatches.ts b/plugins/removeChannelEmojis/plaintextPatches.ts index 92b8943..cd9f2cb 100644 --- a/plugins/removeChannelEmojis/plaintextPatches.ts +++ b/plugins/removeChannelEmojis/plaintextPatches.ts @@ -1,4 +1,8 @@ import { PlaintextPatch } from "replugged/dist/types"; +import { pSettings } from "./Settings"; + +const __a_require = (e: string): string => + `window.replugged.plugins.getExports("dev.alyxia.removeChannelEmojis").${e}`; export default [ { @@ -10,4 +14,19 @@ export default [ }, ], }, + ...(pSettings.get("unicode") + ? ([ + { + find: /.{1,2}.displayName="ChannelStore";/, + replacements: [ + { + match: + /([^;]{1,2}\.getChannel=function\([^)]*\)\{)if\(null!=(.{1,2})\)return ([^(]{1,2})\(.{1,2}\)/, + replace: (_, def, channelId, func) => + `${def}if(null!=e)return ${__a_require("transformName")}(${func}(${channelId}))`, + }, + ], + }, + ] as PlaintextPatch[]) // required typehint due to conditional + : []), ] as PlaintextPatch[]; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 57987cb..575ea29 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,8 @@ -lockfileVersion: '6.0' +lockfileVersion: '6.1' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false dependencies: deepmerge: