Skip to content

Commit

Permalink
1.6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudo-Ivan committed Oct 10, 2024
1 parent 01f44e5 commit 06c8296
Show file tree
Hide file tree
Showing 13 changed files with 1,009 additions and 321 deletions.
42 changes: 42 additions & 0 deletions css/popout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.popout-body {
width: 100%;
height: 100vh;
margin: 0;
padding: 20px;
box-sizing: border-box;
background-color: #000000;
font-family: Arial, sans-serif;
color: #ffffff;
}

.popout-container {
max-width: 600px;
margin: 0 auto;
background-color: #1a1a1a;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
}

.popout-container h1, .popout-container h2 {
color: #ffffff;
}

.popout-container textarea {
width: 100%;
height: 300px;
margin-bottom: 10px;
background-color: #2a2a2a;
color: #ffffff;
border: 1px solid #3a3a3a;
}

.popout-container input[type="text"] {
background-color: #2a2a2a;
color: #ffffff;
border: 1px solid #3a3a3a;
}

.phrase-count {
color: #ffffff;
}
63 changes: 63 additions & 0 deletions html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,69 @@ <h2>Data Management</h2>
</section>
<span id="autoSaveStatus"></span>
<div id="statusMsg"></div>

<section>
<h3>Discord Selectors</h3>
<div class="option-row">
<label for="chatAreaSelector">Chat Area Selector:</label>
<input type="text" id="chatAreaSelector" />
</div>
<div class="option-row">
<label for="messageElementsSelector">Message Elements Selector:</label>
<input type="text" id="messageElementsSelector" />
</div>
<div class="option-row">
<label for="contentElementSelector">Content Element Selector:</label>
<input type="text" id="contentElementSelector" />
</div>
<div class="option-row">
<label for="repliedTextPreviewSelector">Replied Text Preview Selector:</label>
<input type="text" id="repliedTextPreviewSelector" />
</div>
<div class="option-row">
<label for="usernameElementSelector">Username Element Selector:</label>
<input type="text" id="usernameElementSelector" />
</div>
<div class="option-row">
<label for="timestampElementSelector">Timestamp Element Selector:</label>
<input type="text" id="timestampElementSelector" />
</div>
<div class="option-row">
<label for="messageInputSelector">Message Input Selector:</label>
<input type="text" id="messageInputSelector" />
</div>
<button id="resetDiscordSelectors">Reset Discord Selectors</button>
</section>

<!-- Add this section after the Discord selectors section -->
<section>
<h2>Element Selectors</h2>
<div class="option-row">
<label for="elementChatAreaSelector">Chat Area:</label>
<input type="text" id="elementChatAreaSelector" />
</div>
<div class="option-row">
<label for="elementMessageElementsSelector">Message Elements:</label>
<input type="text" id="elementMessageElementsSelector" />
</div>
<div class="option-row">
<label for="elementContentElementSelector">Content Element:</label>
<input type="text" id="elementContentElementSelector" />
</div>
<div class="option-row">
<label for="elementUsernameElementSelector">Username Element:</label>
<input type="text" id="elementUsernameElementSelector" />
</div>
<div class="option-row">
<label for="elementTimestampElementSelector">Timestamp Element:</label>
<input type="text" id="elementTimestampElementSelector" />
</div>
<div class="option-row">
<label for="elementMessageInputSelector">Message Input:</label>
<input type="text" id="elementMessageInputSelector" />
</div>
<button id="resetElementSelectors">Reset Element Selectors</button>
</section>
</div>
<script src="../js/options.js"></script>
<div class="save-container">
Expand Down
34 changes: 34 additions & 0 deletions html/popout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cryptic Chat Popout</title>
<link rel="stylesheet" href="../css/styles.css">
<link rel="stylesheet" href="../css/popout.css">
</head>
<body class="popout-body">
<div class="popout-container">
<h1>Cryptic Chat Popout</h1>

<section>
<h2>Codebook</h2>
<div class="codebook-actions">
<button class="icon-button" id="downloadBtn" title="Export Codebook">
<img src="../icons/download.png" alt="Export">
</button>
<button class="icon-button" id="uploadBtn" title="Import Codebook">
<img src="../icons/upload.png" alt="Import">
</button>
<input type="file" id="fileInput" accept=".txt,.json" style="display: none;">
</div>
<div class="option-row">
<input type="text" id="codebookSearch" placeholder="Search codebook...">
</div>
<textarea id="codebookText" placeholder="Enter your codebook here..."></textarea>
<div id="codebookPhraseCount" class="phrase-count">Phrases: 0</div>
</section>
</div>
<script src="../js/popout.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ <h1>Cryptic Chat</h1>
<textarea id="inputText" placeholder="Decrypted Message"></textarea>
<textarea id="outputText" placeholder="Cryptic Message"></textarea>
<button id="openOptions">Options</button>
<button id="popoutCodebook" class="icon-button" title="Popout Codebook">
<img src="../icons/popout.png" alt="Popout">
</button>
</div>
<script src="../js/popup.js"></script>
</body>
Expand Down
Binary file added icons/popout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 60 additions & 34 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,30 @@ chrome.runtime.onInstalled.addListener(() => {
}
}]
});

