Files
qrcode-from-onetab/templates/macros.html
T
2025-12-19 01:24:23 +07:00

59 lines
1.7 KiB
HTML

{% macro magic_link(url, text, unique_id='magic_link') %} {# Example Macro #}
<a
href="{{ url }}"
target="_blank"
rel="noopener noreferrer"
id="{{ unique_id }}"
>
{{ text }}
</a>
<script>
(function () {
const a = document.getElementById("{{ unique_id }}");
a.addEventListener("click", function (e) {
e.preventDefault();
window.open(
this.href,
this.target,
Array.from(this.relList).join(", ")
);
setTimeout(() => {
window.location.reload();
});
});
})();
</script>
{% endmacro %} {% macro qrcode_queue(queue_items, qr_limit = 100) %} {% if
queue_items %}
<ol class="queue-grid">
{% for item in queue_items %}
<li>
<a href="{{ item }}" target="_blank" rel="noreferrer noopener">
{{ item }}
</a>
{% if not loop.index > qr_limit %}
<div class="qrcode"></div>
{% endif %}
</li>
{% endfor %}
</ol>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/qrcode.js"></script>
<script>
window.addEventListener("load", (_) => {
document.querySelectorAll(".qrcode").forEach((e) => {
// Find the sibling <a> tag within the same <li>
const link = e.parentElement.querySelector("a");
const a = link ? link.textContent.trim() : "";
if (a) {
new QRCode(e, {
text: a,
correctLevel: QRCode.CorrectLevel.L,
width: 256,
height: 256,
});
}
});
});
</script>
{% endif %} {% endmacro %}