|
1 | 1 | import loadPolicy from '../loadPolicy'
|
2 | 2 |
|
| 3 | +const showSuccessMessage = () => { |
| 4 | + var animateIn = document.getElementById("notification") |
| 5 | + animateIn.className = "show" |
| 6 | + setTimeout(function(){ |
| 7 | + animateIn.className = animateIn.className.replace("show", "") |
| 8 | + }, 3000) |
| 9 | +} |
| 10 | + |
| 11 | +const showJoinedCampaigns = () => { |
| 12 | + chrome.storage.sync.get(['policy'], (value) => { |
| 13 | + if (value.policy) { |
| 14 | + const campaignsEl = document.getElementById('campaigns') |
| 15 | + campaignsEl.innerText = `Your campaign: \n${value.policy.name}` |
| 16 | + campaignsEl.className = "campaigns" |
| 17 | + } |
| 18 | + }) |
| 19 | +} |
| 20 | + |
| 21 | +const submitForm = (ev) => { |
| 22 | + ev.preventDefault() |
| 23 | + const policyFileUrl = new FormData(policyFileForm).get('policyFile') |
| 24 | + loadPolicy(policyFileUrl) |
| 25 | + .then(showSuccessMessage) |
| 26 | + .then(showJoinedCampaigns) |
| 27 | +} |
| 28 | + |
3 | 29 | document.addEventListener('DOMContentLoaded', () => {
|
4 | 30 | const policyFileForm = document.getElementById('policyFileForm')
|
5 |
| - policyFileForm.addEventListener('submit', (ev) => { |
6 |
| - ev.preventDefault(); |
7 |
| - const policyFileUrl = new FormData(policyFileForm).get('policyFile') |
8 |
| - loadPolicy(policyFileUrl) |
9 |
| - .then(e => { |
10 |
| - var animateIn = document.getElementById("notification"); |
11 |
| - animateIn.className = "show"; |
12 |
| - setTimeout(function(){ |
13 |
| - animateIn.className = animateIn.className.replace("show", ""); |
14 |
| - }, 3000); |
15 |
| - e.preventDefault(); |
16 |
| - }) |
17 |
| - }) |
| 31 | + |
| 32 | + policyFileForm.addEventListener('submit', submitForm) |
| 33 | + showJoinedCampaigns() |
18 | 34 | })
|
0 commit comments