| 
0
 | 
     1 <!doctype html>
 | 
| 
 | 
     2 <head>
 | 
| 
 | 
     3     <meta charset="utf-8">
 | 
| 
5
 | 
     4     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
| 
0
 | 
     5     <title>QR Code Generator</title>
 | 
| 
 | 
     6 
 | 
| 
 | 
     7     <style type="text/css">
 | 
| 
 | 
     8         * {
 | 
| 
 | 
     9             box-sizing: border-box;
 | 
| 
 | 
    10         }
 | 
| 
 | 
    11 
 | 
| 
 | 
    12         html {
 | 
| 
 | 
    13             height: 100%;
 | 
| 
 | 
    14             margin: 0;
 | 
| 
 | 
    15             padding: 0;
 | 
| 
7
 | 
    16             font-family: Arial, sans-serif;
 | 
| 
0
 | 
    17             font-size: 12px;
 | 
| 
 | 
    18         }
 | 
| 
 | 
    19 
 | 
| 
 | 
    20         body {
 | 
| 
 | 
    21             margin: 0;
 | 
| 
 | 
    22             padding: 10px;
 | 
| 
 | 
    23             height: 100%;
 | 
| 
 | 
    24         }
 | 
| 
 | 
    25 
 | 
| 
 | 
    26         .inputbox {
 | 
| 
 | 
    27             width: 100%;
 | 
| 
 | 
    28             margin-bottom: 10px;
 | 
| 
 | 
    29             resize: vertical;
 | 
| 
7
 | 
    30             font-family: Courier New, monospace;
 | 
| 
5
 | 
    31             /* prevent ios zoom */
 | 
| 
 | 
    32             font-size: 16px;
 | 
| 
0
 | 
    33         }
 | 
| 
 | 
    34 
 | 
| 
 | 
    35         .page {
 | 
| 
 | 
    36             width: 100%;
 | 
| 
7
 | 
    37             min-height: 100%;
 | 
| 
0
 | 
    38             max-width: 600px;
 | 
| 
 | 
    39             margin: 0 auto;
 | 
| 
 | 
    40             display: flex;
 | 
| 
 | 
    41             flex-direction: column;
 | 
| 
 | 
    42             padding: 10px;
 | 
| 
 | 
    43         }
 | 
| 
 | 
    44 
 | 
| 
 | 
    45         .page__main {
 | 
| 
 | 
    46             flex: 1;
 | 
| 
 | 
    47         }
 | 
| 
 | 
    48 
 | 
| 
1
 | 
    49         .outputbox {
 | 
| 
 | 
    50             will-change: opacity;
 | 
| 
 | 
    51         }
 | 
| 
 | 
    52 
 | 
| 
 | 
    53         .outputbox.js-hidden {
 | 
| 
 | 
    54             opacity: 0;
 | 
| 
 | 
    55         }
 | 
| 
 | 
    56 
 | 
| 
11
 | 
    57         .outputbox > canvas {
 | 
| 
 | 
    58             display: none;
 | 
| 
 | 
    59         }
 | 
| 
 | 
    60 
 | 
| 
10
 | 
    61         .outputbox > img {
 | 
| 
 | 
    62             max-width: 100%;
 | 
| 
11
 | 
    63             max-height: calc(100vh - 250px);
 | 
| 
10
 | 
    64         }
 | 
| 
 | 
    65 
 | 
| 
0
 | 
    66         .title {
 | 
| 
 | 
    67             font-size: 16px;
 | 
| 
 | 
    68         }
 | 
| 
 | 
    69     </style>
 | 
| 
 | 
    70 </head>
 | 
| 
 | 
    71 <body>
 | 
| 
 | 
    72     <div class="page">
 | 
| 
 | 
    73         <div class="page__main">
 | 
| 
 | 
    74             <h1>QR Code Generator</h1>
 | 
| 
 | 
    75 
 | 
| 
 | 
    76             <p>
 | 
| 
2
 | 
    77                 Type something and get its QR code (almost) immediately.
 | 
| 
0
 | 
    78             </p>
 | 
| 
 | 
    79 
 | 
| 
 | 
    80             <textarea class="inputbox js-qr-input" rows="4" autofocus></textarea>
 | 
| 
 | 
    81 
 | 
| 
1
 | 
    82             <div class="outputbox js-qr-output"></div>
 | 
| 
0
 | 
    83         </div>
 | 
| 
 | 
    84 
 | 
| 
 | 
    85         <div>
 | 
| 
 | 
    86             <hr>
 | 
| 
 | 
    87 
 | 
| 
12
 | 
    88             <a href="https://hg.sr.ht/~nanaya/qr-html">Source</a>
 | 
| 
0
 | 
    89         </div>
 | 
| 
 | 
    90     </div>
 | 
| 
 | 
    91 
 | 
| 
 | 
    92     <script src="qrcode.min.js"></script>
 | 
| 
 | 
    93 
 | 
| 
 | 
    94     <script>
 | 
| 
9
 | 
    95         var inputDom = document.querySelector(".js-qr-input")
 | 
| 
 | 
    96         var outputDom = document.querySelector(".js-qr-output")
 | 
| 
10
 | 
    97         var qr = new QRCode(outputDom, { correctLevel: QRCode.CorrectLevel.L, width: 1024, height: 1024 })
 | 
| 
0
 | 
    98 
 | 
| 
4
 | 
    99         var runTimeout = null
 | 
| 
 | 
   100         var debouncedRefreshCode = function() {
 | 
| 
 | 
   101             clearTimeout(runTimeout)
 | 
| 
 | 
   102             runTimeout = setTimeout(refreshCode, 100)
 | 
| 
 | 
   103         }
 | 
| 
 | 
   104 
 | 
| 
3
 | 
   105         var refreshCode = function() {
 | 
| 
 | 
   106             var text = inputDom.value
 | 
| 
0
 | 
   107 
 | 
| 
 | 
   108             if (text !== "") {
 | 
| 
2
 | 
   109                 qr.makeCode(text)
 | 
| 
 | 
   110                 outputDom.classList.remove('js-hidden')
 | 
| 
1
 | 
   111             } else {
 | 
| 
2
 | 
   112                 outputDom.classList.add('js-hidden')
 | 
| 
0
 | 
   113             }
 | 
| 
2
 | 
   114         }
 | 
| 
 | 
   115 
 | 
| 
4
 | 
   116         inputDom.addEventListener('input', debouncedRefreshCode)
 | 
| 
3
 | 
   117         refreshCode()
 | 
| 
0
 | 
   118     </script>
 | 
| 
 | 
   119 </body>
 |