diff --git a/bookwyrm/static/css/bookwyrm/components/_barcode.scss b/bookwyrm/static/css/bookwyrm/components/_barcode.scss index da1aa721c..1abbf5d40 100644 --- a/bookwyrm/static/css/bookwyrm/components/_barcode.scss +++ b/bookwyrm/static/css/bookwyrm/components/_barcode.scss @@ -12,3 +12,13 @@ width: 100%; } } + +#barcode-status { + :dir(ltr) .select { + float: right; + } + + :dir(rtl) .select { + float: left; + } +} diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index d7ba9ffe0..4944ada65 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -655,10 +655,13 @@ let BookWyrm = new (class { } } - function cleanup() { + function cleanup(clearDrawing = true) { Quagga.stop(); - scannerNode.replaceChildren(); cameraListNode.removeEventListener('change', changeListener); + + if (clearDrawing) { + scannerNode.replaceChildren(); + } } Quagga.onProcessed((result) => { @@ -683,7 +686,14 @@ let BookWyrm = new (class { } }); + let lastDetection = null; Quagga.onDetected((result) => { + // Detect the same code twice as an extra check to avoid bogus scans. + if (lastDetection === null || lastDetection !== result.codeResult.code) { + lastDetection = result.codeResult.code; + return; + } + const code = result.codeResult.code; statusNode.querySelector('.isbn').innerText = code; @@ -692,7 +702,7 @@ let BookWyrm = new (class { const search = new URL('/search', document.location); search.searchParams.set('q', code); - cleanup(); + cleanup(false); location.assign(search); }); @@ -711,12 +721,6 @@ let BookWyrm = new (class { constraints: { facingMode: "environment", }, - area: { - top: "25%", - right: "25%", - left: "25%", - bottom: "25%", - } }, decoder : { readers: [ diff --git a/bookwyrm/templates/search/barcode_modal.html b/bookwyrm/templates/search/barcode_modal.html index 17eb8829e..00cc7c027 100644 --- a/bookwyrm/templates/search/barcode_modal.html +++ b/bookwyrm/templates/search/barcode_modal.html @@ -12,7 +12,7 @@
@@ -25,7 +25,7 @@ {% trans "Align your book's barcode with the camera." %}