1function injectTikTokScript() { 2 const existing = document.querySelector('script[src*="tiktok.com/embed.js"]') 3 if (existing) return 4 5 const script = document.createElement('script') 6 script.src = 'https://www.tiktok.com/embed.js' 7 script.async = true 8 document.body.appendChild(script) 9} 10 11function parseVisibleTikTokEmbeds() { 12 const embeds = document.querySelectorAll('.tiktok-embed') 13 if (!embeds.length) return 14 15 const needsParsing = Array.from(embeds).some(el => { 16 const isVisible = el.offsetParent !== null 17 const isParsed = el.querySelector('iframe') || el.querySelector('.tiktok-fallback-added') 18 return isVisible && !isParsed 19 }) 20 21 if (needsParsing) { 22 injectTikTokScript() 23 } 24} 25 26// Watch for consent placeholders being hidden 27function observePlaceholderVisibility() { 28 document.querySelectorAll('.embed-placeholder__container').forEach(placeholder => { 29 new MutationObserver(() => { 30 if (placeholder.style.display === 'none') { 31 setTimeout(parseVisibleTikTokEmbeds, 100) 32 } 33 }).observe(placeholder, { attributes: true, attributeFilter: ['style'] }) 34 }) 35} 36 37// Watch for new embeds added to DOM 38new MutationObserver(mutations => { 39 for (const mutation of mutations) { 40 if (mutation.type === 'childList') { 41 const hasTikTokEmbed = [...mutation.addedNodes].some(node => 42 node.nodeType === 1 && (node.matches?.('.tiktok-embed') || node.querySelector?.('.tiktok-embed')) 43 ) 44 if (hasTikTokEmbed) setTimeout(parseVisibleTikTokEmbeds, 100) 45 } 46 } 47}).observe(document.body, { childList: true, subtree: true }) 48 49window.addEventListener('load', () => { 50 setTimeout(parseVisibleTikTokEmbeds, 1000) 51 observePlaceholderVisibility() 52})
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.