-
Notifications
You must be signed in to change notification settings - Fork 1
/
passwordProtectedPages.js
58 lines (47 loc) · 2.09 KB
/
passwordProtectedPages.js
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
let enabled = true;
let passwordProtectedPages = {
"BasicProgramming/RPSCodeAlong.md": "junkenpo",
"Collections/ScoreSortCodeAlong.md": "welikesports",
"Database/RestaurantReviewCodeAlong.md": "reviewrevue",
"Flask/FlaskCodeAlong.md": "hahahaha",
"HelloPython/TurtleCodeAlong.md": "masterofdisguise",
"PyGame/TopDownCodeAlong.md": "link2thepast",
"WebScraping/InfoFinderCodeAlong.md": "harrystyles",
}
document.addEventListener('DOMContentLoaded', function() {
function addPassword(pw) {
let containerSection = document.querySelector("section");
let containerParent = containerSection.parentElement;
containerSection.style.display = "none";
let formDiv = document.createElement("div");
formDiv.setAttribute("id", "password-form");
let passwordHeader = document.createElement("h2");
passwordHeader.innerHTML = "Password Protected Page";
let passwordMessage = document.createElement("p");
passwordMessage.innerHTML = "Please enter a password to continue.";
let passwordInput = document.createElement("input");
passwordInput.setAttribute("type", "text");
passwordInput.setAttribute("id", "password-input");
let submitButton = document.createElement("button");
submitButton.innerHTML = "Submit";
submitButton.onclick = function () {
if (passwordInput.value == pw) {
containerSection.style.display = "block";
formDiv.style.display = "none";
} else {
alert("Wrong Password!!!");
}
}
formDiv.appendChild(passwordHeader);
formDiv.appendChild(passwordMessage);
formDiv.appendChild(passwordInput);
formDiv.appendChild(submitButton);
containerParent.appendChild(formDiv);
}
gitbook.events.bind("page.change", function() {
let passwordForCurrentPage = passwordProtectedPages[gitbook.state.filepath];
if (enabled && passwordForCurrentPage) {
addPassword(passwordForCurrentPage);
}
});
});