From c6845a798c99e96aa0e2f6daece0684a8ac50681 Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Sun, 19 Nov 2023 16:21:29 +0100 Subject: wip --- options.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 options.js (limited to 'options.js') diff --git a/options.js b/options.js new file mode 100644 index 0000000..aa33ea1 --- /dev/null +++ b/options.js @@ -0,0 +1,61 @@ +document.addEventListener('DOMContentLoaded', function() { + const domainInput = document.getElementById('domainInput'); + const addDomainButton = document.getElementById('addDomainButton'); + const domainList = document.getElementById('domainList'); + + // Load the current list of domains + browser.storage.sync.get('domains', function(data) { + const domains = data.domains || []; + if (domains.length === 0) { + updateDomainList(["https://gitlab.com"]); + } else { + updateDomainList(domains); + } + }); + + // Function to update the displayed domain list + function updateDomainList(domains) { + domainList.innerHTML = ''; + domains.forEach(function(domain) { + const li = document.createElement('li'); + li.textContent = domain; + + // Add a delete button for each domain + const deleteButton = document.createElement('button'); + deleteButton.textContent = 'Delete'; + deleteButton.addEventListener('click', function() { + // Remove the domain and update the list + const updatedDomains = domains.filter(d => d !== domain); + browser.storage.sync.set({ 'domains': updatedDomains }, function() { + updateDomainList(updatedDomains); + }); + }); + + li.appendChild(deleteButton); + domainList.appendChild(li); + }); + } + + + // Add domain button click event + addDomainButton.addEventListener('click', function() { + const domain = domainInput.value.trim(); + + if (domain !== '') { + // Update the list of domains + browser.storage.sync.get('domains', function(data) { + const domains = data.domains || []; + domains.push(domain); + + // Save the updated list + browser.storage.sync.set({ 'domains': domains }, function() { + // Update the displayed list + updateDomainList(domains); + + // Clear the input field + domainInput.value = ''; + }); + }); + } + }); +}); -- cgit v1.2.3