1// ð¯ JSON Integration for WikiLive Production 2// This script integrates the JSON extraction system into the main WikiLive application 3 4// Function to integrate JSON extraction into existing WikiLive 5function integrateJSONExtraction() { 6 console.log('ð¨ [JSON Integration] Initializing JSON extraction system...'); 7 8 // Override the original showRealTimeAIFactsBox to include JSON extraction 9 if (typeof window.originalShowRealTimeAIFactsBox === 'undefined') { 10 // Store the original function 11 window.originalShowRealTimeAIFactsBox = window.showRealTimeAIFactsBox; 12 13 // Create enhanced version with JSON extraction 14 window.showRealTimeAIFactsBox = async function(allWikiUrlsForInfobox, topLevelRealtimeFacts, mainEntityMetadata, primaryWikipediaUrl, chatContainer, factsByEntity, conversationHistory) { 15 console.log('ð¨ [Enhanced showRealTimeAIFactsBox] Starting with JSON extraction...'); 16 17 // Call the original function 18 const result = await window.originalShowRealTimeAIFactsBox.call(this, allWikiUrlsForInfobox, topLevelRealtimeFacts, mainEntityMetadata, primaryWikipediaUrl, chatContainer, factsByEntity, conversationHistory); 19 20 // Add JSON extraction after a delay to ensure all infoboxes are rendered 21 setTimeout(() => { 22 console.log('ð¨ [Enhanced showRealTimeAIFactsBox] Triggering JSON extraction...'); 23 if (typeof extractInfoboxDataAsJSON === 'function') { 24 extractInfoboxDataAsJSON(chatContainer); 25 } else { 26 console.log('ð¨ [Enhanced showRealTimeAIFactsBox] JSON extraction function not available, loading...'); 27 // Try to load the extraction functions if not available 28 loadJSONExtractionFunctions(); 29 } 30 }, 5000); // Increased to 5 seconds to ensure all infoboxes and images are loaded 31 32 return result; 33 }; 34 35 console.log('ð¨ [JSON Integration] Successfully enhanced showRealTimeAIFactsBox with JSON extraction'); 36 } 37} 38 39// Function to load JSON extraction functions if not available 40function loadJSONExtractionFunctions() { 41 console.log('ð¨ [JSON Integration] Loading JSON extraction functions...'); 42 43 // Check if functions are available 44 if (typeof extractInfoboxDataAsJSON !== 'function') { 45 console.log('ð¨ [JSON Integration] JSON extraction functions not loaded, attempting to load scripts...'); 46 47 // Try to load the scripts dynamically 48 const scripts = [ 49 'infobox-json-extractor.js', 50 'fancy-ui-preview.js' 51 ]; 52 53 scripts.forEach(scriptSrc => { 54 if (!document.querySelector(`script[src="${scriptSrc}"]`)) { 55 const script = document.createElement('script'); 56 script.src = scriptSrc; 57 script.onload = () => { 58 console.log(`ð¨ [JSON Integration] Successfully loaded ${scriptSrc}`); 59 }; 60 script.onerror = () => { 61 console.log(`ð¨ [JSON Integration] Failed to load ${scriptSrc}`); 62 }; 63 document.head.appendChild(script); 64 } 65 }); 66 } 67} 68 69// Function to manually trigger JSON extraction for existing infoboxes 70function triggerJSONExtractionNow() { 71 console.log('ð¨ [Manual Trigger] Attempting to extract JSON from existing infoboxes...'); 72 73 const chatContainer = document.querySelector('.chat-container'); 74 if (chatContainer) { 75 if (typeof extractInfoboxDataAsJSON === 'function') { 76 extractInfoboxDataAsJSON(chatContainer); 77 } else { 78 console.log('ð¨ [Manual Trigger] JSON extraction function not available'); 79 loadJSONExtractionFunctions(); 80 81 // Try again after a short delay 82 setTimeout(() => { 83 if (typeof extractInfoboxDataAsJSON === 'function') {
84 extractInfoboxDataAsJSON(chatContainer); 85 } else { 86 console.log('ð¨ [Manual Trigger] Still unable to load JSON extraction functions'); 87 } 88 }, 1000); 89 } 90 } else { 91 console.log('ð¨ [Manual Trigger] Chat container not found'); 92 } 93} 94 95// Initialize the integration when the script loads 96if (document.readyState === 'loading') { 97 document.addEventListener('DOMContentLoaded', integrateJSONExtraction); 98} else { 99 integrateJSONExtraction(); 100} 101 102// Make functions available globally for manual testing 103window.triggerJSONExtractionNow = triggerJSONExtractionNow; 104window.integrateJSONExtraction = integrateJSONExtraction; 105 106console.log('ð¨ [JSON Integration] Integration script loaded. Use triggerJSONExtractionNow() to manually extract JSON from existing infoboxes.');
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.