|
|
|
@ -103,6 +103,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
const image = document.getElementById("webcamimage");
|
|
|
|
const image = document.getElementById("webcamimage");
|
|
|
|
|
|
|
|
const previewStage = document.querySelector(".preview-stage");
|
|
|
|
const controlsElement = document.getElementById("controls");
|
|
|
|
const controlsElement = document.getElementById("controls");
|
|
|
|
const variablesElement = document.getElementById("variables");
|
|
|
|
const variablesElement = document.getElementById("variables");
|
|
|
|
const notice = document.getElementById("notice");
|
|
|
|
const notice = document.getElementById("notice");
|
|
|
|
@ -112,6 +113,11 @@
|
|
|
|
let filterEnabled = false;
|
|
|
|
let filterEnabled = false;
|
|
|
|
let refreshCount = 0;
|
|
|
|
let refreshCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setPreviewAspectRatio() {
|
|
|
|
|
|
|
|
if (!previewStage || !image.naturalWidth || !image.naturalHeight) return;
|
|
|
|
|
|
|
|
previewStage.style.setProperty("--preview-ratio", image.naturalWidth + " / " + image.naturalHeight);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function post(url) {
|
|
|
|
function post(url) {
|
|
|
|
return fetch(url, { method: "POST" }).then(function(response) {
|
|
|
|
return fetch(url, { method: "POST" }).then(function(response) {
|
|
|
|
if (!response.ok) throw new Error("Request failed: " + response.status);
|
|
|
|
if (!response.ok) throw new Error("Request failed: " + response.status);
|
|
|
|
@ -142,6 +148,7 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
image.addEventListener("load", function() {
|
|
|
|
image.addEventListener("load", function() {
|
|
|
|
|
|
|
|
setPreviewAspectRatio();
|
|
|
|
document.getElementById("preview-error").hidden = true;
|
|
|
|
document.getElementById("preview-error").hidden = true;
|
|
|
|
document.getElementById("last-updated").textContent =
|
|
|
|
document.getElementById("last-updated").textContent =
|
|
|
|
"Updated " + new Date().toLocaleTimeString();
|
|
|
|
"Updated " + new Date().toLocaleTimeString();
|
|
|
|
@ -286,7 +293,8 @@
|
|
|
|
const data = JSON.parse(response);
|
|
|
|
const data = JSON.parse(response);
|
|
|
|
const variables = data.variables || [];
|
|
|
|
const variables = data.variables || [];
|
|
|
|
const activeName = document.activeElement &&
|
|
|
|
const activeName = document.activeElement &&
|
|
|
|
document.activeElement.classList.contains("variable-value")
|
|
|
|
(document.activeElement.classList.contains("variable-value") ||
|
|
|
|
|
|
|
|
document.activeElement.classList.contains("variable-slider"))
|
|
|
|
? document.activeElement.dataset.name
|
|
|
|
? document.activeElement.dataset.name
|
|
|
|
: null;
|
|
|
|
: null;
|
|
|
|
if (activeName !== null) return;
|
|
|
|
if (activeName !== null) return;
|
|
|
|
@ -312,13 +320,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
const editor = document.createElement("div");
|
|
|
|
const editor = document.createElement("div");
|
|
|
|
editor.className = "setting-editor";
|
|
|
|
editor.className = "setting-editor";
|
|
|
|
const input = document.createElement("input");
|
|
|
|
const isControlId = variable.name === "auto_brightness";
|
|
|
|
|
|
|
|
const isRatio = variable.name === "filter_ratio" ||
|
|
|
|
|
|
|
|
variable.name === "auto_brightness_target";
|
|
|
|
|
|
|
|
const input = document.createElement(isControlId ? "select" : "input");
|
|
|
|
input.className = "variable-value";
|
|
|
|
input.className = "variable-value";
|
|
|
|
|
|
|
|
input.dataset.name = variable.name;
|
|
|
|
|
|
|
|
input.setAttribute("aria-label", variable.name + " value");
|
|
|
|
|
|
|
|
if (isControlId) {
|
|
|
|
|
|
|
|
const currentId = String(variable.value);
|
|
|
|
|
|
|
|
const disabledOption = document.createElement("option");
|
|
|
|
|
|
|
|
disabledOption.value = "0";
|
|
|
|
|
|
|
|
disabledOption.textContent = "Disabled (ID: 0)";
|
|
|
|
|
|
|
|
input.appendChild(disabledOption);
|
|
|
|
|
|
|
|
if (currentId !== "0" && !controls.some(function(control) {
|
|
|
|
|
|
|
|
return String(control.id) === currentId;
|
|
|
|
|
|
|
|
})) {
|
|
|
|
|
|
|
|
const currentOption = document.createElement("option");
|
|
|
|
|
|
|
|
currentOption.value = currentId;
|
|
|
|
|
|
|
|
currentOption.textContent = "Unavailable control (ID: " + currentId + ")";
|
|
|
|
|
|
|
|
input.appendChild(currentOption);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
controls.forEach(function(control) {
|
|
|
|
|
|
|
|
if (String(control.id) === "0") return;
|
|
|
|
|
|
|
|
const option = document.createElement("option");
|
|
|
|
|
|
|
|
option.value = String(control.id);
|
|
|
|
|
|
|
|
option.textContent = control.name + " (ID: " + control.id + ")";
|
|
|
|
|
|
|
|
input.appendChild(option);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
input.value = currentId;
|
|
|
|
|
|
|
|
} else if (isRatio) {
|
|
|
|
|
|
|
|
const slider = document.createElement("input");
|
|
|
|
|
|
|
|
slider.className = "control-slider variable-slider";
|
|
|
|
|
|
|
|
slider.type = "range";
|
|
|
|
|
|
|
|
slider.min = "0";
|
|
|
|
|
|
|
|
slider.max = "1";
|
|
|
|
|
|
|
|
slider.step = "0.01";
|
|
|
|
|
|
|
|
slider.value = variable.value;
|
|
|
|
|
|
|
|
slider.dataset.name = variable.name;
|
|
|
|
|
|
|
|
slider.setAttribute("aria-label", variable.name + " slider");
|
|
|
|
|
|
|
|
|
|
|
|
input.type = "number";
|
|
|
|
input.type = "number";
|
|
|
|
input.step = "any";
|
|
|
|
input.min = "0";
|
|
|
|
|
|
|
|
input.max = "1";
|
|
|
|
|
|
|
|
input.step = "0.01";
|
|
|
|
input.value = variable.value;
|
|
|
|
input.value = variable.value;
|
|
|
|
input.dataset.name = variable.name;
|
|
|
|
|
|
|
|
input.setAttribute("aria-label", variable.name + " value");
|
|
|
|
input.setAttribute("aria-label", variable.name + " value");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let submitTimeout;
|
|
|
|
|
|
|
|
slider.addEventListener("input", function() {
|
|
|
|
|
|
|
|
input.value = slider.value;
|
|
|
|
|
|
|
|
window.clearTimeout(submitTimeout);
|
|
|
|
|
|
|
|
submitTimeout = window.setTimeout(function() {
|
|
|
|
|
|
|
|
submitVariable(input);
|
|
|
|
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
slider.addEventListener("change", function() {
|
|
|
|
|
|
|
|
window.clearTimeout(submitTimeout);
|
|
|
|
|
|
|
|
submitVariable(input);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
input.addEventListener("input", function() {
|
|
|
|
|
|
|
|
slider.value = input.value;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
editor.classList.add("setting-slider-editor");
|
|
|
|
|
|
|
|
editor.append(slider);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
input.type = "number";
|
|
|
|
|
|
|
|
input.step = "any";
|
|
|
|
|
|
|
|
input.value = variable.value;
|
|
|
|
|
|
|
|
}
|
|
|
|
const apply = document.createElement("button");
|
|
|
|
const apply = document.createElement("button");
|
|
|
|
apply.className = "button button-small";
|
|
|
|
apply.className = "button button-small";
|
|
|
|
apply.type = "button";
|
|
|
|
apply.type = "button";
|
|
|
|
@ -384,13 +454,11 @@
|
|
|
|
function refresh() {
|
|
|
|
function refresh() {
|
|
|
|
reloadImage();
|
|
|
|
reloadImage();
|
|
|
|
if (refreshCount++ % 25 === 0) {
|
|
|
|
if (refreshCount++ % 25 === 0) {
|
|
|
|
refreshCtrls();
|
|
|
|
refreshCtrls().then(refreshVariables);
|
|
|
|
refreshVariables();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
refreshCtrls();
|
|
|
|
refreshCtrls().then(refreshVariables);
|
|
|
|
refreshVariables();
|
|
|
|
|
|
|
|
window.setInterval(refresh, 500);
|
|
|
|
window.setInterval(refresh, 500);
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</body>
|
|
|
|
|