-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path404.html
39 lines (35 loc) · 1.47 KB
/
404.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
<script src="/firebaseConfig.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.4.3/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.4.3/firebase-firestore.js"></script>
<script>
localStorage.clear();
console.clear();
var fullURL = window.location.href;
var urlBehindRoot = fullURL.replace(window.location.origin + "/", '');
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
db.collection("links").where("name", "==", urlBehindRoot)
.get()
.then((querySnapshot) => {
if (querySnapshot.size > 0) {
querySnapshot.forEach((doc) => {
const url = doc.data().url;
let redirect = url;
if (!redirect.startsWith("https://")) {
redirect = "https://" + redirect;
window.location.href = redirect;
}
if (redirect.includes("http://")) {
redirect = redirect.replace("http://", "https://");
window.location.href = redirect;
}
window.location.href = redirect;
});
} else {
console.log("No document found for the given name");
}
})
.catch((error) => {
console.log("Error getting documents: ", error);
});
</script>