Skip to content

Commit

Permalink
v1.4.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudo-Ivan committed Sep 23, 2024
1 parent 3d0aff2 commit 4e2d0b7
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Cryptic Chat Preview](preview/cryptic-chat-preview1.png)

A Chrome V3 extension to encrypt and decrypt cryptic messages to get around censorship.
A Chrome V3 extension to exchange cryptic messages with friends.

## Work In Progress (WIP)

Expand Down
7 changes: 6 additions & 1 deletion html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<div class="options-container">
<h1>Wordlist Options</h1>
<p>Enter each phrase pair on a new line, separating the original phrase from the cryptic phrase with a colon (:).</p>
<p>Example: the government is cool : veggies are good for you</p>
<div class="wordlist-actions">
<button id="uploadBtn" class="icon-button"><img src="../icons/upload.png" alt="Upload" title="Upload Wordlist"></button>
<button id="downloadBtn" class="icon-button"><img src="../icons/download.png" alt="Download" title="Download Wordlist"></button>
Expand All @@ -23,6 +22,12 @@ <h1>Wordlist Options</h1>
<input type="text" id="urlInput" placeholder="Enter HTTPS URL ending with .txt">
<button id="updateFromUrlBtn">Update from URL</button>
</div>
<div class="auto-update-container">
<label for="autoUpdate">
<input type="checkbox" id="autoUpdate">
Auto-Update Wordlist from URL (Only when using URL wordlist)
</label>
</div>
<textarea id="wordlist" placeholder="Enter wordlist"></textarea>
<button id="saveBtn">Save</button>
<p id="errorMsg"></p>
Expand Down
2 changes: 1 addition & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let popupWindowId = null;

chrome.runtime.onInstalled.addListener(() => {
const defaultWordlist = {
"bypassing censorship is the best": "veggies are good for you"
"I hate veggies": "veggies are good for you"
};
chrome.storage.local.set({ wordlist: defaultWordlist });

Expand Down
112 changes: 102 additions & 10 deletions js/content.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
let crypticChatInterval;

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "parseCrypticText") {
parseCrypticText();
return true;
}

try {
chrome.storage.local.get("wordlist", (data) => {
if (chrome.runtime.lastError) {
sendResponse({ error: chrome.runtime.lastError.message });
return;
}

const wordlist = data.wordlist || {};
let processedMessage = request.message;
let actionType;

if (request.action === "encrypt") {
for (const [key, value] of Object.entries(wordlist)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(key), 'g'), value);
Expand All @@ -23,15 +31,99 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
sendResponse({ error: "Unknown action" });
return;
}

let response = {};
response[actionType] = processedMessage;

sendResponse(response);
});
return true;
});

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
} catch (error) {
console.error("Error in onMessage listener: ", error);
sendResponse({ error: "An error occurred while processing the message" });
}
return true;
});

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

function parseCrypticText() {
try {
chrome.storage.local.get("wordlist", (data) => {
if (chrome.runtime.lastError) {
console.error("Chrome runtime error: ", chrome.runtime.lastError);
return;
}

const wordlist = data.wordlist || {};
let decryptedTexts = discordParse(wordlist);

if (decryptedTexts.length > 0) {
displayDecryptedText(decryptedTexts.join('\n\n'));
}
});
} catch (error) {
console.error("Error in parseCrypticText: ", error);
if (error.message.includes("Extension context invalidated")) {
clearInterval(crypticChatInterval);
}
}
}

function displayDecryptedText(text) {
try {
let decryptedBox = document.getElementById('cryptic-chat-decrypted-box');
if (!decryptedBox) {
decryptedBox = document.createElement('div');
decryptedBox.id = 'cryptic-chat-decrypted-box';
decryptedBox.style.position = 'fixed';
decryptedBox.style.bottom = '10px';
decryptedBox.style.right = '10px';
decryptedBox.style.width = '450px';
decryptedBox.style.maxHeight = '400px';
decryptedBox.style.overflowY = 'auto';
decryptedBox.style.backgroundColor = '#16213e';
decryptedBox.style.border = '1px solid #4ecca3';
decryptedBox.style.borderRadius = '10px';
decryptedBox.style.padding = '10px';
decryptedBox.style.zIndex = '9999';
decryptedBox.style.color = '#ffffff';
decryptedBox.style.fontFamily = "'Roboto', 'Arial', sans-serif";

const closeButton = document.createElement('button');
closeButton.textContent = 'Close';
closeButton.style.position = 'absolute';
closeButton.style.top = '5px';
closeButton.style.right = '5px';
closeButton.style.backgroundColor = '#4ecca3';
closeButton.style.border = 'none';
closeButton.style.borderRadius = '5px';
closeButton.style.padding = '5px 10px';
closeButton.style.cursor = 'pointer';
closeButton.onclick = () => decryptedBox.remove();

decryptedBox.appendChild(closeButton);
document.body.appendChild(decryptedBox);
}

const content = document.createElement('div');
content.innerHTML = `
<h3 style="color: #4ecca3; margin-top: 0; margin-bottom: 10px;">Cryptic Chat</h3>
<hr style="border: 0; height: 1px; background-color: #4ecca3; margin-bottom: 10px;">
<pre style="white-space: pre-wrap; word-wrap: break-word; margin: 0;">${text}</pre>
`;

decryptedBox.innerHTML = '';
decryptedBox.appendChild(content);
} catch (error) {
console.error("Error in displayDecryptedText: ", error);
}
}

