/* eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["w"] }] */ // ESLint configuration that prevents reassigning function parameters except for "w" (window) /* global QRCode */ // Informs ESLint that QRCode is a global variable that will be available at runtime (function iefe(w, d, c, t, a, s) { // Immediately Invoked Function Expression (IIFE) to create a private scope // Parameters are shortcuts to commonly used objects/methods: // w = window, d = document, c = createElement, t = createTextNode // a = appendChild, s = setAttribute /* inject:js */ /* endinject */ // Placeholder comments for a build process to inject additional JavaScript w.printlinks = function printlinks(sel) { // Defines a global function on the window object called "printlinks" // Takes an optional selector parameter (sel) d.querySelectorAll('.tw-linklist,.tw-linkref').forEach((e) => { e.remove(); }); // First removes any existing link lists or references from previous runs const links = d.querySelectorAll(sel || 'a[href]:not([href^="javascript:"])'); // Selects all links matching the provided selector, or if none provided, // selects all elements with href attributes that don't start with "javascript:" if (links.length) { // Only proceeds if links were found const dimension = 36; // Sets the size for QR codes (36x36) const hrefs = new Map(); // Creates a Map to store unique URLs and their reference numbers const linklist = d[c]('ol'); // Creates an ordered list element linklist.className = 'tw-linklist'; // Assigns a class name for styling and later identification links.forEach((l) => { // Processes each link element const href = String(l.href); // Gets the URL and ensures it's a string let sup = hrefs.size + 1; // Default superscript number if this is a new URL if (hrefs.has(href)) { // If this URL was already processed sup = hrefs.get(href); // Reuse the existing reference number } else { // For new URLs not seen before hrefs.set(href, sup); // Store the URL with its reference number const listitem = d[c]('li'); // Create a list item for this URL const qrcode = d.createElementNS('http://www.w3.org/2000/svg', 'svg'); // Create an SVG element for the QR code using proper namespace qrcode[s]('width', dimension); qrcode[s]('height', dimension); qrcode[s]('viewBox', `0 0 ${dimension} ${dimension}`); qrcode[s]('aria-hidden', 'true'); qrcode[s]('focusable', 'false'); // Set SVG attributes for size, accessibility, etc. qrcode.innerHTML = (new QRCode({ content: href, // URL to encode width: dimension, // Width of QR code height: dimension, // Height of QR code join: true, // Join paths into a single path xmlDeclaration: false, // Skip XML declaration ecl: 'L', // Error correction level: Low container: 'none' // Don't wrap in a container })).svg(); // Generate the QR code SVG and insert it listitem[a](qrcode); // Add QR code to list item listitem[a](d[t](href)); // Add URL text to list item linklist[a](listitem); // Add the list item to the ordered list } const ref = d[c]('sup'); // Create a superscript element for the reference number ref.className = 'tw-linkref'; // Assign class for styling and identification ref[a](d[t](sup)); // Add the reference number to the superscript l.parentNode.insertBefore(ref, l.nextSibling); // Insert the superscript right after the link }); d.body[a](linklist); // Add the completed ordered list to the end of the document body } }; }(window, document, 'createElement', 'createTextNode', 'appendChild', 'setAttribute')); // Immediately invoke the function with these arguments