]> gitweb.michael.orlitzky.com - charm-bypass.git/commitdiff
index.html.in: factor out the svg_to_client() function
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 11 Sep 2025 01:58:09 +0000 (21:58 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 11 Sep 2025 01:58:09 +0000 (21:58 -0400)
This will waste a tiiiiny bit of time because we only call this
function in contexts where we already have the security code
background element handy (and the new function recomputes it),
but it's so much cleaner as a separate function.

index.html.in

index 3d1ec0b7faa4b33cdb01c44d12462c7c9949a79e..244f7429aad6f77dae1e9e111b42b6ca57ef3ccd 100644 (file)
       }
 
 
+      /**
+       * Convert SVG units into client (HTML/CSS) units based
+       * on the declared/rendered width of the code background.
+       */
+      function svg_to_client() {
+          const codebg = document.getElementById("codebg");
+          const client_width = codebg.getBoundingClientRect().width;
+          const svg_width = parseFloat(codebg.getAttribute("width"));
+          return client_width / svg_width;
+      }
+
       /**
        * Resize the  ticket background based on the service name.
        * The BaltimoreLink, Commuter Bus, and MARC Train tickets