-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
53 lines (43 loc) · 2.32 KB
/
script.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
document.addEventListener("DOMContentLoaded", () => {
// Set bit length upon change
document.getElementById("bit-length-control").addEventListener("change", (e) => {
document.querySelectorAll('[is=hex-input-list]').forEach(el => el.dataset.count = Math.ceil(e.target.dataset.value/4));
document.querySelectorAll('[is=id-table]').forEach(el => el.dataset.count = Math.ceil(e.target.dataset.value / 4));
});
// Trigger bit length event if refreshed
document.querySelectorAll("input[name=bit-length]").forEach(radio => {
if (radio.checked) radio.dispatchEvent(new Event("change", { bubbles: true }));
});
// Set range-offset upon change
document.getElementById('table-offset').addEventListener("change", e => {
if (e.target.value == "" || e.target.valueAsNumber < 0) e.target.value = "0";
document.querySelectorAll('[is=id-table]').forEach(el => {
el.dataset.offset = e.target.value;
});
});
// Set range-length upon change
document.getElementById('table-length').addEventListener("change", e => {
if (e.target.value == "" || e.target.valueAsNumber < 0) e.target.value = "0";
document.querySelectorAll('[is=id-table]').forEach(el => {
el.dataset.length = e.target.value;
});
});
// Trigger range change event if refreshed
[...document.getElementsByClassName('table-length-input')].forEach(el => el.dispatchEvent(new Event("change", { bubbles: true })));
// Event listeners for copy buttons
document.querySelectorAll(".copy-button").forEach(button => {
button.addEventListener("click", (e) => {
let input = document.createElement('input');
input.setAttribute('value', "0x"+[...e.target.previousElementSibling.children].slice(1).map(i => i.firstElementChild.value).join(""));
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
});
});
// Set focus to first input
document.getElementById("mask-input-list").children[1].firstElementChild.focus();
// Trigger input event
let inputEvent = new InputEvent("input", {bubbles: true});
document.getElementById("mask-input-list").children[1].firstElementChild.dispatchEvent(inputEvent);
});