Skip to content

Commit

Permalink
🐛 limit the message content to be bellow 1200 character
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa-kheibary committed Apr 10, 2024
1 parent 531dcd2 commit 66edf61
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/content/scripts/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const registerEventListener = (urlStore: Url) => {
const state = get(chatStore);
const contact = LocalStorage.getMap(config.CONTACTS_STORAGE_KEY, urlStore.id);
let textFieldElement = document.querySelector(selector.textField) as HTMLElement;
const messageLengthIsOk = (textFieldElement.textContent || "").length <= 1200;

if (!textFieldElement.textContent?.trim() || !contact.enable) return;
if (state.clickSubmit || state.submit)
Expand All @@ -36,6 +37,8 @@ export const registerEventListener = (urlStore: Url) => {
e.preventDefault();
e.stopImmediatePropagation();

if (!messageLengthIsOk) return alert("character length should be bellow 1200 character");

const encrypted = await cipher.createDRSAP(textFieldElement.textContent || "", urlStore.id);
if (!encrypted) return;
typeTo(selector.textField, encrypted);
Expand All @@ -58,22 +61,26 @@ export const registerEventListener = (urlStore: Url) => {

const contact = LocalStorage.getMap(config.CONTACTS_STORAGE_KEY, urlStore.id);
let textFieldElement = document.querySelector(selector.textField) as HTMLElement;
const messageLengthIsOk = (textFieldElement.textContent || "").length <= 1200;

if (e.key === "Enter" && contact.enable && textFieldElement.textContent?.trim() && !e.shiftKey && !isTouch) {
e.preventDefault();
e.stopImmediatePropagation();
const encrypted = await cipher.createDRSAP(textFieldElement.textContent || "", urlStore.id);
if (!encrypted) return;
typeTo(selector.textField, encrypted);
textFieldElement = document.querySelector(selector.textField) as HTMLElement;
textFieldElement.style.display = "none";
await wait(20);
chatStore.update((prev) => ({ ...prev, submit: true }));
clickTo(selector.submitButton);
textFieldElement.focus();
textFieldElement.style.display = "block";
logger.info("Message sent, Form submitted");
if (e.key !== "Enter" || !contact.enable || !textFieldElement.textContent?.trim() || e.shiftKey || isTouch) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();

if (!messageLengthIsOk) return alert("character length should be bellow 1200 character");
const encrypted = await cipher.createDRSAP(textFieldElement.textContent || "", urlStore.id);
if (!encrypted) return;
typeTo(selector.textField, encrypted);
textFieldElement = document.querySelector(selector.textField) as HTMLElement;
textFieldElement.style.display = "none";
await wait(20);
chatStore.update((prev) => ({ ...prev, submit: true }));
clickTo(selector.submitButton);
textFieldElement.focus();
textFieldElement.style.display = "block";
logger.info("Message sent, Form submitted");
},
{ capture: true }
);
Expand Down

0 comments on commit 66edf61

Please sign in to comment.