diff --git a/src/assets/indicator.tsx b/src/assets/indicator.tsx new file mode 100644 index 0000000..296e041 --- /dev/null +++ b/src/assets/indicator.tsx @@ -0,0 +1,6 @@ +import React from "react"; + +export const Indicator = React.createElement("img", { + src: "https://cdn-icons-png.flaticon.com/32/3064/3064130.png", + width: "20", +}); diff --git a/src/components/EncryptionModal.tsx b/src/components/EncryptionModal.tsx index b5caf95..c8f4c83 100644 --- a/src/components/EncryptionModal.tsx +++ b/src/components/EncryptionModal.tsx @@ -71,7 +71,9 @@ export function buildEncModal() { webpack.common.messages.sendMessage( webpack.common.channels.getCurrentlySelectedChannelId(), - { content: toSend }, + // Adds an indicator (\u200b) + // eslint-disable-next-line no-irregular-whitespace + { content: `${toSend}​` }, ); // @ts-ignore closeModal(s); diff --git a/src/index.ts b/src/index.ts index c75c816..a115b31 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,11 @@ import { Injector, OutgoingMessage, webpack } from "replugged"; -import StegCloak from "./lib/stegcloak.js"; import { popoverIcon } from "./assets/popoverIcon"; import { chatbarLock } from "./assets/chatbarLock"; +import { Indicator } from "./assets/indicator"; import { buildDecModal } from "./components/DecryptionModal"; +import StegCloak from "./lib/stegcloak.js"; const inject = new Injector(); const steggo: StegCloak = new StegCloak(true, false); @@ -35,6 +36,7 @@ export async function start(): Promise { INV_DETECTION, receiver, chatbarLock, + Indicator, }; } @@ -48,31 +50,25 @@ export function runPlaintextPatches(): void { /.\?(..)\(\{key:"reply",label:.{1,40},icon:.{1,40},channel:(.{1,3}),message:(.{1,3}),onClick:.{1,5}\}\):null/gm, replace: `$&,$3.content.match(window.invisiblechat.INV_DETECTION)?$1({key:"decrypt",label:"Decrypt Message",icon:window.invisiblechat.popoverIcon,channel:$2,message:$3,onClick:()=>window.invisiblechat.receiver($3)}):null`, }, - { - // Detection Lock - // TODO: Find a better way that doesnt need hovering over the message - match: /var .=(.)\.channel,.=.\.message,.=.\.expanded,.=.\.canCopy/gm, - replace: `window.invisiblechat.receiver($1.message, $1.canPin);$&`, - }, { // Chatbar Lock match: /.=.\.activeCommand,.=.\.activeCommandOption,(.)=\[\];/, replace: "$&;$1.push(window.invisiblechat.chatbarLock);", }, + { + // Message Indicator + match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/, + replace: + "try{$1?.content[0].match(window.invisiblechat.INV_DETECTION)?$1?.content.push(window.invisiblechat.Indicator):null}catch(e){};$&", + }, ], }, ]); } // Grab the data from the above Plantext Patches -function receiver(message: IncomingMessage, canPin: boolean | undefined): void { - if (typeof canPin !== "undefined") { - if (message.content.match(INV_DETECTION) && !message.content.includes("🔒")) { - message.content = `🔒${message.content}🔒`; - } - } else { - buildDecModal(message); - } +function receiver(message: IncomingMessage): void { + buildDecModal(message); } // Gets the Embed of a Link @@ -133,6 +129,7 @@ export function encrypt(secret: string, password: string, cover: string): string } export function decrypt(secret: string, password: string): string { + // Remove the Indicator when revealing // eslint-disable-next-line no-irregular-whitespace return steggo.reveal(secret, password).replace("​", ""); } diff --git a/src/updater.ts b/src/updater.ts new file mode 100644 index 0000000..54d42e9 --- /dev/null +++ b/src/updater.ts @@ -0,0 +1,56 @@ +import { createWriteStream } from "fs"; +import { get } from "https"; +import { plugins } from "replugged"; +import { CONFIG_PATHS } from "replugged/dist/util"; +import { join } from "path"; + +const GITAPI_LINK = "https://api.github.com/repos/SammCheese/invisible-chat/releases/latest"; +const FILENAME = "dev.sammcheese.InvisibleChat.asar"; + +async function fetchGithub(): Promise { + return new Promise((resolve, reject) => { + fetch(GITAPI_LINK) + .then((resp) => resolve(resp.json())) + .catch((rej) => { + console.log(rej); + reject(rej); + }); + }); +} + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +const downloadFile = (url: string, path: string) => { + const file = createWriteStream(path); + get(url, (res) => { + res.pipe(file); + + file.on("finish", () => { + file.close(); + }); + }); +}; + +export async function checkUpdate(): Promise { + const gitResult = await fetchGithub(); + // @ts-expect-error response type not declared + const localVersion = await plugins.get("dev.sammcheese.InvisibleChat")?.manifest?.version; + + // @ts-expect-error type not declared + if (isNewAvailable(localVersion, gitResult.tag_name)) { + // @ts-expect-error type not declared + downloadFile(gitResult.assets.browser_download_url, join(CONFIG_PATHS.plugins, FILENAME)); + /*rename(join(CONFIG_PATHS.plugins, FILENAME), `${FILENAME}.update`, (e) => { + // @ts-expect-error type not declared + if (e) unlinkSync(file); + });*/ + } +} + +function isNewAvailable(localVersion: string, remoteVersion: string): boolean { + if (!localVersion || !remoteVersion) return false; + + localVersion.replaceAll(".", "").replace("v", ""); + remoteVersion.replaceAll(".", "").replace("v", ""); + + return parseInt(remoteVersion, 10) > parseInt(localVersion, 10); +} diff --git a/tsconfig.json b/tsconfig.json index 94250ff..bba99e4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ "jsx": "react" /* Specify what JSX code is generated. */, // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */