-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsubscribe.html
61 lines (47 loc) · 2.03 KB
/
unsubscribe.html
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
---
permalink: /unsubscribe/index.html
layout: default
---
<h1 class="text-center">Avslutt abonnement</h1>
<p id="instructions" class="text-center">Klikk på lenkja under for å avslutte abonnementet ditt.</p>
<div class="d-flex justify-content-center">
<a id="unsubscribe-button" class="btn btn-outline-primary" href="">Avslutt abonnement</a>
<div class="spinner-border text-primary m-5" role="status" id="unsubscribe-spinner" style="display: none;">
<span class="visually-hidden">Lastar...</span>
</div>
</div>
<div id="unsubscribe-message" class="text-center mt-3"></div>
<script>
const instructions = document.getElementById('instructions');
const unsubscribeButton = document.getElementById('unsubscribe-button');
const message = document.getElementById('unsubscribe-message');
const spinner = document.getElementById('unsubscribe-spinner');
let ran = false;
document.addEventListener('DOMContentLoaded', () => {
const token = new URLSearchParams(window.location.search).get('token');
unsubscribeButton.href = `{{ site.data.api.baseUrl }}/unsubscribe?token=${token}`;
unsubscribeButton.click();
});
unsubscribeButton.addEventListener('click', async (event) => {
event.preventDefault();
if (ran || !unsubscribeButton.href) {
return;
}
ran = true;
message.innerHTML = '';
spinner.style.display = 'block';
instructions.style.display = 'none';
unsubscribeButton.style.display = 'none';
const response = await fetch(unsubscribeButton.href);
spinner.style.display = 'none';
if (response.status === 200) {
message.innerHTML = 'Abonnementet ditt er avslutta. Du vil ikkje lenger motta e-post frå oss.';
} else if (response.status === 429) {
message.innerHTML = 'Du har vore for rask. Vennlegst prøv igjen om ei stund.';
} else if (response.status === 404) {
message.innerHTML = 'Kunne ikkje finne abonnementet ditt. Har du allereie avslutta?';
} else {
message.innerHTML = 'Noko gjekk gale. Vennlegst prøv igjen.';
}
});
</script>