From d07df339546ec9cbdf97be8d43078fdb13b25c44 Mon Sep 17 00:00:00 2001 From: Mostafa Kheibary Date: Fri, 12 Apr 2024 21:21:05 +0330 Subject: [PATCH] :recycle: refactor the device detection system for event and selector, fix the bug for submit button --- docs/getting-started/installation.md | 2 +- manifest.json | 2 +- package.json | 2 +- src/components/modules/content/Actions.svelte | 20 ++-- src/components/modules/popup/Settings.svelte | 2 +- src/config/index.ts | 112 ++++++++---------- src/content/index.ts | 19 +-- src/content/scripts/listeners.ts | 93 +++++++-------- src/content/scripts/messageParser.ts | 6 +- src/hooks/useConfig.ts | 37 ++++++ src/hooks/useRender.ts | 4 +- src/types/Config.d.ts | 22 ++-- src/utils/elementVisibility.ts | 10 ++ src/utils/index.ts | 41 ------- src/utils/logSelectors.ts | 8 -- src/utils/userAction.ts | 9 +- 16 files changed, 191 insertions(+), 198 deletions(-) create mode 100644 src/hooks/useConfig.ts create mode 100644 src/utils/elementVisibility.ts delete mode 100644 src/utils/logSelectors.ts diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md index 3cc630d..8535842 100644 --- a/docs/getting-started/installation.md +++ b/docs/getting-started/installation.md @@ -36,7 +36,7 @@ Welcome to Chat Guard for. This guide will walk you through the steps to downloa ### Sideload Extension (Using the Extension File) -1. Download the extension file (usually a .zip or .crx file) from [download page](https://github.com/PrivacyForge/ChatGuard/releases/tag/v0.9.2-beta). +1. Download the extension file (usually a .zip or .crx file) from [download page](https://github.com/PrivacyForge/ChatGuard/releases/tag/v0.9.3-beta). 2. Open Chrome and go to `chrome://extensions/`. diff --git a/manifest.json b/manifest.json index ff4d5d1..6606324 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "ChatGuard-beta", "description": "Browser Add on that allow (End to End) encrypted in web chat messenger", - "version": "0.9.2", + "version": "0.9.3", "author": "https://github.com/mostafa-kheibary", "icons": { "16": "src/assets/icons/icon16.png", diff --git a/package.json b/package.json index dbf7794..9f34687 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "email": "mostafa.kheibary@gmail.com", "url": "https://github.com/mostafa-kheibary" }, - "version": "0.9.2", + "version": "0.9.3", "type": "module", "scripts": { "dev": "vite", diff --git a/src/components/modules/content/Actions.svelte b/src/components/modules/content/Actions.svelte index d13d1c8..69a9daa 100644 --- a/src/components/modules/content/Actions.svelte +++ b/src/components/modules/content/Actions.svelte @@ -4,14 +4,14 @@ import { clickTo, typeTo } from "src/utils/userAction"; import { url } from "src/store/url.store"; import { chatStore as state } from "src/store/chat.store"; - import type { Contact, Field } from "src/types/Config"; + import type { Contact } from "src/types/Config"; import type Cipher from "src/class/Cipher"; import { config } from "src/config"; import { wait } from "src/utils/wait"; import Lock from "src/components/icon/Lock.svelte"; + import { useConfig } from "src/hooks/useConfig"; export let cipher: Cipher; - export let selector: Field; export let id: string; let status: "safe" | "unsafe" = "unsafe"; @@ -21,6 +21,7 @@ let intervalId: any | null = null; $: !$state.loading && clearInterval(intervalId); + const { getSelector } = useConfig(); const checkStatus = () => { const contact = LocalStorage.getMap(config.CONTACTS_STORAGE_KEY, $url.id); @@ -48,18 +49,17 @@ }); const handleSendHandshake = async (e: MouseEvent) => { - let textFiled = document.querySelector(selector.textField) as HTMLElement; + let textFiled = document.querySelector(getSelector("textField")) as HTMLElement; textFiled.focus(); if ($state.loading) return; - const submitButton = selector.submitButton; const packet = await cipher.createDRSAPHandshake($url.id); - typeTo(selector.textField, packet); - textFiled = document.querySelector(selector.textField) as HTMLElement; + typeTo(getSelector("textField"), packet); + textFiled = document.querySelector(getSelector("textField")) as HTMLElement; textFiled.style.display = "none"; await wait(50); state.update((state) => ({ ...state, loading: true, submit: true })); textFiled.style.display = "block"; - clickTo(submitButton); + clickTo(getSelector("submitButton")); isMenuOpen = false; intervalId = setInterval(() => { const user = LocalStorage.getMap(config.CONTACTS_STORAGE_KEY, $url.id); @@ -77,15 +77,15 @@ }; -
+ + +
- -
{#if status === "safe"}
diff --git a/src/components/modules/popup/Settings.svelte b/src/components/modules/popup/Settings.svelte index a6042e9..9ef5aa9 100644 --- a/src/components/modules/popup/Settings.svelte +++ b/src/components/modules/popup/Settings.svelte @@ -39,7 +39,7 @@ goto("/advanced-setting")}> Advanced Settings - v0.9.2 + v0.9.3