From 6316316253aa2e21b5c1689157df74e4a013f173 Mon Sep 17 00:00:00 2001 From: Ivan Ryan Date: Tue, 8 Oct 2024 02:54:02 -0500 Subject: [PATCH] add: clear data --- css/styles.css | 12 ++++++++++++ html/options.html | 8 ++++++++ js/options.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/css/styles.css b/css/styles.css index aa42416..ccbb82e 100644 --- a/css/styles.css +++ b/css/styles.css @@ -248,6 +248,7 @@ button:last-child { #statusMsg { margin-top: 20px; + margin-bottom: 20px; padding: 10px; border-radius: 5px; text-align: center; @@ -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; } \ No newline at end of file diff --git a/html/options.html b/html/options.html index 29cd0c6..4b692d5 100644 --- a/html/options.html +++ b/html/options.html @@ -21,6 +21,7 @@

Codebook

+
@@ -125,6 +126,13 @@

Advanced Features

+
+

Data Management

+
+ +
+
+
diff --git a/js/options.js b/js/options.js index 7a97227..2f6115b 100644 --- a/js/options.js +++ b/js/options.js @@ -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(); @@ -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)); @@ -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(); + } + }); + } } \ No newline at end of file