-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (60 loc) · 2.31 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const createHostingInfoData = (elmTr, val) => {
const elmTd = document.createElement("td");
const textNode = document.createTextNode(val);
elmTd.appendChild(textNode);
elmTr.appendChild(elmTd);
};
document.getElementById("decode").addEventListener("click", () => {
createTable();
document.getElementById("decode").disabled = true;
});
document
.getElementById("clear")
.addEventListener("click", (e) => location.reload());
const createTable = () => {
const elmTextarea = document.getElementById("url");
const elmUrl = elmTextarea.value;
const elmParameters = document.getElementById("parameters");
const decodedUrl = decodeURIComponent(elmUrl);
const urlParams = decodedUrl.split(/[&?]/i);
const elmThead = document.createElement("thead");
const elmTbody = document.createElement("tbody");
const elmTr = document.createElement("tr");
const dContainer = document.querySelector(".d-container");
dContainer.style.height = "400px";
elmThead.append(elmTr);
const columnNames = ["name", "value", ""];
for (let i = 0; i < columnNames.length; i++) {
const elmTh = document.createElement("th");
elmTh.classList.add("col");
elmTh.innerText = columnNames[i];
elmTr.appendChild(elmTh);
}
elmParameters.appendChild(elmThead);
for (let i = 1; i < urlParams.length; i++) {
const elmTr = document.createElement("tr");
let splitData = urlParams[i].split("=");
for (let j = 0; j < 3; j++) {
const elmTd = document.createElement("td");
const elmInput = document.createElement("input");
elmInput.setAttribute("name", `param-${j}`);
elmInput.setAttribute("value", splitData[j]);
elmInput.classList.add("param");
const elmBtn = document.createElement("button");
elmBtn.id = `btn-${i}`;
elmBtn.classList.add("btn", "btn-success", "d-grid", "mx-auto");
elmBtn.innerText = "copy";
j < 2 ? elmTd.append(elmInput) : elmTd.appendChild(elmBtn);
elmTr.append(elmTd);
elmBtn.addEventListener("click", () => {
const parentElm = elmBtn.parentNode.parentNode;
const firstChildElm = parentElm.firstChild;
const siblingElm = firstChildElm.nextSibling.firstChild;
siblingElm.select();
document.execCommand("copy");
});
}
elmTbody.append(elmTr);
}
elmParameters.appendChild(elmTbody);
};