56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<?php include $_SERVER['DOCUMENT_ROOT']."/snippets/head.php" ?>
|
|
<body>
|
|
<?php include $_SERVER['DOCUMENT_ROOT']."/snippets/header.php" ?>
|
|
|
|
<div class="container">
|
|
<div class="content flex-vertical">
|
|
<div class="section-one">
|
|
<h1>QR Code</h1>
|
|
<a id="qr-link" href="">
|
|
<div id="qr"></div>
|
|
</a>
|
|
</div>
|
|
<div class="section-two">
|
|
<div id="loading"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include $_SERVER['DOCUMENT_ROOT']."/snippets/footer.php" ?>
|
|
|
|
<script src="/static/qrcode.min.js"></script>
|
|
<script>
|
|
const path = window.location.pathname;
|
|
const parts = path.split("/");
|
|
const user = parts.pop();
|
|
let url = location.protocol + "//" + location.host + "/u/" + user.toLowerCase();
|
|
|
|
const qrcode = new QRCode(document.getElementById('qr'), {
|
|
text: url,
|
|
width: 1024,
|
|
height: 1024,
|
|
colorDark : '#000',
|
|
colorLight : '#fff',
|
|
correctLevel : QRCode.CorrectLevel.L
|
|
});
|
|
|
|
let qrLink = document.getElementById("qr-link");
|
|
let qrImg = document.querySelector("#qr img");
|
|
console.log(qrImg.src);
|
|
qrLink.setAttribute("download", "qrcode-" + user.toLowerCase() + ".png");
|
|
|
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
|
const setHref = async () => {
|
|
while (!qrLink.href.startsWith("data:")) {
|
|
await delay(100);
|
|
qrLink.setAttribute("href", qrImg.src);
|
|
console.log("Refreshing...");
|
|
}
|
|
document.getElementById("loading").remove();
|
|
};
|
|
setHref();
|
|
</script>
|
|
</body>
|
|
</html>
|