|
1 | | -const elEmail = document.querySelector('.js-email'); |
2 | | -const submit = document.querySelector('button'); |
3 | | -const label = document.querySelector('label'); |
4 | | - |
5 | | -const params = new URLSearchParams(location.search); |
6 | | -elEmail.textContent = params.get('email'); |
7 | | - |
8 | | -submit.addEventListener('click', async (e) => { |
9 | | - e.preventDefault(); |
10 | | - label.textContent = ''; |
11 | | - const email = params.get('email'); |
12 | | - const key = params.get('key'); |
13 | | - if (email.includes('@') && key) { |
14 | | - submit.classList.add('button-loading'); |
15 | | - setTimeout(() => { |
16 | | - document.addEventListener('__darkreader_activationResult__', (e) => { |
17 | | - const {result} = e.detail; |
18 | | - if (result) { |
19 | | - submit.classList.add('button-success'); |
20 | | - submit.textContent = 'Complete'; |
21 | | - } else { |
22 | | - submit.classList.add('button-failure'); |
23 | | - submit.textContent = 'Error'; |
24 | | - } |
25 | | - }); |
26 | | - document.dispatchEvent(new CustomEvent('__darkreader_activate__', {detail: {email, key}})); |
27 | | - }, 2000 + Math.round(500 * Math.random())); |
| 1 | +function run() { |
| 2 | + const elEmail = document.querySelector('.js-email'); |
| 3 | + const submit = document.querySelector('button'); |
| 4 | + const label = document.querySelector('label'); |
| 5 | + |
| 6 | + if (!navigator.userAgent.includes('Edg')) { |
| 7 | + /** @type {HTMLElement} */ |
| 8 | + const edgeProblemBlock = document.querySelector('.js-edge-problem-block'); |
| 9 | + edgeProblemBlock.style.display = ''; |
| 10 | + |
| 11 | + /** @type {HTMLAnchorElement} */ |
| 12 | + const edgeLink = document.querySelector('.js-edge-link'); |
| 13 | + edgeLink.href = location.href; |
| 14 | + |
| 15 | + /** @type {HTMLElement} */ |
| 16 | + const form = document.querySelector('.js-form'); |
| 17 | + form.style.display = 'none'; |
| 18 | + |
| 19 | + /** @type {HTMLElement} */ |
| 20 | + const contacts = document.querySelector('.js-contacts'); |
| 21 | + contacts.style.display = 'none'; |
| 22 | + |
| 23 | + /** @type {HTMLElement} */ |
| 24 | + const footer = document.querySelector('footer'); |
| 25 | + footer.style.backgroundColor = 'inherit'; |
| 26 | + |
| 27 | + /** @type {HTMLButtonElement} */ |
| 28 | + const copyButton = document.querySelector('.js-copy'); |
| 29 | + copyButton.addEventListener('click', () => { |
| 30 | + const input = document.createElement('input'); |
| 31 | + input.value = location.href; |
| 32 | + document.body.append(input); |
| 33 | + input.select(); |
| 34 | + document.execCommand('copy'); |
| 35 | + input.remove(); |
| 36 | + |
| 37 | + copyButton.textContent = 'Copied'; |
| 38 | + copyButton.classList.add('copy-button--copied'); |
| 39 | + }); |
| 40 | + footer.style.backgroundColor = 'inherit'; |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + const hash = location.hash; |
| 45 | + let email = ''; |
| 46 | + let key = ''; |
| 47 | + if (hash.startsWith('#v1=')) { |
| 48 | + [email, key] = atob(hash.slice(4)).split('::'); |
| 49 | + elEmail.textContent = email; |
| 50 | + location.hash = ''; |
| 51 | + history.pushState('', document.title, location.pathname); |
28 | 52 | } |
29 | | -}); |
| 53 | + |
| 54 | + submit.addEventListener('click', async (e) => { |
| 55 | + e.preventDefault(); |
| 56 | + label.textContent = ''; |
| 57 | + if (email.includes('@') && key) { |
| 58 | + submit.classList.add('button-loading'); |
| 59 | + setTimeout(() => { |
| 60 | + document.addEventListener('__darkreader_activationResult__', (e) => { |
| 61 | + const {result} = e.detail; |
| 62 | + if (result) { |
| 63 | + submit.classList.add('button-success'); |
| 64 | + submit.textContent = 'Complete'; |
| 65 | + } else { |
| 66 | + submit.classList.add('button-failure'); |
| 67 | + submit.textContent = 'Error'; |
| 68 | + } |
| 69 | + }); |
| 70 | + document.dispatchEvent(new CustomEvent('__darkreader_activate__', {detail: {email, key}})); |
| 71 | + }, 2000 + Math.round(500 * Math.random())); |
| 72 | + } |
| 73 | + }); |
| 74 | +} |
| 75 | + |
| 76 | +run(); |
0 commit comments