function globalChatOpen() { collectchat.open(); } function globalExternApiDetectFrameSourceType(sFrameSource) { var sFrameType = 'summary'; if(typeof(sFrameSource) != 'undefined' && sFrameSource.indexOf('/api/v2/doc/doc?') > -1) { // Kein Summary mehr, wir sind in einem Daten Frame if(sFrameSource.indexOf('mode=timelinevol') > -1) { sFrameType = 'timeline'; } else if(sFrameSource.indexOf('mode=tonechart') > -1) { sFrameType = 'tonechart'; } else if(sFrameSource.indexOf('mode=artlist') > -1) { sFrameType = 'artlist'; } } return sFrameType; } function globalExternApiProjectFrameOnload() { // $('img.externApiProjectsSummaryLoaderIcon').hide(); // $('#externApiProjectsSummaryFrame').fadeIn(1000); globalExternApiProjectFrameSummaryCleanup($('#externApiProjectsSummaryFrame')); window.setTimeout(function(){ // Irgendwo ist etwas schief gegangen, wir zeigen an dass wir nicht weiter laden $('img.externApiProjectsSummaryLoaderIcon').hide(); }, 30000); } function globalExternApiProjectFrameUnload() { $('#externApiProjectsSummaryFrame').hide(); $('img.externApiProjectsSummaryLoaderIcon').show(); window.setTimeout(function(){ // Irgendwo ist etwas schief gegangen, wir zeigen an dass wir nicht weiter laden $('img.externApiProjectsSummaryLoaderIcon').hide(); }, 30000); } function globalExternApiProjectUpdateSeacrTerm(sNewSearchTerm) { $('.externalApiProjectsSummarySearchTerm').html(decodeURIComponent(sNewSearchTerm)); } function globalExternApiProjectFrameSummaryCleanup(oFrame, sFrameId) { var sReplaceSearch = 'https://api.gdeltproject.org'; var sReplaceWith = '/eapi/gd'; if(typeof(oFrame) == 'undefined') oFrame = $('#externApiProjectsSummaryFrame'); var sFrameSource = $(oFrame).attr('src'); // Wir brauchen immer einen Trigger bei Source Change $(oFrame).unbind('load'); $(oFrame).on('load', function(){ globalExternApiProjectFrameOnload(); }); $(oFrame).attr('onload', 'globalExternApiProjectFrameOnload();'); // Lets check the frame url if(typeof(sFrameSource) != 'undefined' && sFrameSource.indexOf(sReplaceSearch) > -1) { var sNewSource = sFrameSource.replace(sReplaceSearch, sReplaceWith); $(oFrame).attr('src', sNewSource); return; } // Wir entfernen den Modify Search Link. Wenn er vorgesehen ist, so wird er vom Target kommen // und eingebunden // $(document).find('a:contains("Modify Search")').remove(); // Der Link muss zuerst entnommen werden bevor wir saemtliche Container und Inhalte "clearen" var oModifySearchLink = $(oFrame).contents().find('a:contains("Modify Search")'); if(oModifySearchLink.length > 0 && oModifySearchLink.attr('href')) { var sNewHref = oModifySearchLink.attr('href').replace(sReplaceSearch, sReplaceWith); // oModifySearchLink.attr('href', sNewHref); oModifySearchLink.attr('href', 'javascript:void(0)'); oModifySearchLink.attr('targetHref', sNewHref); oModifySearchLink.css('margin-left', '10px'); // oModifySearchLink.attr('target', 'externFrameObject_apiProjectsSummary'); oModifySearchLink.attr('onclick', 'globalReplaceUrlFrameTarget(\$(this).attr(\'targetHref\'));'); if($(document).find('a:contains("Modify Search")').length <= 0) { $(oFrame).parent().prepend(oModifySearchLink); } else { $(document).find('a:contains("Modify Search")').attr('targetHref', sNewHref); } } // Sollten wir im Such-Formular sein, so passen wir auch hier die Url an var oSearchForm = $(oFrame).contents().find('form'); if(oSearchForm.length > 0) { var sSource = oSearchForm.attr('action'); if(typeof(sSource) != 'undefined') { sSource = sSource.replace(sReplaceSearch, sReplaceWith); oSearchForm.attr('action', sSource); } // Die Info Icons funktionieren sowieso nicht $(oFrame).contents().find('i').parent().remove(); // Wir moechten gerne informiert werden wenn sich der Search Term veraendert oSearchForm.attr('onsubmit', 'if(typeof(parent.globalExternApiProjectUpdateSeacrTerm) == \'function\') parent.globalExternApiProjectUpdateSeacrTerm(\$(\'#k\').val());'); // Wir sind hier fertig, nach uns die Sintflut (jippieh, endlich genug Wasser fuer alle ;P) } var sFrameType = 'summary'; if(typeof(sFrameSource) != 'undefined' && sFrameSource.indexOf('/api/v2/doc/doc?') > -1) { // Kein Summary mehr, wir sind in einem Daten Frame if(sFrameSource.indexOf('mode=timelinevol') > -1) { sFrameType = 'timeline'; } else if(sFrameSource.indexOf('mode=tonechart') > -1) { sFrameType = 'tonechart'; } else if(sFrameSource.indexOf('mode=artlist') > -1) { sFrameType = 'artlist'; } } if(typeof(sFrameSource) != 'undefined' && sFrameType == 'summary') { $(oFrame).contents().find('body').attr('onunload', 'parent.globalExternApiProjectFrameUnload();'); $(oFrame).contents().find('#header, br, p, h2').remove(); $(oFrame).contents().find('#content > div:first').remove(); $(oFrame).contents().find('#content').css('margin-top', '-50px'); $(oFrame).contents().find('i').closest('div').remove(); $(oFrame).contents().find('a').each(function(){ if($(this).html() == 'EMBED') { $(this).remove(); } else { var sLinkSource = $(this).attr('href'); if(typeof(sLinkSource) != 'undefined' && sLinkSource.indexOf(sReplaceSearch) > -1) { sLinkSource = sLinkSource.replace(sReplaceSearch, sReplaceWith); $(this).attr('href', sLinkSource); } } }); } // So, jetzt wird es ein wenig tricky, wir muessen die Javascript funktionen bei den Suchen anpassen. Hack the world ;P $(oFrame).contents().find('#d').unbind('change'); $(oFrame).contents().find('#d').change(function(){ var sNewUrl = '/eapi/gd/api/v2/summary/summary?d=' + $(oFrame).contents().find('#d').val(); $(oFrame).attr('src', sNewUrl); // Ist bescheuert aber muessen wir leider machen window.setTimeout(function(){ $(oFrame).prop('src', $(oFrame).prop('src')); }, 500); }); $(oFrame).contents().find('#t').unbind('change'); $(oFrame).contents().find('#t').change(function(){ var sNewUrl = '/eapi/gd/api/v2/summary/summary?d=' + $(oFrame).contents().find('#d').val() + '&t=' + $(oFrame).contents().find('#t').val(); $(oFrame).attr('src', sNewUrl); // Ist bescheuert aber muessen wir leider machen window.setTimeout(function(){ $(oFrame).prop('src', $(oFrame).prop('src')); }, 500); }); // Chyron Browser (Internet Archive) entfernen, das unterstuetzen wir leider noch nicht $(oFrame).contents().find('option[value="ltb"]').remove(); // Eingebundene Frames Url Korrektur var iCountFrames = $(oFrame).contents().find('iframe').length; var iLoopFrames = 0; if(iCountFrames <= 0) { window.setTimeout(function(){ $('img.externApiProjectsSummaryLoaderIcon').hide(); $('#externApiProjectsSummaryFrame').fadeIn('1000'); }, 500); } $(oFrame).contents().find('iframe').each(function(){ var bSkipFadeIn = false; iLoopFrames++; var sSource = $(this).attr('src'); sSource = sSource.replace(sReplaceSearch, sReplaceWith); $(this).on('load', function(oEvent){ var oSubFrame = oEvent.currentTarget; // Externe Fehlerbehandlung der Api var oSubBody = $(oSubFrame).contents().find('body'); if(oSubBody.html().indexOf('The specified phrase is too short.') > -1) { var sSearchedTerm = globalGetUrlParam(sSource, 'query'); if(sSearchedTerm.substr(0, 1) == '"' && sSearchedTerm.substr(-1) == '"') { bSkipFadeIn = true; $('#externApiProjectsSummaryFrame').hide(); $('img.externApiProjectsSummaryLoaderIcon').show(); var sNewSearchTerm = sSearchedTerm.substr(1, (sSearchedTerm.length-2)); sNewSearchTerm = encodeURIComponent(sNewSearchTerm); globalExternApiProjectUpdateSeacrTerm(sNewSearchTerm); $('#externApiProjectsSummaryFrame').attr('src', globalReplaceUrlParam($('#externApiProjectsSummaryFrame').attr('src'), 'key', sNewSearchTerm)); return; } } var sFrameType = globalExternApiDetectFrameSourceType(oSubFrame.src); $(oSubFrame).contents().find('body').attr('onunload', 'if(typeof(parent.globalExternApiProjectFrameUnload) == \'function\') parent.globalExternApiProjectFrameUnload();'); // Wir korrigieren die Links $(oSubFrame).contents().find('a').each(function(){ if($(this).html() == 'EMBED') { $(this).remove(); } else { var sLinkSource = $(this).attr('href'); if(typeof(sLinkSource) != 'undefined' && sLinkSource.indexOf(sReplaceSearch) > -1) { sLinkSource = sLinkSource.replace(sReplaceSearch, sReplaceWith); $(this).attr('href', sLinkSource); } } }); if(sFrameType != 'artlist') { $(oSubFrame).contents().find('i').parent().remove(); } $(oSubFrame).contents().find('.highcharts-credits').remove(); if(sFrameType == 'tonechart') { if($(oSubFrame).contents().find('svg').length <= 0) { // Der Tonechart hat keine Ergebnisse, wir koennen ihn also entfernen $(oSubFrame).remove(); $(oFrame).contents().find('h3:contains("Tone Barchart")').remove(); $(oFrame).contents().find('hr').remove(); } } else if(sFrameType == 'artlist') { if($(oSubFrame).contents().find('span.arttitle').length <= 0) { // Die Artikel Liste hat keine Ergebnisse, wir koennen den Frame also entfernen $(oSubFrame).remove(); $(oFrame).contents().find('h3:contains("Top Articles")').remove(); $(oFrame).contents().find('hr').remove(); } } // Wenn wir alle Frames abgearbeitet haben, dann zeigen wir auch den Main Frame an if(iLoopFrames >= iCountFrames && bSkipFadeIn === false) { // Wir sind durch und duerfen den Main Frame anzeigen $('img.externApiProjectsSummaryLoaderIcon').hide(); $('#externApiProjectsSummaryFrame').fadeIn('1000'); } }); // Wir haben ein paar Kodierunges-Fehler, dafuer koennen wir nichts, aber wir muessen versuchen sie zu beheben //1var sNativeSearchTerm = $('.externalApiProjectsSummarySearchTerm').html(); //2 sNativeSearchTerm = sNativeSearchTerm.replace(/\s/gi, '+'); //2 var sUrlSearchTerm = globalGetUrlParam(sSource, 'query'); //2 console.log(sNativeSearchTerm+':'+sUrlSearchTerm); // Das funktioniert nicht bei erweiterter Filter Nutzung, wir deaktivieren das erst mal //1 sSource = globalReplaceUrlParam(sSource, 'query', globalExternApiProjectFrameSummaryBuildQuery(encodeURIComponent(sNativeSearchTerm))); // Wir muessen bei allen Urls diesen Parameter anhaengen, sonst bekommen wir oft keine Ergebnisse // var oDate = new Date(); // var sStartDate = (oDate.getFullYear()-5).toString().padStart(4, '0')+oDate.getMonth().toString().padStart(2, '0')+oDate.getDate().toString().padStart(2, '0')+oDate.getHours().toString().padStart(2, '0')+oDate.getMinutes().toString().padStart(2, '0')+oDate.getSeconds().toString().padStart(2, '0'); // var sEndDate = oDate.getFullYear().toString().padStart(4, '0')+oDate.getMonth().toString().padStart(2, '0')+oDate.getDate().toString().padStart(2, '0')+oDate.getHours().toString().padStart(2, '0')+oDate.getMinutes().toString().padStart(2, '0')+oDate.getSeconds().toString().padStart(2, '0'); // sSource = sSource + '&sdt='+sStartDate+'&edt='+sEndDate; // Wir muessen darauf achten keinen timespan Parameter zu senden wenn Start- und End- Datum in der Url sind if(sSource.indexOf('startdatetime=') < 0 || sSource.indexOf('enddatetime=') < 0) { // sSource = sSource + '×pan=FULL'; sSource = sSource + '&ts=full'; } $(this).attr('src', sSource); }); } function globalExternApiProjectFrameSummaryBuildQuery(sSearchTerm) { // Wenn die Suche einen Filter enthalten, dann muessen wir das Original zurueck geben if(sSearchTerm.indexOf('(') > -1 || sSearchTerm.indexOf(':') > -1) return sSearchTerm; // Ansonsten passen wir den Query auf Gueltigkeit an if(sSearchTerm.indexOf(' ') > -1 || sSearchTerm.indexOf('-') > -1) return '"'+sSearchTerm+'"'; return sSearchTerm; } function globalGetUrlParam(sUrl, sIndex) { var oUrlParams = new URLSearchParams(sUrl); return oUrlParams.get(sIndex); } function globalReplaceUrlParam(url, paramName, paramValue) { if(paramValue == null) { paramValue = ''; } var pattern = new RegExp('\\b('+paramName+'=).*?(&|#|$)'); if(url.search(pattern)>=0) { return url.replace(pattern,'$1' + paramValue + '$2'); } url = url.replace(/[?#]$/,''); return url + (url.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue; } function globalReplaceUrlFrameTarget(sUrl) { $('#externApiProjectsSummaryFrame').attr('src', sUrl); } function frameMutationObserver() { new MutationObserver(function(mutations) { mutations.some(function(mutation) { if (mutation.type === 'attributes' && mutation.attributeName === 'src') { console.log(mutation); console.log('Old src: ', mutation.oldValue); console.log('New src: ', mutation.target.src); return true; } return false; }); }).observe(document.body, { attributes: true, attributeFilter: ['src'], attributeOldValue: true, characterData: false, characterDataOldValue: false, childList: false, subtree: true }); } function globalDocumentReady() { globalCheckRegistration(); } function globalCheckRegistration() { window.setTimeout(function(){ var sHref = top.location.href; if(sHref.indexOf('sNotify=true') > -1) { $('.registrationNotification').fadeIn(); // var sSearch = top.location.pathname.substring(1); // sSearch = sSearch.substring((sSearch.indexOf('=')+1), sSearch.lastIndexOf(';')); // $('input[name="email"]').val(sSearch); } }, 500); }