forked from mirrors/bookwyrm
Prettier
This commit is contained in:
parent
789626a9da
commit
fbe7e860e8
1 changed files with 89 additions and 70 deletions
|
@ -431,11 +431,11 @@ let BookWyrm = new (class {
|
|||
});
|
||||
|
||||
modalElement.addEventListener("keydown", handleFocusTrap);
|
||||
modalElement.dispatchEvent(new Event('open'));
|
||||
modalElement.dispatchEvent(new Event("open"));
|
||||
}
|
||||
|
||||
function handleModalClose(modalElement) {
|
||||
modalElement.dispatchEvent(new Event('close'));
|
||||
modalElement.dispatchEvent(new Event("close"));
|
||||
modalElement.removeEventListener("keydown", handleFocusTrap);
|
||||
htmlElement.classList.remove("is-clipped");
|
||||
modalElement.classList.remove("is-active");
|
||||
|
@ -644,7 +644,7 @@ let BookWyrm = new (class {
|
|||
const statusNode = document.getElementById("barcode-status");
|
||||
const cameraListNode = document.querySelector("#barcode-camera-list > select");
|
||||
|
||||
cameraListNode.addEventListener('change', onChangeCamera);
|
||||
cameraListNode.addEventListener("change", onChangeCamera);
|
||||
|
||||
function onChangeCamera(event) {
|
||||
initBarcodes(event.target.value);
|
||||
|
@ -657,18 +657,19 @@ let BookWyrm = new (class {
|
|||
}
|
||||
|
||||
function initBarcodes(cameraId = null) {
|
||||
toggleStatus('grant-access');
|
||||
toggleStatus("grant-access");
|
||||
|
||||
if (!cameraId) {
|
||||
cameraId = sessionStorage.getItem('preferredCam');
|
||||
cameraId = sessionStorage.getItem("preferredCam");
|
||||
} else {
|
||||
sessionStorage.setItem('preferredCam', cameraId);
|
||||
sessionStorage.setItem("preferredCam", cameraId);
|
||||
}
|
||||
|
||||
scannerNode.replaceChildren();
|
||||
Quagga.stop();
|
||||
Quagga.init({
|
||||
inputStream : {
|
||||
Quagga.init(
|
||||
{
|
||||
inputStream: {
|
||||
name: "Live",
|
||||
type: "LiveStream",
|
||||
target: scannerNode,
|
||||
|
@ -677,23 +678,24 @@ let BookWyrm = new (class {
|
|||
deviceId: cameraId,
|
||||
},
|
||||
},
|
||||
decoder : {
|
||||
decoder: {
|
||||
readers: [
|
||||
"ean_reader",
|
||||
{
|
||||
format: "ean_reader",
|
||||
config: {
|
||||
supplements: [ "ean_2_reader", "ean_5_reader" ]
|
||||
}
|
||||
}
|
||||
],
|
||||
multiple: false
|
||||
supplements: ["ean_2_reader", "ean_5_reader"],
|
||||
},
|
||||
}, (err) => {
|
||||
},
|
||||
],
|
||||
multiple: false,
|
||||
},
|
||||
},
|
||||
(err) => {
|
||||
if (err) {
|
||||
scannerNode.replaceChildren();
|
||||
console.log(err);
|
||||
toggleStatus('access-denied');
|
||||
toggleStatus("access-denied");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -707,7 +709,7 @@ let BookWyrm = new (class {
|
|||
cameraListNode.replaceChildren();
|
||||
|
||||
for (const device of devices) {
|
||||
const child = document.createElement('option');
|
||||
const child = document.createElement("option");
|
||||
child.value = device.deviceId;
|
||||
child.innerText = device.label.slice(0, 30);
|
||||
|
||||
|
@ -719,14 +721,15 @@ let BookWyrm = new (class {
|
|||
}
|
||||
});
|
||||
|
||||
toggleStatus('scanning');
|
||||
toggleStatus("scanning");
|
||||
Quagga.start();
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function cleanup(clearDrawing = true) {
|
||||
Quagga.stop();
|
||||
cameraListNode.removeEventListener('change', onChangeCamera);
|
||||
cameraListNode.removeEventListener("change", onChangeCamera);
|
||||
|
||||
if (clearDrawing) {
|
||||
scannerNode.replaceChildren();
|
||||
|
@ -739,18 +742,34 @@ let BookWyrm = new (class {
|
|||
|
||||
if (result) {
|
||||
if (result.boxes) {
|
||||
drawingCtx.clearRect(0, 0, parseInt(drawingCanvas.getAttribute("width")), parseInt(drawingCanvas.getAttribute("height")));
|
||||
result.boxes.filter((box) => box !== result.box).forEach((box) => {
|
||||
Quagga.ImageDebug.drawPath(box, {x: 0, y: 1}, drawingCtx, {color: "green", lineWidth: 2});
|
||||
drawingCtx.clearRect(
|
||||
0,
|
||||
0,
|
||||
parseInt(drawingCanvas.getAttribute("width")),
|
||||
parseInt(drawingCanvas.getAttribute("height"))
|
||||
);
|
||||
result.boxes
|
||||
.filter((box) => box !== result.box)
|
||||
.forEach((box) => {
|
||||
Quagga.ImageDebug.drawPath(box, { x: 0, y: 1 }, drawingCtx, {
|
||||
color: "green",
|
||||
lineWidth: 2,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (result.box) {
|
||||
Quagga.ImageDebug.drawPath(result.box, {x: 0, y: 1}, drawingCtx, {color: "#00F", lineWidth: 2});
|
||||
Quagga.ImageDebug.drawPath(result.box, { x: 0, y: 1 }, drawingCtx, {
|
||||
color: "#00F",
|
||||
lineWidth: 2,
|
||||
});
|
||||
}
|
||||
|
||||
if (result.codeResult && result.codeResult.code) {
|
||||
Quagga.ImageDebug.drawPath(result.line, {x: 'x', y: 'y'}, drawingCtx, {color: 'red', lineWidth: 3});
|
||||
Quagga.ImageDebug.drawPath(result.line, { x: "x", y: "y" }, drawingCtx, {
|
||||
color: "red",
|
||||
lineWidth: 3,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -769,17 +788,17 @@ let BookWyrm = new (class {
|
|||
|
||||
const code = result.codeResult.code;
|
||||
|
||||
statusNode.querySelector('.isbn').innerText = code;
|
||||
toggleStatus('found');
|
||||
statusNode.querySelector(".isbn").innerText = code;
|
||||
toggleStatus("found");
|
||||
|
||||
const search = new URL('/search', document.location);
|
||||
search.searchParams.set('q', code);
|
||||
const search = new URL("/search", document.location);
|
||||
search.searchParams.set("q", code);
|
||||
|
||||
cleanup(false);
|
||||
location.assign(search);
|
||||
});
|
||||
|
||||
event.target.addEventListener('close', cleanup, { once: true });
|
||||
event.target.addEventListener("close", cleanup, { once: true });
|
||||
|
||||
initBarcodes();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue