summaryrefslogtreecommitdiff
path: root/options.js
blob: aa33ea1216c7902830e189e5161d04496c23e2bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 = '';
        });
      });
    }
  });
});