Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudo-Ivan committed Oct 8, 2024
1 parent 6316316 commit 642e80f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
16 changes: 10 additions & 6 deletions html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ <h2>Styling Options</h2>
<label for="headerColor">Header color:</label>
<input type="color" id="headerColor" value="#1a1a40">
</div>
<div id="userColorContainer"></div>
<button id="addUserColor">Add User Color</button>
<div class="option-row">
<button id="resetTheme">Reset Theme to Default</button>
</div>
<div class="option-row">
<label for="messageBubbleColor">Message Bubble Color:</label>
<input type="color" id="messageBubbleColor" value="#1e1e3f">
Expand All @@ -88,6 +83,11 @@ <h2>Styling Options</h2>
<label for="messageBubbleOpacity">Message Bubble Opacity:</label>
<input type="range" id="messageBubbleOpacity" min="0" max="100" value="70">
</div>
<div id="userColorContainer"></div>
<button id="addUserColor">Add User Color</button>
<div class="option-row">
<button id="resetTheme">Reset Theme to Default</button>
</div>
</section>

<section>
Expand Down Expand Up @@ -122,7 +122,8 @@ <h2>Advanced Features</h2>
<input type="checkbox" id="showDestructTimer" checked>
</div>
<div class="option-row">
<button id="exportCodebook">Export Codebook with Settings</button>
<label for="caseInsensitiveEncryption">Case-insensitive Encryption (Codebook):</label>
<input type="checkbox" id="caseInsensitiveEncryption">
</div>
</section>

Expand All @@ -131,6 +132,9 @@ <h2>Data Management</h2>
<div class="option-row">
<button id="clearDataBtn" class="danger-btn">Clear All Data and Reset Values</button>
</div>
<div class="option-row">
<button id="exportCodebook">Export Codebook with Settings</button>
</div>
</section>

<div id="statusMsg"></div>
Expand Down
26 changes: 23 additions & 3 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ function isValidMessage(request) {
function processMessage(request, sendResponse) {
let processedMessage = request.message;

chrome.storage.local.get(['codebook', 'mutedUsers', 'crypticPhrase'], function(result) {
chrome.storage.local.get(['codebook', 'mutedUsers', 'crypticPhrase', 'caseInsensitiveEncryption'], function(result) {
const codebook = result.codebook || {};
const mutedUsers = result.mutedUsers || [];
const crypticPhrase = result.crypticPhrase || '\\d ! d';
const caseInsensitiveEncryption = result.caseInsensitiveEncryption || false;

// Check if the message is from a muted user
const username = extractUsername(processedMessage);
Expand All @@ -130,7 +131,17 @@ function processMessage(request, sendResponse) {
if (request.action === "encrypt") {
for (const key in codebook) {
if (codebook.hasOwnProperty(key)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(key), 'g'), codebook[key]);
const regex = caseInsensitiveEncryption
? new RegExp(escapeRegExp(key), 'gi')
: new RegExp(escapeRegExp(key), 'g');
processedMessage = processedMessage.replace(regex, (match) => {
const replacement = codebook[key];
return caseInsensitiveEncryption ? replacement : (
match === match.toUpperCase() ? replacement.toUpperCase() :
match === match.toLowerCase() ? replacement.toLowerCase() :
replacement
);
});
}
}
// Replace default cryptic phrase with custom one
Expand All @@ -141,7 +152,16 @@ function processMessage(request, sendResponse) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(crypticPhrase), 'g'), '\\d ! d');
for (const key in codebook) {
if (codebook.hasOwnProperty(key)) {
processedMessage = processedMessage.replace(new RegExp(escapeRegExp(codebook[key]), 'g'), key);
const regex = caseInsensitiveEncryption
? new RegExp(escapeRegExp(codebook[key]), 'gi')
: new RegExp(escapeRegExp(codebook[key]), 'g');
processedMessage = processedMessage.replace(regex, (match) => {
return caseInsensitiveEncryption ? key : (
match === match.toUpperCase() ? key.toUpperCase() :
match === match.toLowerCase() ? key.toLowerCase() :
key
);
});
}
}
sendResponse({ decryptedMessage: processedMessage });
Expand Down
6 changes: 6 additions & 0 deletions js/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ CrypticChat.Discord = {
const contentElement = messageElement.querySelector('[id^="message-content-"]');
if (!contentElement) return null;

// Ignore repliedTextPreview
const repliedTextPreview = messageElement.querySelector('[class*="repliedTextPreview_"]');
if (repliedTextPreview) {
return null;
}

const originalText = contentElement.textContent.trim();
let decryptedText = originalText;
let isDecrypted = false;
Expand Down
9 changes: 7 additions & 2 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById(id).addEventListener('change', debounce(autoSave, 500));
document.getElementById(id).addEventListener('input', debounce(autoSave, 500));
});

document.getElementById('caseInsensitiveEncryption').addEventListener('change', saveOptions);
});

function debounce(func, delay) {
Expand Down Expand Up @@ -129,7 +131,8 @@ function saveOptions(showMessage = true) {
messageBubbleOpacity: document.getElementById('messageBubbleOpacity').value,
userColors: getUserColors(),
mutedUsers: getMutedUsers(),
autoSend: document.getElementById('autoSend').checked
autoSend: document.getElementById('autoSend').checked,
caseInsensitiveEncryption: document.getElementById('caseInsensitiveEncryption').checked
};

chrome.storage.local.set(options, function() {
Expand Down Expand Up @@ -160,7 +163,8 @@ function loadOptions() {
'messageSpacing',
'crypticPhrase',
'messageBubbleColor',
'messageBubbleOpacity'
'messageBubbleOpacity',
'caseInsensitiveEncryption'
], function(items) {
document.getElementById('codebookText').value = formatCodebook(items.codebook || {});
document.getElementById('messagesToLoad').value = items.messagesToLoad || 50;
Expand All @@ -182,6 +186,7 @@ function loadOptions() {
document.getElementById('crypticPhrase').value = items.crypticPhrase || '\\d ! d';
document.getElementById('messageBubbleColor').value = items.messageBubbleColor || '#1e1e3f';
document.getElementById('messageBubbleOpacity').value = items.messageBubbleOpacity || '70';
document.getElementById('caseInsensitiveEncryption').checked = items.caseInsensitiveEncryption || false;
});
}

Expand Down

0 comments on commit 642e80f

Please sign in to comment.