1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| (function () { 'use strict';
const SKIP_TAGS = new Set(['CODE', 'PRE', 'SCRIPT', 'STYLE', 'TEXTAREA']);
const MARK_RE = /==([\s\S]+?)==/g;
function isInsideSkippedTag(node) { while (node) { if (node.nodeType === 1 && SKIP_TAGS.has(node.tagName)) return true; node = node.parentNode; } return false; }
function replaceInTextNode(textNode) { const text = textNode.nodeValue; if (!text || text.indexOf('==') === -1) return;
MARK_RE.lastIndex = 0; let match; let lastIndex = 0; const frag = document.createDocumentFragment();
while ((match = MARK_RE.exec(text)) !== null) { const before = text.slice(lastIndex, match.index); if (before) frag.appendChild(document.createTextNode(before));
const mark = document.createElement('mark'); mark.textContent = match[1]; frag.appendChild(mark);
lastIndex = MARK_RE.lastIndex; }
const after = text.slice(lastIndex); if (after) frag.appendChild(document.createTextNode(after));
textNode.parentNode.replaceChild(frag, textNode); }
function process(root = document.body) { if (!root) return; const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, { acceptNode(node) { if (!node.nodeValue) return NodeFilter.FILTER_REJECT; if (node.nodeValue.indexOf('==') === -1) return NodeFilter.FILTER_REJECT; if (node.nodeValue.trim() === '') return NodeFilter.FILTER_REJECT; return NodeFilter.FILTER_ACCEPT; } }, false);
const nodes = []; while (walker.nextNode()) nodes.push(walker.currentNode);
for (const n of nodes) { if (!isInsideSkippedTag(n.parentNode)) { replaceInTextNode(n); } } }
function onReadyRun() { process(); }
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', onReadyRun); } else { onReadyRun(); }
if (window.swup && typeof window.swup.on === 'function') { try { window.swup.on('contentReplaced', () => process()); } catch (e) { } } document.addEventListener('swup:contentReplaced', () => process());
let idleTimer = null; const observer = new MutationObserver(() => { if (idleTimer) clearTimeout(idleTimer); idleTimer = setTimeout(() => { process(); idleTimer = null; }, 60); }); observer.observe(document.documentElement || document.body, { childList: true, subtree: true });
window.__applyDoubleEqualsMark = process;
})();
|