diff --git a/script.js b/script.js index 63413ec..f944a11 100644 --- a/script.js +++ b/script.js @@ -127,9 +127,27 @@ addEventListener('DOMContentLoaded', () => { }) { // Choose best scale for screen height - const height = document.documentElement.clientHeight; - const padding = getComputedStyle(document.body).paddingTop; - // TODO + let padding = getComputedStyle(document.body).paddingBottom + // remove `px` at the end and convert to number + padding = Number(padding.slice(0, padding.length - 2)) + + // compute available height + const height = + document.documentElement.clientHeight + - canvas.offsetTop // substract height of everything above canvas + - padding // substract body padding + + const width = + document.documentElement.clientWidth + - padding * 2 + + options.scale.value = Math.max( + intDiv( + width < height ? width : height, + 25, // divide least dimension by QR version 2 size + ), + 10, // minimum scale for this auto-detect algorithm + ) } { // QR version related stuff