forked from zachleat/speedlify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exclude.njk
76 lines (71 loc) · 2.77 KB
/
exclude.njk
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
layout: layout.njk
---
<div class="container mt-24 text-center">
<h1 class="text-5xl font-black dark:text-gray-100">Plausible Exclude</h1>
<div class="my-4 text-xl dark:text-gray-100">
Click the button below to toggle your exclusion in analytics for this
site
</div>
<div class="my-4 text-xl dark:text-gray-100">
You currently <span
class="font-bold text-red-600 dark:text-red-400"
id="plausible_not">are not</span>
<span
class="hidden font-bold text-green-600 dark:text-green-400"
id="plausible_yes">are</span>
excluding your visits.
</div>
<a
class="w-full rounded-lg bg-indigo-600 px-4 py-2 text-center text-base font-semibold text-white shadow-md transition duration-200 ease-in hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:ring-offset-indigo-200"
id="plausible_button">Exclude my visits</a
>
</div>
<style>
.hidden {
display: none;
}
</style>
<script>
window.addEventListener('load', function (e) {
var exclusionState = window.localStorage.plausible_ignore == 'true'
if (exclusionState) {
document.getElementById('plausible_not').classList.add('hidden')
document.getElementById('plausible_yes').classList.remove('hidden')
document.getElementById('plausible_button').innerHTML =
'Stop excluding my visits'
} else {
document.getElementById('plausible_yes').classList.add('hidden')
document.getElementById('plausible_not').classList.remove('hidden')
document.getElementById('plausible_button').innerHTML =
'Exclude my visits'
}
})
function toggleExclusion(e) {
var exclusionState = window.localStorage.plausible_ignore == 'true'
if (exclusionState) {
delete window.localStorage.plausible_ignore
document.getElementById('plausible_yes').classList.add('hidden')
document.getElementById('plausible_not').classList.remove('hidden')
document.getElementById('plausible_button').innerHTML =
'Exclude my visits'
} else {
window.localStorage.plausible_ignore = 'true'
document.getElementById('plausible_not').classList.add('hidden')
document.getElementById('plausible_yes').classList.remove('hidden')
document.getElementById('plausible_button').innerHTML =
'Stop excluding my visits'
}
}
function registerToggle() {
document
.querySelector('#plausible_button')
.addEventListener('click', toggleExclusion)
}
// Run once when page loads
if (document.readyState === 'complete') {
document.addEventListener('DOMContentLoaded', () => registerToggle())
} else {
document.addEventListener('DOMContentLoaded', () => registerToggle())
}
</script>