1
0
mirror of https://github.com/spacebarchat/docs.git synced 2024-09-19 23:21:40 +02:00

Allow viewing which bits make up a right in the calculator

This commit is contained in:
Madeline 2023-02-03 14:08:54 +11:00
parent 291e6f2d07
commit cc96ac3b46
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
2 changed files with 34 additions and 10 deletions

View File

@ -6,15 +6,30 @@
// grab the table data elements
[...document.querySelectorAll("td")]
.map((x) => x.innerText) // get their content
.map((x, i) =>
x.indexOf("<<") == 2 // if this column is the `value` column
? x.split(" ").reverse()[0] // get the value we shift by
: x,
); // otherwise dont do anything
.map(
(x, i) =>
x.indexOf("<<") == 2 // if this column is the `value` column
? x.split(" ").reverse()[0] // get the value we shift by
: x, // otherwise dont do anything
);
const mount = document.getElementById("rights-container");
const outputMount = document.getElementById("rights-output");
var calculated = 0n;
const calcBitsFromInput = () => {
const value = BigInt(outputMount.value);
calculated = value;
for (const div of mount.children) {
const toggle = div.children[0];
const flag = BigInt(toggle.getAttribute("id"));
toggle.checked = ((value >> flag) & 1n) != 0n;
}
};
outputMount.addEventListener("input", calcBitsFromInput);
for (var i = 0; i < rights.length; i += NUM_COLUMNS) {
const name = rights[i];
const shift = rights[i + 1];
@ -25,7 +40,7 @@
input.setAttribute("type", "checkbox");
input.setAttribute("id", shift);
const label = document.createElement("label");
label.setAttribute("for", label.id);
label.setAttribute("for", input.id);
label.innerText = name.toUpperCase();
div.appendChild(input);
@ -44,13 +59,14 @@
}
event.target.removeAttribute("disabled");
outputMount.innerText = "1";
calculated++;
outputMount.value = "1";
return;
} else {
for (var elem of mount.children) {
elem.children[0].removeAttribute("disabled");
}
outputMount.innerText = calculated;
outputMount.value = --calculated;
return;
}
}
@ -59,7 +75,10 @@
? calculated + value
: calculated - value;
outputMount.innerText = calculated;
outputMount.value = calculated;
});
}
// if you reload the page, your input is still present.
calcBitsFromInput();
})();

View File

@ -50,12 +50,17 @@ Operator rights currently grants access to the following, in addition to all rig
background-color: rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
#rights-output {
background-color: transparent;
border-bottom: 2px solid white;
}
</style>
<div id="rights-calculator">
<div id="rights-container"></div>
<div id="rights-output-container">
<p>Rights: <span id="rights-output"></span></p>
<p>Rights: <input id="rights-output"></input></p>
</div>
</div>