├── .editorconfig
├── .gitattributes
├── .gitignore
├── .yarn
└── releases
│ └── yarn-4.7.0.cjs
├── .yarnrc.yml
├── LICENSE
├── README.md
├── build
└── build-patch.cts
├── encryption.plugin.js
├── package.json
├── rollup.config.js
├── src
├── index.ts
├── lib
│ ├── components
│ │ ├── encryptionButton.ts
│ │ ├── encryptionInput.ts
│ │ ├── index.ts
│ │ └── updatePanel.ts
│ ├── config.ts
│ ├── crypto.ts
│ ├── helpers.ts
│ ├── index.ts
│ ├── log.ts
│ ├── storage.ts
│ └── styles.ts
└── types
│ └── index.d.ts
├── tsconfig.json
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | end_of_line = lf
5 | insert_final_newline = true
6 |
7 | [*.{js,json,yml}]
8 | charset = utf-8
9 | indent_style = space
10 | indent_size = 2
11 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | /.yarn/** linguist-vendored
2 | /.yarn/releases/* binary
3 | /.yarn/plugins/**/* binary
4 | /.pnp.* binary linguist-generated
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 | .env.local
3 |
4 | .yarn/*
5 | !.yarn/patches
6 | !.yarn/plugins
7 | !.yarn/releases
8 | !.yarn/sdks
9 | !.yarn/versions
10 |
11 | node_modules/
12 | npm-debug.log
13 | yarn-error.log
14 |
15 | !encryption.plugin.js
16 |
--------------------------------------------------------------------------------
/.yarnrc.yml:
--------------------------------------------------------------------------------
1 | compressionLevel: mixed
2 |
3 | enableGlobalCache: false
4 |
5 | nodeLinker: node-modules
6 |
7 | yarnPath: .yarn/releases/yarn-4.7.0.cjs
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2020 Harry Merritt
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Discord Encryption
2 |
3 | > We're back baby :)
4 |
5 | An experimental encryption solution for Discord using [BetterDiscord](https://github.com/rauenzi/BetterDiscordApp/releases).
6 |
7 | Download the `encryption.plugin.js` from the releases [here](https://github.com/hmerritt/discord-encryption/releases/latest).
8 |
9 | ## Features
10 |
11 | Adds ability to encrypt / decrypt messages on discord using a set password
12 |
13 | - Utilizes AES-256 encryption via the [crypto-js library](https://www.npmjs.com/package/crypto-js)
14 | - Passwords are saved per-chat
15 | - Messages are decrypted the moment they are receved with little to no delay
16 | - Encrypted messages appear as green
17 | - Messages that fail to be decrypted (most likely due to an incorrect password) display a message and appear as red
18 |
19 | 
20 | 
21 |
22 | ## How to use
23 |
24 | ### Install
25 |
26 | - Install Discord
27 | - Install BetterDiscord
28 | - Navigate to Discord Preferences -> BD/Plugins -> Open Plugin Folder
29 | - Place 'encryption.plugin.js' in BetterDiscord's plugin folder
30 | - Enable encryption in the BD/Plugins preference pane.
31 |
32 | > It may ask to install an additional plugin `0PluginLibrary.plugin` which is required - It should install itself if you click `download`.
33 |
34 | 
35 | 
36 |
37 | ### Usage
38 |
39 | - To toggle the encryption simply click the lock icon. You will be prompted for a password, if none is found for the chat channel.
40 | - Received messages are decrypted automatically
41 | - To view or change the encryption password simply right-click the lock icon and an input box will appear - passwords are automatically saved as you type
42 |
43 | 
44 |
45 | ### Encrypted Message
46 |
47 | 
48 |
49 | ### Decrypted Message
50 |
51 | 
52 |
53 | ## Development
54 |
55 | This plugin uses [`rollup`](https://rollupjs.org/) to bundle what's in `src` into the final `encryption.plugin.js` script.
56 |
57 | Getting `rollup` to work with `BetterDiscord` was a **gamechanger** as it allows the plugin to use multiple src files instead of just one. This makes development much nicer.
58 |
59 | How to build Build:
60 |
61 | ```
62 | $ yarn && yarn build
63 | ```
64 |
65 | > This runs both `rollup`, and a `build-patch` script to add the required `BetterDiscord` META tags.
66 |
--------------------------------------------------------------------------------
/build/build-patch.cts:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 | const os = require('os');
3 | const pathfs = require('path');
4 | const prependFile = require('prepend-file');
5 | const { config } = require('../src/lib/config');
6 |
7 | const isDev = process.argv?.[2] === 'dev';
8 | const pluginOutputFile = pathfs.join(__dirname, '../', 'encryption.plugin.js');
9 | const betterDiscordPluginDir = `C:/Users/${os.userInfo().username}/AppData/Roaming/BetterDiscord/plugins`;
10 |
11 | const main = async () => {
12 | console.log(`> Patching build`);
13 |
14 | console.log(`> Adding META data to plugin output file`);
15 | await prependFile(pluginOutputFile, `/**
16 | * @name ${config.nameTitle}
17 | * @version ${config.version.current}
18 | * @description ${config.description}
19 | * @author ${config.author.github_username}
20 | * @website ${config.link.repository}
21 | * @source ${config.link.source}
22 | * @updateUrl ${config.link.source}
23 | */
24 | `);
25 |
26 | if (isDev) {
27 | console.log(`> Copy output file to betterDiscord plugin directory`);
28 | fs.copyFileSync(pluginOutputFile, `${betterDiscordPluginDir}/encryption.plugin.js`);
29 | }
30 |
31 | console.log('> Patching complete :)');
32 | };
33 |
34 | (async () => {
35 | await main();
36 | process.exit();
37 | })();
38 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "discord-encryption",
3 | "version": "2.1.0",
4 | "type": "module",
5 | "description": "An experimental encryption solution for Discord",
6 | "scripts": {
7 | "build": "rollup -c && tsx ./build/build-patch.cts",
8 | "build:dev": "rollup -c && tsx ./build/build-patch.cts dev",
9 | "update": "yarn upgrade-interactive"
10 | },
11 | "dependencies": {
12 | "crypto-js": "^4.2.0",
13 | "dayjs": "^1.11.13",
14 | "jquery": "^3.7.1"
15 | },
16 | "devDependencies": {
17 | "@rollup/plugin-commonjs": "^28.0.3",
18 | "@rollup/plugin-node-resolve": "^16.0.1",
19 | "@rollup/plugin-typescript": "^12.1.2",
20 | "@types/crypto-js": "^4.2.2",
21 | "@types/node": "^20.17.24",
22 | "prepend-file": "^2.0.1",
23 | "rollup": "^4.35.0",
24 | "tslib": "^2.8.1",
25 | "tsx": "^4.19.3",
26 | "typescript": "^5.8.2"
27 | },
28 | "repository": {
29 | "type": "git",
30 | "url": "https://github.com/hmerritt/discord-encryption.git"
31 | },
32 | "packageManager": "yarn@4.7.0"
33 | }
34 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | // @ts-nocheck
2 | import commonjs from '@rollup/plugin-commonjs';
3 | import resolve from '@rollup/plugin-node-resolve';
4 | import typescript from '@rollup/plugin-typescript';
5 |
6 | // https://rollupjs.org/introduction/
7 | export default {
8 | input: 'src/index.ts',
9 | output: {
10 | file: 'encryption.plugin.js',
11 | format: 'cjs', // cjs | es
12 | sourcemap: false
13 | },
14 | plugins: [
15 | typescript(),
16 | resolve(),
17 | commonjs(),
18 | ],
19 | define: {
20 | "process.env": {},
21 | },
22 | };
23 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | import {
2 | config,
3 | Config,
4 | Dummy,
5 | decryptAllMessages,
6 | downloadRequiredLibraryIfMissing,
7 | encrypt,
8 | getChannelId,
9 | getOrCreateUserData,
10 | getUserData,
11 | inject,
12 | injectLog,
13 | isEncryptionOn,
14 | isMessageEncrypted,
15 | log,
16 | PREFIX,
17 | removeElements,
18 | styles,
19 | } from "lib";
20 |
21 | import { encryptionButton, encryptionInput, updatePanel } from "lib/components";
22 |
23 | downloadRequiredLibraryIfMissing();
24 |
25 | export default !window.ZeresPluginLibrary
26 | ? Dummy
27 | : (([Plugin, Api]) => {
28 | const plugin = (Plugin, Api) => {
29 | const {
30 | DiscordClasses,
31 | DiscordModules,
32 | DOMTools,
33 | Patcher,
34 | ReactTools,
35 | Utilities,
36 | WebpackModules,
37 | } = Api;
38 |
39 | return class Encryption extends Plugin {
40 | script: Config;
41 | components: any;
42 |
43 | /*
44 | * Define global variables
45 | */
46 | constructor() {
47 | super();
48 | injectLog();
49 |
50 | // Script metadata
51 | this.script = { ...config };
52 |
53 | // Stores component data
54 | this.components = {};
55 | }
56 |
57 | /*
58 | * Runs once on plugin load (before start)
59 | */
60 | load() {
61 | injectLog();
62 |
63 | // Initialize DOM components
64 | this.initializeComponents();
65 |
66 | // Check for new version
67 | this.checkForUpdate();
68 | }
69 |
70 | /*
71 | * Runs each time plugin starts (after load on initial start)
72 | */
73 | start() {
74 | // Inject styles
75 | inject("styles", "head", "append", this.components.styles);
76 |
77 | this.bootstrapUi();
78 |
79 | Patcher.before(
80 | DiscordModules.MessageActions,
81 | "sendMessage",
82 | (t, a) => {
83 | let message = a[1].content;
84 |
85 | if (
86 | isEncryptionOn(getUserData(), getChannelId()) &&
87 | !isMessageEncrypted(message) &&
88 | message.length > 0
89 | ) {
90 | const enc =
91 | PREFIX +
92 | encrypt(
93 | message,
94 | getOrCreateUserData(getUserData(), getChannelId())
95 | );
96 |
97 | a[1].content = enc;
98 | }
99 | }
100 | );
101 |
102 | Patcher.after(
103 | DiscordModules.MessageActions,
104 | "receiveMessage",
105 | function () {
106 | this.bootstrapUi();
107 |
108 | setTimeout(
109 | function () {
110 | this.bootstrapUi();
111 | }.bind(this),
112 | 1000
113 | );
114 | }.bind(this)
115 | );
116 | }
117 |
118 | /*
119 | * Runs when plugin has been stopped
120 | */
121 | stop() {
122 | // Remove all elements that have been injected
123 | removeElements(`[${this.script.name}]`);
124 | }
125 |
126 | /**
127 | * Runs after every channel switch
128 | */
129 | onSwitch() {
130 | this.bootstrapUi();
131 |
132 | setTimeout(
133 | function () {
134 | this.bootstrapUi();
135 | }.bind(this),
136 | 1000
137 | );
138 | }
139 |
140 | //--------------------------------------------------------------------
141 | //--------------------------------------------------------------------
142 |
143 | initializeComponents() {
144 | /*
145 | * CSS
146 | */
147 | this.components.styles = `
150 | `;
151 |
152 | /*
153 | * Register components
154 | */
155 | this.components.updatePanel = updatePanel(
156 | this.script,
157 | getUserData()
158 | );
159 | this.components.encryptionButton = encryptionButton(
160 | this.script,
161 | getUserData()
162 | );
163 | this.components.encryptionInput = encryptionInput(
164 | this.script,
165 | getUserData()
166 | );
167 | }
168 |
169 | bootstrapUi() {
170 | /*
171 | * Inject UI elements. Decode messages.
172 | */
173 | this.components.encryptionInput.toggleInput("hide");
174 |
175 | const channelId = getChannelId() || "global";
176 | const channelState = getOrCreateUserData(getUserData(), channelId);
177 |
178 | this.components.encryptionButton.inject();
179 | channelState.state && decryptAllMessages(channelState);
180 | }
181 |
182 | //--------------------------------------------------------------------
183 | //--------------------------------------------------------------------
184 |
185 | /*
186 | * Checks GitHub for a newer version of the script
187 | */
188 | async checkForUpdate() {
189 | // Skip checking if user has previously chosen to ignore the update
190 | if (this.script.version.ignoreUpdate) return;
191 | log("Checking for updates...");
192 |
193 | try {
194 | // Get latest script from GitHub
195 | const res = await (
196 | await fetch(this.script.link.sourceConfig)
197 | ).text();
198 |
199 | // Extract latest version from script
200 | const latestMatch = res.match(/(\d.\d.\d)/);
201 | const latest = latestMatch == null ? "" : latestMatch[0];
202 |
203 | // Update global var with latest version
204 | this.script.version.latest = latest;
205 |
206 | // Make script versions a number (remove '.')
207 | const currentVersion = this.script.version.current.replace(
208 | /\./g,
209 | ""
210 | );
211 | const latestVersion = latest.replace(/\./g, "");
212 |
213 | // Compare current and latest version
214 | if (currentVersion < latestVersion) {
215 | // Update is available
216 | this.script.version.update = true;
217 | log(
218 | `An update is available! [${currentVersion} => ${latestVersion}]`
219 | );
220 |
221 | // add update pop-up to ui
222 | this.components.updatePanel.inject();
223 | }
224 | } catch (err) {
225 | log("error", `Error checking for updates: ${err}`);
226 | }
227 | }
228 | };
229 | };
230 |
231 | return plugin(Plugin, Api);
232 | })(
233 | window.ZeresPluginLibrary.buildPlugin({
234 | info: {
235 | name: config.nameTitle,
236 | authors: [config.author],
237 | version: config.version.current,
238 | description: config.description,
239 | github: config.link.repository,
240 | github_raw: config.link.source,
241 | },
242 | main: "index.js",
243 | })
244 | );
245 |
--------------------------------------------------------------------------------
/src/lib/components/encryptionButton.ts:
--------------------------------------------------------------------------------
1 | import $ from "jquery";
2 |
3 | import {
4 | checkInputPassword,
5 | getEncryptionPassword,
6 | isEncryptionOn,
7 | saveUserData,
8 | } from "../storage";
9 | import { fade, getChannelId, getOrCreateUserData, inject } from "../helpers";
10 | import { Config, UserData } from "../config";
11 | import { encryptionInput } from "./encryptionInput";
12 |
13 | /**
14 | * Encryption button
15 | */
16 |
17 | const componentName = "encryptionButton";
18 |
19 | const html = (script: Config, userData: UserData) => {
20 | const $button = document.createElement("button");
21 | $button.setAttribute(script.name, componentName);
22 | $button.setAttribute("state", `${isEncryptionOn(userData) ?? false}`);
23 | $button.setAttribute("class", componentName);
24 |
25 | $button.innerHTML = `
26 |
29 | `;
30 |
31 | $button.onclick = (evt: any) => {
32 | toggleState(script, userData);
33 | $(`[role="textbox"]`).focus();
34 | };
35 |
36 | // bind right click to adding encryption input
37 | $button.oncontextmenu = (evt: any) => {
38 | evt.preventDefault();
39 | encryptionInput(script, userData).toggleInput("");
40 | $("#encryptionInput input").val(getEncryptionPassword(userData));
41 | checkInputPassword();
42 | };
43 |
44 | return $button;
45 | };
46 |
47 | const close = (script: Config, userData: UserData, delay = 0) => {
48 | script.version.ignoreUpdate = true;
49 | fade(`[${script.name}].${componentName}`, "out", delay);
50 | };
51 |
52 | const toggleState = (script: Config, userData: UserData) => {
53 | const $button = $(`[${script.name}].${componentName}`);
54 | const channelId = getChannelId() || "global";
55 | getOrCreateUserData(userData, channelId);
56 |
57 | if (isEncryptionOn(userData, channelId)) {
58 | $button.attr("state", "false");
59 | userData[channelId].state = false;
60 | } else {
61 | $button.attr("state", "true");
62 | userData[channelId].state = true;
63 | }
64 |
65 | saveUserData(userData);
66 | };
67 |
68 | export const encryptionButton = (script: Config, userData: UserData) => ({
69 | html: () => html(script, userData),
70 | close: (delay = 0) => close(script, userData, delay),
71 | inject: () =>
72 | inject(
73 | componentName,
74 | `[class^=attachWrapper] > button`,
75 | "after",
76 | html(script, userData)
77 | ),
78 | //
79 | toggleState: () => toggleState(script, userData),
80 | });
81 |
--------------------------------------------------------------------------------
/src/lib/components/encryptionInput.ts:
--------------------------------------------------------------------------------
1 | import $ from "jquery";
2 |
3 | import { log } from "../log";
4 | import { Config, UserData } from "../config";
5 | import { getChannelId, fade, inject, getOrCreateUserData } from "../helpers";
6 | import { checkInputPassword, saveUserData } from "../storage";
7 |
8 | /**
9 | * Encryption input
10 | */
11 |
12 | const componentName = "encryptionInput";
13 |
14 | const html = (script: Config, userData: UserData) => {
15 | const $div = document.createElement("div");
16 | $div.setAttribute("id", componentName);
17 | $div.setAttribute(script.name, componentName);
18 | $div.setAttribute("class", `${componentName} animated fadeInUp`);
19 |
20 | $div.innerHTML = `
21 |
24 |
25 | `;
26 |
27 | // Change password on typing.
28 | $div.onkeyup = (evt: any) => {
29 | // set password and save in storage
30 | checkInputPassword();
31 | const channelId = getChannelId() || "global";
32 | getOrCreateUserData(userData, channelId);
33 | userData[channelId].password = evt.target.value;
34 | saveUserData(userData);
35 | };
36 |
37 | // Toggle between **** and text for the password
38 | $div.querySelector("svg").onclick = (evt: any) => {
39 | evt.preventDefault();
40 | if ($("#encryptionInput input").attr("type") == "password") {
41 | $("#encryptionInput input").attr("type", "text");
42 | $("#encryptionInput svg path").attr(
43 | "d",
44 | "M11.83,9L15,12.16C15,12.11 15,12.05 15,12A3,3 0 0,0 12,9C11.94,9 11.89,9 11.83,9M7.53,9.8L9.08,11.35C9.03,11.56 9,11.77 9,12A3,3 0 0,0 12,15C12.22,15 12.44,14.97 12.65,14.92L14.2,16.47C13.53,16.8 12.79,17 12,17A5,5 0 0,1 7,12C7,11.21 7.2,10.47 7.53,9.8M2,4.27L4.28,6.55L4.73,7C3.08,8.3 1.78,10 1,12C2.73,16.39 7,19.5 12,19.5C13.55,19.5 15.03,19.2 16.38,18.66L16.81,19.08L19.73,22L21,20.73L3.27,3M12,7A5,5 0 0,1 17,12C17,12.64 16.87,13.26 16.64,13.82L19.57,16.75C21.07,15.5 22.27,13.86 23,12C21.27,7.61 17,4.5 12,4.5C10.6,4.5 9.26,4.75 8,5.2L10.17,7.35C10.74,7.13 11.35,7 12,7Z"
45 | );
46 | } else {
47 | $("#encryptionInput input").attr("type", "password");
48 | $("#encryptionInput svg path").attr(
49 | "d",
50 | "M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z"
51 | );
52 | }
53 | };
54 |
55 | return $div;
56 | };
57 |
58 | const close = (script: Config, userData: UserData, delay = 0) => {
59 | script.version.ignoreUpdate = true;
60 | fade(`[${script.name}].${componentName}`, "out", delay);
61 | };
62 |
63 | const toggleInput = (script: Config, userData: UserData, action = "") => {
64 | if (action == "show" || (action == "" && $("#encryptionInput").length == 0)) {
65 | inject(componentName, `form`, "before", html(script, userData));
66 | } else {
67 | $("#encryptionInput").removeClass("fadeInUp").addClass("fadeOutDown");
68 | setTimeout(function () {
69 | $("#encryptionInput").remove();
70 | }, 288);
71 | }
72 | };
73 |
74 | export const encryptionInput = (script: Config, userData: UserData) => ({
75 | html: () => html(script, userData),
76 | close: (delay = 0) => close(script, userData, delay),
77 | inject: () => inject(componentName, "form", "before", html(script, userData)),
78 | //
79 | toggleInput: (action = "") => toggleInput(script, userData, action),
80 | });
81 |
--------------------------------------------------------------------------------
/src/lib/components/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./encryptionButton";
2 | export * from "./encryptionInput";
3 | export * from "./updatePanel";
4 |
--------------------------------------------------------------------------------
/src/lib/components/updatePanel.ts:
--------------------------------------------------------------------------------
1 | import { Config, UserData } from "../config";
2 | import { fade, inject } from "../helpers";
3 |
4 | /**
5 | * Update panel. Displays when an update is available.
6 | */
7 |
8 | const componentName = "updatePanel";
9 |
10 | const html = (script: Config, userData: UserData) => {
11 | const $div = document.createElement("div");
12 | $div.setAttribute(script.name, componentName);
13 | $div.setAttribute("class", `${componentName} animated fadeInUp`);
14 |
15 | $div.innerHTML = `
16 |
An update is available for the discord encryption plugin!