chrome.storage.local.set({
elementSelectors: {
chatArea: '[class^="mx_RoomView_messagePanel"]',
messageElements: '[class^="mx_EventTile"]',
contentElement: '[class^="mx_EventTile_body"]',
usernameElement: '[class^="mx_Username_color"][class*="mx_DisambiguatedProfile_displayName"]',
timestampElement: '[class^="mx_MessageTimestamp"]',
messageInput: '[class^="mx_BasicMessageComposer_input"]'
}
});

chrome.storage.local.get('messageCheckInterval', (result) => {
const interval = result.messageCheckInterval || 5;
startMessageCheckInterval(interval);
});
});

chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "encrypt" || info.menuItemId === "decrypt") {
processMessage({
action: info.menuItemId,
message: info.selectionText
message: info.selectionText,
platform: 'contextMenu'
}, (response) => {
openOrUpdatePopupWithResults(response, info.selectionText);
});
Expand Down Expand Up @@ -110,6 +127,17 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
.then(decryptedData => sendResponse({ decryptedData }))
.catch(error => sendResponse({ error: error.message }));
return true;
} else if (request.action === 'updateDiscordSelectors' || request.action === 'updateElementSelectors') {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { action: request.action });
});
} else if (request.action === 'popoutCodebook') {
popoutCodebookWindow();
} else if (request.action === 'updateMessageCheckInterval') {
chrome.storage.local.get('messageCheckInterval', (result) => {
const interval = result.messageCheckInterval || 5;
startMessageCheckInterval(interval);
});
} else if (isValidMessage(request)) {
processMessage(request, sendResponse);
return true;
Expand All @@ -121,12 +149,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
function isValidMessage(request) {
return request &&
(request.action === 'encrypt' || request.action === 'decrypt') &&
typeof request.message === 'string';
typeof request.message === 'string' &&
(request.platform === 'discord' || request.platform === 'element' || request.platform === 'contextMenu');
}

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

chrome.storage.local.get([
'codebook',
'mutedUsers',
Expand All @@ -143,6 +170,8 @@ function processMessage(request, sendResponse) {
const destructableMessages = result.destructableMessages || false;
const destructKeyword = result.destructKeyword || '\\d ! d';
const defaultDestructTime = result.defaultDestructTime || 5;

let processedMessage = request.message;

// Check if the message is from a muted user
const username = extractUsername(processedMessage);
Expand All @@ -160,7 +189,7 @@ function processMessage(request, sendResponse) {
const destructMatch = processedMessage.match(destructRegex);
if (destructMatch) {
const minutes = destructMatch[1] || defaultDestructTime;
processedMessage = processedMessage.replace(destructMatch[0], `${crypticPhrase}${minutes}//`);
processedMessage = processedMessage.replace(destructMatch[0], `${crypticPhrase}${minutes}`);
}
}

Expand All @@ -185,8 +214,8 @@ function processMessage(request, sendResponse) {
// Decrypt the message
// Handle destructible messages
const destructRegex = caseInsensitiveEncryption
? new RegExp(escapeRegExp(crypticPhrase) + '(\\d+)//', 'gi')
: new RegExp(escapeRegExp(crypticPhrase) + '(\\d+)//', 'g');
? new RegExp(escapeRegExp(crypticPhrase) + '(\\d+)', 'gi')
: new RegExp(escapeRegExp(crypticPhrase) + '(\\d+)', 'g');
const destructMatch = processedMessage.match(destructRegex);

if (destructMatch) {
Expand Down Expand Up @@ -217,7 +246,6 @@ function processMessage(request, sendResponse) {
}

function extractUsername(message) {
// This function should extract the username from the message
const match = message.match(/^([^:]+):/);
return match ? match[1].trim() : '';
}
Expand Down Expand Up @@ -272,37 +300,20 @@ chrome.windows.onRemoved.addListener((windowId) => {
let messageCheckIntervalId = null;

function startMessageCheckInterval(interval) {
if (messageCheckIntervalId) {
clearInterval(messageCheckIntervalId);
}
messageCheckIntervalId = setInterval(checkForNewMessages, interval * 1000);
if (messageCheckIntervalId) {
clearInterval(messageCheckIntervalId);
}
messageCheckIntervalId = setInterval(checkForNewMessages, interval * 1000);
}

function checkForNewMessages() {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'checkForNewMessages' });
}
});
}

chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.get('messageCheckInterval', (result) => {
const interval = result.messageCheckInterval || 5;
startMessageCheckInterval(interval);
});
});

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'updateMessageCheckInterval') {
chrome.storage.local.get('messageCheckInterval', (result) => {
const interval = result.messageCheckInterval || 5;
startMessageCheckInterval(interval);
});
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'checkForNewMessages' });
}
});
});
}

// Add these functions at the beginning of the file
async function generateKey(password) {
const encoder = new TextEncoder();
const data = encoder.encode(password);
Expand Down Expand Up @@ -335,4 +346,19 @@ async function decryptData(encryptedData, key) {
);
const decoder = new TextDecoder();
return JSON.parse(decoder.decode(decryptedContent));
}

function popoutCodebookWindow() {
chrome.windows.create({
url: chrome.runtime.getURL("html/popout.html"),
type: "popup",
width: 600,
height: 700
});
}

function loadCodebook() {
chrome.storage.local.get('codebook', function(result) {
codebook = result.codebook || {};
});
}
Loading

0 comments on commit 06c8296

Please sign in to comment.