2023-11-23 08:53:28 +00:00
|
|
|
var accScale;
|
2023-11-26 07:37:29 +00:00
|
|
|
var accWidth;
|
2023-11-23 08:53:28 +00:00
|
|
|
var accBase;
|
|
|
|
|
|
|
|
function createAccessibilityNodes() {
|
|
|
|
document.querySelector("#accessibility").innerHTML = `<fieldset>
|
|
|
|
<legend>Accessibility controls</legend>
|
2023-11-26 07:37:29 +00:00
|
|
|
<label for="acc-scale">
|
2023-11-23 08:53:28 +00:00
|
|
|
<input
|
|
|
|
id="acc-scale"
|
|
|
|
type="number"
|
|
|
|
style="width: 8ch"
|
|
|
|
min="8"
|
|
|
|
max="48"
|
|
|
|
value="16"
|
|
|
|
/>
|
|
|
|
UI scale</label><br />
|
2023-11-26 07:37:29 +00:00
|
|
|
<label for="acc-width">
|
|
|
|
<input
|
|
|
|
id="acc-width"
|
|
|
|
type="number"
|
|
|
|
style="width: 8ch"
|
|
|
|
min="30"
|
|
|
|
max="100"
|
|
|
|
value="40"
|
|
|
|
/>
|
|
|
|
Page width</label><br />
|
2023-11-23 08:53:28 +00:00
|
|
|
<label for="acc-base" class="checkbox">
|
|
|
|
<input id="acc-base" type="checkbox" id="acc-base" />
|
2023-11-25 05:09:23 +00:00
|
|
|
<span class="checkbox">✓</span>
|
2023-11-23 08:53:28 +00:00
|
|
|
Base style (requires reload)
|
|
|
|
</label>
|
|
|
|
</fieldset>`;
|
2023-11-23 17:33:47 +00:00
|
|
|
document.querySelector("#accessibility").hidden = false;
|
2023-11-23 08:53:28 +00:00
|
|
|
|
|
|
|
accScale = document.getElementById("acc-scale");
|
2023-11-26 07:37:29 +00:00
|
|
|
accWidth = document.getElementById("acc-width");
|
2023-11-23 08:53:28 +00:00
|
|
|
accBase = document.getElementById("acc-base");
|
|
|
|
|
|
|
|
accScale.addEventListener("change", function (e) {
|
|
|
|
window.localStorage.setItem("acc-scale", e.target.value);
|
|
|
|
changeScale(e.target.value);
|
|
|
|
});
|
|
|
|
|
2023-11-26 07:37:29 +00:00
|
|
|
accWidth.addEventListener("change", function (e) {
|
|
|
|
window.localStorage.setItem("acc-width", e.target.value);
|
|
|
|
changeWidth(e.target.value);
|
|
|
|
});
|
|
|
|
|
2023-11-23 08:53:28 +00:00
|
|
|
accBase.addEventListener("change", function (e) {
|
|
|
|
window.localStorage.setItem("acc-base", e.target.checked);
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", (e) => initializeChanges(e, true));
|
|
|
|
|
|
|
|
// on localStorage change
|
|
|
|
window.addEventListener("storage", initializeChanges);
|
|
|
|
|
|
|
|
let prevBase; // previous base, for reload check
|
|
|
|
|
|
|
|
function initializeChanges(_, loading) {
|
|
|
|
if (window.frameElement == null) createAccessibilityNodes();
|
|
|
|
|
2023-11-26 07:37:29 +00:00
|
|
|
let scale = window.localStorage.getItem("acc-scale");
|
|
|
|
if (scale == null) {
|
|
|
|
window.localStorage.setItem("acc-scale", 16);
|
|
|
|
scale = window.localStorage.getItem("acc-scale");
|
|
|
|
}
|
|
|
|
let width = window.localStorage.getItem("acc-width");
|
|
|
|
if (width == null) {
|
|
|
|
window.localStorage.setItem("acc-width", 40);
|
|
|
|
width = window.localStorage.getItem("acc-width");
|
|
|
|
}
|
|
|
|
let base = window.localStorage.getItem("acc-base");
|
|
|
|
if (base == null) {
|
|
|
|
window.localStorage.setItem("acc-base", false);
|
|
|
|
base = window.localStorage.getItem("acc-base");
|
|
|
|
}
|
2023-11-23 08:53:28 +00:00
|
|
|
changeScale(scale);
|
2023-11-26 07:37:29 +00:00
|
|
|
changeWidth(width);
|
2023-11-23 08:53:28 +00:00
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
prevBase = base;
|
|
|
|
changeBase(base === "true");
|
|
|
|
} else if (base != prevBase) window.location.reload();
|
|
|
|
|
|
|
|
if (scale != null && accScale != null) accScale.value = scale;
|
2023-11-26 07:37:29 +00:00
|
|
|
if (width != null && accWidth != null) accWidth.value = width;
|
2023-11-23 08:53:28 +00:00
|
|
|
if (base != null && accBase != null) accBase.checked = base === "true";
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeScale(scale) {
|
|
|
|
document.documentElement.style.setProperty("--base-scale", scale + "px");
|
|
|
|
}
|
|
|
|
|
2023-11-26 07:37:29 +00:00
|
|
|
function changeWidth(width) {
|
|
|
|
document.documentElement.style.setProperty("--document-width", width + "em");
|
|
|
|
}
|
|
|
|
|
2023-11-23 08:53:28 +00:00
|
|
|
function changeBase(base) {
|
|
|
|
if (base) document.documentElement.classList.add("base");
|
|
|
|
else document.documentElement.classList.remove("base");
|
|
|
|
}
|