-
Notifications
You must be signed in to change notification settings - Fork 4
/
AuthPopup.astro
65 lines (59 loc) · 1.8 KB
/
AuthPopup.astro
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
<div
id="authPopup"
class="hidden fixed inset-0 items-center justify-center bg-black bg-opacity-70 z-50"
>
<div
class="backdrop-blur-4xl px-20 py-20 rounded-lg border border-white shadow-md text-center relative"
>
<button
id="closePopup"
class="absolute top-0 right-0 mt-2 mr-6 text-white text-4xl"
>×</button
>
<p id="popupText" class="text-white text-4xl tracking-widest">
<slot />
</p>
<button
id="copyTextButton"
class="mt-4 bg-white text-black px-4 py-2 rounded-md">Copy Code</button
>
</div>
</div>
<script>
const authPopup = document.getElementById("authPopup");
const copyTextButton = document.getElementById("copyTextButton");
const closePopupButton = document.getElementById("closePopup");
copyTextButton?.addEventListener("click", function (event) {
event.stopPropagation();
copyTextToClipboard();
});
closePopupButton?.addEventListener("click", function (event) {
authPopup?.classList.add("hidden");
});
function copyTextToClipboard() {
const popupText = document.getElementById("popupText");
if (popupText) {
const textToCopy = popupText.textContent;
if (textToCopy) {
navigator.clipboard
.writeText(textToCopy)
.then(() =>
copyTextButton ? (copyTextButton.textContent = "Copied!") : {}
);
}
}
}
const url = new URL(window.location.href);
const paramName = url.searchParams.get("code");
if (paramName && authPopup) {
const popupText = document.querySelector("#popupText");
if (popupText) {
popupText.textContent = paramName;
}
authPopup.classList.remove("hidden");
authPopup.classList.add("flex");
} else {
authPopup?.classList.add("hidden");
authPopup?.classList.remove("flex");
}
</script>