Skip to content

Commit

Permalink
add: clear data
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudo-Ivan committed Oct 8, 2024
1 parent b28df59 commit 6316316
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ button:last-child {

#statusMsg {
margin-top: 20px;
margin-bottom: 20px;
padding: 10px;
border-radius: 5px;
text-align: center;
Expand Down Expand Up @@ -465,4 +466,15 @@ button:last-child {

#exportCodebook:hover {
background-color: #e59100;
}

.danger-btn {
background-color: #e84545;
color: #ffffff;
margin-top: 20px;
width: 50%;
}

.danger-btn:hover {
background-color: #d63d3d;
}
8 changes: 8 additions & 0 deletions html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h2>Codebook</h2>
</button>
</div>
<textarea id="codebookText" placeholder="Enter your codebook here..."></textarea>
<div id="statusMsg"></div>

<div class="url-input-container">
<input type="text" id="urlInput" placeholder="Enter URL for remote codebook">
Expand Down Expand Up @@ -125,6 +126,13 @@ <h2>Advanced Features</h2>
</div>
</section>

<section>
<h2>Data Management</h2>
<div class="option-row">
<button id="clearDataBtn" class="danger-btn">Clear All Data and Reset Values</button>
</div>
</section>

<div id="statusMsg"></div>
</div>
<input type="file" id="fileInput" style="display: none;">
Expand Down
42 changes: 42 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ document.addEventListener('DOMContentLoaded', function() {
const addMutedUserBtn = document.getElementById("addMutedUser");
const newMutedUserInput = document.getElementById("newMutedUser");
const resetThemeBtn = document.getElementById("resetTheme");
const clearDataBtn = document.getElementById('clearDataBtn');

loadOptions();

Expand Down Expand Up @@ -51,6 +52,10 @@ document.addEventListener('DOMContentLoaded', function() {
});
}

if (clearDataBtn) {
clearDataBtn.addEventListener('click', clearAllData);
}

document.getElementById('exportCodebook').addEventListener('click', exportCodebook);
document.getElementById('saveBtn').addEventListener('click', () => saveOptions(true));

Expand Down Expand Up @@ -512,4 +517,41 @@ function autoSave() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {action: "updateStyles"});
});
}

function clearAllData() {
if (confirm("Are you sure you want to clear all data and reset all values? This action cannot be undone.")) {
chrome.storage.local.clear(() => {
if (chrome.runtime.lastError) {
showStatus('Error clearing data: ' + chrome.runtime.lastError.message, true);
} else {
// Reset all input fields to their default values
document.getElementById('codebookText').value = '';
document.getElementById('messagesToLoad').value = '50';
document.getElementById('autoScroll').checked = true;
document.getElementById('backgroundColor').value = '#141422';
document.getElementById('inputBoxColor').value = '#1e1e3f';
document.getElementById('headerColor').value = '#1a1a40';
document.getElementById('windowTransparency').value = '90';
document.getElementById('urlInput').value = '';
document.getElementById('autoUpdate').checked = false;
document.getElementById('autoSend').checked = true;
document.getElementById('destructableMessages').checked = false;
document.getElementById('destructKeyword').value = '\\d ! d';
document.getElementById('defaultDestructTime').value = '5';
document.getElementById('showDestructTimer').checked = true;
document.getElementById('messageSpacing').value = '5';
document.getElementById('crypticPhrase').value = '\\d ! d';
document.getElementById('messageBubbleColor').value = '#1e1e3f';
document.getElementById('messageBubbleOpacity').value = '70';

// Clear user colors and muted users
document.getElementById('userColorContainer').innerHTML = '';
document.getElementById('mutedUsersContainer').innerHTML = '';

showStatus('All data cleared and values reset successfully');
saveOptions();
}
});
}
}

0 comments on commit 6316316

Please sign in to comment.