try {
parseCrypticText();
crypticChatInterval = setInterval(parseCrypticText, 5000);
} catch (error) {
console.error("Error in initial parseCrypticText call: ", error);
}
47 changes: 47 additions & 0 deletions js/discord-parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function discordParse(wordlist) {
let decryptedTexts = [];

const chatArea = document.querySelector('.chatContent_a7d72e');
if (!chatArea) return decryptedTexts;

chatArea.querySelectorAll('[id^="chat-messages-"]').forEach(messageElement => {
const decryptedText = decryptElement(messageElement, wordlist);
if (decryptedText) decryptedTexts.push(decryptedText);
if (decryptedTexts.length >= 10) return;
});

return decryptedTexts;
}

function decryptElement(messageElement, wordlist) {
try {
const contentElement = messageElement.querySelector('[id^="message-content-"]');
if (!contentElement) return null;

const originalText = contentElement.textContent.trim();
let decryptedText = originalText;

for (const [key, value] of Object.entries(wordlist)) {
decryptedText = decryptedText.replace(new RegExp(escapeRegExp(value), 'g'), key);
}

if (decryptedText !== originalText) {
const usernameElement = messageElement.querySelector('[class*="username_"]');
const timestampElement = messageElement.querySelector('time');

const username = usernameElement ? usernameElement.textContent.trim() : 'Unknown User';
const timestamp = timestampElement ? timestampElement.getAttribute('aria-label') : '';

return `${username}: ${decryptedText} - ${timestamp}`;
}

return null;
} catch (error) {
console.error("Error in decryptElement: ", error);
return null;
}
}

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
9 changes: 8 additions & 1 deletion js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ document.addEventListener("DOMContentLoaded", () => {
const fileInput = document.getElementById("fileInput");
const dropZone = document.getElementById("dropZone");
const updateFromUrlBtn = document.getElementById("updateFromUrlBtn");
const autoUpdateCheckbox = document.getElementById("autoUpdate");
const errorMsg = document.createElement("p");
errorMsg.id = "errorMsg";
errorMsg.style.color = "red";
errorMsg.style.fontSize = "12px";
document.querySelector(".options-container").appendChild(errorMsg);

chrome.storage.local.get("wordlist", (data) => {
chrome.storage.local.get(["wordlist", "wordlistUrl", "autoUpdate"], (data) => {
displayWordlist(data.wordlist || {});
document.getElementById("urlInput").value = data.wordlistUrl || "";
autoUpdateCheckbox.checked = data.autoUpdate || false;
});

saveBtn.addEventListener("click", saveWordlist);
uploadBtn.addEventListener("click", () => fileInput.click());
downloadBtn.addEventListener("click", downloadWordlist);
fileInput.addEventListener("change", (event) => processFile(event.target.files[0]));
updateFromUrlBtn.addEventListener("click", updateFromUrl);
autoUpdateCheckbox.addEventListener("change", () => {
chrome.storage.local.set({ autoUpdate: autoUpdateCheckbox.checked });
});

dropZone.addEventListener("dragover", handleDragOver);
dropZone.addEventListener("dragleave", handleDragLeave);
Expand Down Expand Up @@ -164,6 +170,7 @@ function updateFromUrl() {
console.log("Fetched text:", text.substring(0, 100) + "...");
document.getElementById("wordlist").value = text;
saveWordlist();
chrome.storage.local.set({ wordlistUrl: url });
showError("Wordlist updated successfully from URL!", false);
})
.catch(error => {
Expand Down
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"manifest_version": 3,
"name": "Cryptic Chat",
"version": "1.3.1",
"version": "1.4.0",
"author": {
"name": "Sudo-Ivan"
},
"description": "Encrypt and decrypt cryptic messages to get around censorship.",
"description": "Exchange cryptic messages with friends.",
"permissions": [
"activeTab",
"storage",
Expand All @@ -25,8 +25,8 @@
"options_page": "html/options.html",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/content.js"]
"matches": ["https://discord.com/*"],
"js": ["js/content.js", "js/discord-parse.js"]
}
],
"icons": {
Expand Down

0 comments on commit 4e2d0b7

Please sign in to comment.