1const BUTTON_SELECTOR = '.pixfort-likes'; 2const RUNTIME_MODULE_SPECIFIER = window.pixfortLikesRuntimeModuleId || 'pixfort-likes-runtime'; 3const interactionEvents = [ 4 ['scroll', { passive: true }], 5 ['mousemove', { passive: true }], 6 ['touchstart', { passive: true }], 7 ['keydown', {}], 8]; 9 10let runtimePromise = null; 11let runtimeReady = false; 12let triggersBound = false; 13let replayingClick = false; 14 15const hasLikeButtons = () => Boolean(document.querySelector(BUTTON_SELECTOR)); 16 17const removeRuntimeTriggers = () => { 18 interactionEvents.forEach(([eventName]) => { 19 window.removeEventListener(eventName, triggerRuntimeLoad); 20 }); 21 22 document.removeEventListener('click', interceptEarlyLikeClick, true); 23 triggersBound = false; 24}; 25 26const loadRuntime = async () => { 27 if (!hasLikeButtons()) { 28 return; 29 } 30 31 if (runtimeReady) { 32 return; 33 } 34 35 if (runtimePromise) { 36 return runtimePromise; 37 } 38 39 removeRuntimeTriggers(); 40 41 runtimePromise = import(RUNTIME_MODULE_SPECIFIER) 42 .then((module) => module.initPixfortLikes()) 43 .then(() => { 44 runtimeReady = true; 45 }) 46 .catch((error) => { 47 runtimePromise = null; 48 bindRuntimeTriggers(); 49 throw error; 50 }); 51 52 return runtimePromise; 53}; 54 55function triggerRuntimeLoad() { 56 loadRuntime().catch(() => {}); 57} 58 59async function interceptEarlyLikeClick(event) { 60 if (runtimeReady || replayingClick) { 61 return; 62 } 63 64 const button = event.target.closest(BUTTON_SELECTOR); 65 66 if (!button) { 67 return; 68 } 69 70 event.preventDefault(); 71 event.stopImmediatePropagation(); 72 73 try { 74 await loadRuntime(); 75 replayingClick = true; 76 button.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true })); 77 } catch (error) { 78 return; 79 } finally { 80 replayingClick = false; 81 } 82} 83 84function bindRuntimeTriggers() { 85 if (triggersBound || !hasLikeButtons()) { 86 return; 87 } 88 89 interactionEvents.forEach(([eventName, options]) => { 90 window.addEventListener(eventName, triggerRuntimeLoad, { 91 ...options, 92 once: true, 93 }); 94 }); 95 96 document.addEventListener('click', interceptEarlyLikeClick, true); 97 triggersBound = true; 98} 99 100if (document.readyState === 'complete') { 101 bindRuntimeTriggers(); 102} else { 103 window.addEventListener('load', bindRuntimeTriggers, { once: true }); 104}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.