diff options
author | Christian Segundo | 2023-11-19 16:21:29 +0100 |
---|---|---|
committer | Christian Segundo | 2023-11-19 16:21:29 +0100 |
commit | c6845a798c99e96aa0e2f6daece0684a8ac50681 (patch) | |
tree | a75eec68984bcb7ff8f8c5f048b4806d5cb4ff5a /options.js | |
parent | d880836621f0b4b4ca036e62e34d6edc74b61e81 (diff) | |
download | moz-run-this-page-action-c6845a798c99e96aa0e2f6daece0684a8ac50681.tar.gz |
wip
Diffstat (limited to 'options.js')
-rw-r--r-- | options.js | 61 |
1 files changed, 61 insertions, 0 deletions
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 = ''; + }); + }); + } + }); +}); |