-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
116 lines (99 loc) · 3.05 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<head>
<link rel="stylesheet" href="style.css" />
<title>OBSN invite link generator</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="step">
<p id="stepNumber">1</p>
<h2 id="stepTitle"></h2>
<h3 id="stepDescription"></h3>
<div id="stepAnswers"></div>
</div>
<div id="progressAndLink">
<div id="progressContainer">
<div id="progress">0%</div>
</div>
<div id="link">
<div id="finalUrl">https://obs.ninja/</div>
</div>
</div>
</body>
<script>
function makeid(length) {
var result = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
var randomId = makeid(10);
var steps;
var currentStep;
var finalUrl = "https://obs.ninja/";
let url = "data.json";
fetch(url)
.then((res) => res.json())
.then((out) => {
steps = out;
printStep(0);
})
.catch((err) => {
throw err;
});
function printStep(index) {
if (index == steps.length) {
document.getElementById('step').innerHTML = `
<h1>Here's your URL</h1>
<a id='outputUrl' href='${finalUrl}'>${finalUrl}</a>`;
document.getElementById("progress").style.width = "100%";
document.getElementById("progress").innerText = "Done!";
document.getElementById("link").outerHTML= "";
}
var percentComplete = (index / steps.length) * 100;
item = steps[index];
document.getElementById("stepTitle").innerText = item.title;
document.getElementById("stepDescription").innerText = item.description;
document.getElementById("stepAnswers").innerHTML = null;
if (index == 0) {
document.getElementById("progress").style.width = "7%";
} else {
document.getElementById("progress").style.width = percentComplete + "%";
}
document.getElementById("progress").innerText =
index + 1 + " / " + Number.parseInt(steps.length + 1);
currentStep = index;
item.answers.forEach(function (answer) {
var el;
if (answer.type == "button") {
el = document.createElement("a");
el.setAttribute("data-value", answer.params);
el.innerText = answer.label;
el.onclick = function () {
if (answer.params == "?push=") {
answer.params = answer.params + randomId;
}
finalUrl = finalUrl + answer.params;
document.getElementById("finalUrl").innerText = finalUrl;
document.getElementById("stepNumber").innerText = index + 2;
printStep(index + 1);
};
} else {
el = document.createElement("input");
el.setAttribute("placeholder", answer.label);
el.onkeyup = function (e) {
if (e.keyCode == 13) {
finalUrl = finalUrl + answer.params + el.value;
document.getElementById("finalUrl").innerText = finalUrl;
document.getElementById("stepNumber").innerText = index + 2;
printStep(index + 1);
}
};
}
document.getElementById("stepAnswers").appendChild(el);
});
}
</script>