Skip to content

Commit

Permalink
update 1.4.1
Browse files Browse the repository at this point in the history
wording changes, auto-saving and other minor changes.
  • Loading branch information
Sudo-Ivan committed Sep 24, 2024
1 parent 79b01fd commit bc9fede
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 135 deletions.
17 changes: 8 additions & 9 deletions html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wordlist Options</title>
<title>Codebook Options</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../css/styles.css">
</head>
<body class="options-body">
<div class="options-container">
<h1>Wordlist Options</h1>
<h1>Codebook Options</h1>
<p>Enter each phrase pair on a new line, separating the original phrase from the cryptic phrase with a colon (:).</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>
<div class="codebook-actions">
<button id="uploadBtn" class="icon-button"><img src="../icons/upload.png" alt="Upload" title="Upload Codebook"></button>
<button id="downloadBtn" class="icon-button"><img src="../icons/download.png" alt="Download" title="Download Codebook"></button>
</div>
<div id="dropZone" class="drop-zone">
<p>Drag and drop a file here</p>
</div>
<div class="url-input-container">
<input type="text" id="urlInput" placeholder="Enter HTTPS URL ending with .txt">
<input type="text" id="urlInput" placeholder="Enter 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)
Auto-Update Codebook from URL (Only when using URL codebook)
</label>
</div>
<textarea id="wordlist" placeholder="Enter wordlist"></textarea>
<button id="saveBtn">Save</button>
<textarea id="codebook" placeholder="Enter codebook"></textarea>
<p id="errorMsg"></p>
</div>
<input type="file" id="fileInput" style="display: none;">
Expand Down
6 changes: 3 additions & 3 deletions html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<body class="popup-body">
<div class="popup-container">
<h1>Cryptic Chat</h1>
<textarea id="inputText" placeholder="Enter text"></textarea>
<textarea id="outputText" placeholder="Output text"></textarea>
<button id="openOptions">Edit Wordlist</button>
<textarea id="inputText" placeholder="Decrypted Message"></textarea>
<textarea id="outputText" placeholder="Cryptic Meesage"></textarea>
<button id="openOptions">Options</button>
</div>
<script src="../js/popup.js"></script>
</body>
Expand Down
36 changes: 24 additions & 12 deletions js/background.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let popupWindowId = null;

chrome.runtime.onInstalled.addListener(() => {
const defaultWordlist = {
const defaultCodebook = {
"I hate veggies": "veggies are good for you"
};
chrome.storage.local.set({ wordlist: defaultWordlist });
chrome.storage.local.set({ codebook: defaultCodebook });

chrome.contextMenus.create({
id: "encrypt",
Expand All @@ -21,8 +21,8 @@ chrome.runtime.onInstalled.addListener(() => {

chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "encrypt" || info.menuItemId === "decrypt") {
chrome.storage.local.get("wordlist", (data) => {
processMessage(data.wordlist || {}, {
chrome.storage.local.get("codebook", (data) => {
processMessage(data.codebook || {}, {
action: info.menuItemId,
message: info.selectionText
}, (response) => {
Expand All @@ -33,25 +33,37 @@ chrome.contextMenus.onClicked.addListener((info, tab) => {
});

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "encrypt" || request.action === "decrypt") {
chrome.storage.local.get("wordlist", (data) => {
processMessage(data.wordlist || {}, request, sendResponse);
if (isValidMessage(request)) {
chrome.storage.local.get("codebook", (data) => {
processMessage(data.codebook || {}, request, sendResponse);
});
return true;
} else {
sendResponse({ error: 'Invalid message format' });
}
});

function processMessage(wordlist, request, sendResponse) {
function isValidMessage(request) {
return request &&
(request.action === 'encrypt' || request.action === 'decrypt') &&
typeof request.message === 'string';
}

function processMessage(codebook, request, sendResponse) {
let processedMessage = request.message;

if (request.action === "encrypt") {
for (const [key, value] of Object.entries(wordlist)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(key), 'g'), value);
for (const key in codebook) {
if (codebook.hasOwnProperty(key)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(key), 'g'), codebook[key]);
}
}
sendResponse({ encryptedMessage: processedMessage });
} else {
for (const [key, value] of Object.entries(wordlist)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(value), 'g'), key);
for (const key in codebook) {
if (codebook.hasOwnProperty(key)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(codebook[key]), 'g'), key);
}
}
sendResponse({ decryptedMessage: processedMessage });
}
Expand Down
75 changes: 43 additions & 32 deletions js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,69 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return true;
}

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

const wordlist = data.wordlist || {};
let processedMessage = request.message;
let actionType;
const codebook = data.codebook || {};
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);
}
actionType = 'encryptedMessage';
} else if (request.action === "decrypt") {
for (const [key, value] of Object.entries(wordlist)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(value), 'g'), key);
if (request.action === "encrypt") {
for (const key in codebook) {
if (codebook.hasOwnProperty(key)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(key), 'g'), codebook[key]);
}
}
actionType = 'encryptedMessage';
} else if (request.action === "decrypt") {
for (const key in codebook) {
if (codebook.hasOwnProperty(key)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(codebook[key]), 'g'), key);
}
}
actionType = 'decryptedMessage';
}
actionType = 'decryptedMessage';
} else {
sendResponse({ error: "Unknown action" });
return;
}

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

sendResponse(response);
});
} catch (error) {
console.error("Error in onMessage listener: ", error);
sendResponse({ error: "An error occurred while processing the message" });
sendResponse(response);
});
} catch (error) {
console.error("Error in onMessage listener: ", error);
sendResponse({ error: "An error occurred while processing the message" });
}
} else {
sendResponse({ error: 'Invalid message format' });
}
return true;
});

function isValidMessage(request) {
return request &&
(request.action === 'encrypt' || request.action === 'decrypt') &&
typeof request.message === 'string';
}

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

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

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

if (decryptedTexts.length > 0) {
displayDecryptedText(decryptedTexts.join('\n\n'));
Expand Down
76 changes: 41 additions & 35 deletions js/discord-parse.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
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 discordParse(codebook) {
let decryptedTexts = [];

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

const messageElements = chatArea.querySelectorAll('[id^="chat-messages-"]');
for (let i = 0; i < messageElements.length; i++) {
const decryptedText = decryptElement(messageElements[i], codebook);
if (decryptedText) {
decryptedTexts.push(decryptedText);
if (decryptedTexts.length >= 10) break;
}
}

function decryptElement(messageElement, wordlist) {
try {

return decryptedTexts;
}

function decryptElement(messageElement, codebook) {
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);

for (const key in codebook) {
if (Object.prototype.hasOwnProperty.call(codebook, key)) {
const value = codebook[key];
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}`;
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) {
} catch (error) {
console.error("Error in decryptElement: ", error);
return null;
}
}

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

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

0 comments on commit bc9fede

Please sign in to comment.