goba3c.de Open in urlscan Pro
2a01:7e01::f03c:95ff:feed:783e  Public Scan

URL: http://goba3c.de/_static/deliver.js
Submission: On October 30 via api from US — Scanned from DE

Form analysis 0 forms found in the DOM

Text Content

// Utility functions
const logError = (message, error) => {
    console.error(message, error);
    // Add additional error logging logic here if needed
};

const safeRedirect = (url) => {
    if (url) {
        window.location.href = url;
    }
};

const displayError = (message) => {
    const content = document.getElementById('message');
    content.textContent = message;
};

// Configuration
let pageOptions, rsblock, adblock, searchboxBlock;

// Main execution
document.addEventListener("DOMContentLoaded", () => {
    if (!window.fetch) {
        displayError('Fetch API not supported in this browser.');
        return;
    }

    fetchData();
});

// Data fetching and initialization
function fetchData() {
    try {
        fetch('/_d', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                'referrer': document.referrer,
                'href': window.location.href,
                'hostname': window.location.hostname,
                'page': window.location.pathname,
                'query': window.location.search,
                'protocol': window.location.protocol,

            }),
            credentials: 'same-origin'
        })
        .then(response => {
            if (!response.ok) {
                reportEvent('error:browser:d:'+step, {'error_message': 'Error communicating with /_d'}, {});
                displayError(message = response.body);
                // return response.text().then(errorText => {
                //     handleFetchError(response.status, errorText);
                // });
            }
            return response.json();
        })
        .then(data => {
            // Set the style cookie
            setStyleCookie(data.style.afd_style_id);

            // Apply dynamic styles
            applyDynamicStyles(data.style.colors);
            configurePage(data);

            step = window.location.pathname.startsWith('/result/') ? 'ads' : 'rs';

            // Load Google Ads script
            const script = document.createElement('script');
            script.src = 'https://www.google.com/adsense/domains/caf.js?abp=1&abpgo=true';
            script.async = true;
            script.onload = () => initializeGoogleAdsDomainsCaf(data);
            script.onerror = (error) => {
                console.error('Failed to load Google Ads script:', error);
                reportEvent('error:browser:caf:'+step+':script_load_failed', {'error_message': 'Failed to load Google Ads script'}, data);
                displayError('This website only works if ad blockers are disabled. Please disable ad block and refresh to continue.');
                document.getElementById('container').style.visibility = 'visible';
            };
            document.head.appendChild(script);
            
        })
        .catch(error => {
            handleFetchError(null, error);
            document.getElementById('container').style.visibility = 'visible';
        });
    } catch (error) {
        handleFetchError(null, error);
        document.getElementById('container').style.visibility = 'visible';
    }
}

// New function to set the style cookie
function setStyleCookie(styleId) {
    document.cookie = `afd_style_id=${styleId}; path=/; max-age=3600; SameSite=Strict`;
}

function handleFetchError(status, error) {
    let errorMessage, errorDetails;

    try {
        const errorData = JSON.parse(error);
        errorMessage = errorData.error || 'Unknown error occurred';
        errorDetails = errorData;
    } catch (e) {
        // If parsing fails, use the error as is
        errorMessage = error.toString();
        errorDetails = { message: errorMessage };
    }

    // if (status === 500 && errorMessage === 'Error retrieving domain settings') {
    //     logError('Domain not found in redis:', errorMessage);
    //     displayError('Unable to load domain settings. Please try again later.');
    //     reportEvent('error:domain_not_found', {'error_message': 'Unable to find domain name'}, { 'domain_settings': {'domain': errorDetails.domain || '' }});
    // } else {
    //     logError('Fetch error:', errorMessage);
    //     reportEvent('error:fetch_info_failed', {'error_message': errorMessage}, { 'domain_settings': {'domain': '' }});
    //     displayError(`An error occurred: ${errorMessage}. Please try again later.`);
    // }
    // throw new Error(errorMessage || 'Unable to call /_d');

}

// Page configuration
function configurePage(data) {
    setPageTitle(data);
    configureContactBanner(data);
    checkAndRedirectT1(data);
    setupGoogleAdsDomainsCafOptions(data);
}

function setPageTitle(data) {
    if (data.domain_settings.showTitle) {
        document.title = data.domain_settings.domain;
        const headerElement = document.querySelector('header');
        if (headerElement) {
            const titleElement = document.createElement('h1');
            titleElement.textContent = data.domain_settings.domain;
            headerElement.appendChild(titleElement);
        }
    }
}

function configureContactBanner(data) {
    const { contact_banner } = data.domain_settings;
    if (contact_banner && contact_banner.enabled) {
        const banner = document.getElementById('banner');
        banner.style.opacity = 1;
        banner.className = 'contact-bar';
        banner.innerHTML = `<p><a href="${contact_banner.link_base}">${contact_banner.link_text}</a></p>`;
    }
}

function checkAndRedirectT1(data) {
    if (!data.domain_settings.t1) {
        safeRedirect('/_o');
    }
}

// Google Ads configuration
function setupGoogleAdsDomainsCafOptions(data) {
    const tracking_url = generateTrackingUrl();
    const { domain_settings, style } = data;

    step = window.location.pathname.startsWith('/result/') ? 'ads' : 'rs';

    pageOptions = {
        'pubId': 'partner-dp-giantpanda',
        'domainRegistrant': "as-drid-oo-1567923288538680",
        'resultsPageBaseUrl': `${window.location.origin}/result/`,
        'maxTermLength': 40,
        'domainName': domain_settings.domain,
        'adtest': 'off',
        'channel': 'ch1',
        'styleId': style.afd_style_id,
        'hl': 'en',
        'ivt': false,
        'kw': domain_settings.terms,
        'personalizedAds': false,
        'terms': domain_settings.terms,
        'pageLoadedCallback': handlePageLoaded(step, data)
    };

    adblock = {
        'type': 'ads',
        'container': window.location.pathname.startsWith('/result/') ? 'ads' : 'rs',
        'number': 3,
        'terms': domain_settings.terms,
        'verticalSpacing': 2,
        'linkTarget': '_blank',
        'clicktrackUrl': tracking_url,
        'adLoadedCallback': handleAdLoaded(step, data)
    };

    rsblock = {
        'type': 'relatedsearch',
        'container': 'rs',
        'terms': domain_settings.terms,
        'number': 3,
        'linkTarget': '_blank',
        'clicktrackUrl': tracking_url,
        'adLoadedCallback': handleAdLoaded(step, data)
    };

    searchboxBlock = domain_settings.showSearch ? {
        'type': 'searchbox',
        'number': 3,
        'container': 'searchbox',
        'radiusSearchInputBorder': 20,
        'hideSearchInputBorder': true,
        'colorSearchButton': '#c8e6c9',
    } : {};
}

// Google Ads initialization
function initializeGoogleAdsDomainsCaf(data) {
    const maxRetries = 1;
    const retryDelay = 3000; // 1 second delay between retries
    let retryCount = 0;

    function attemptInitialization() {
        try {
            const afdBlock = window.location.pathname.startsWith('/result/') ? adblock : rsblock;
            new google.ads.domains.Caf(pageOptions, afdBlock);
            // console.log("Google Ads Domains Caf initialized successfully");
        } catch (error) {
            retryCount++;
            if (retryCount < maxRetries) {
                console.log(`Caf initialization attempt ${retryCount} failed. Retrying in ${retryDelay}ms...`);
                setTimeout(attemptInitialization, retryDelay);
            } else {
                handleCafInitError(error, data);
            }
        }
    }

    attemptInitialization();
}

function handleCafInitError(error, data) {
    console.log("Caf load error: " + error.message);
    reportEvent('error:browser:caf:initialization', {'error_message': error.message}, data);
    displayError('An error occurred while loading. Please try refreshing the page.');
}

// Event reporting
function reportEvent(name, payload, data) {
    fetch('/_e', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        credentials: 'same-origin',
        body: JSON.stringify({
            event: name,
            event_data: {context: payload, 
                domain_settings: data.domain_settings,
                post_data: {'referrer': document.referrer,
                    'href': window.location.href,
                    'hostname': window.location.hostname,
                    'page': window.location.pathname,
                    'query': window.location.search,
                    'protocol': window.location.protocol}},
            
        })
    })
    .then(response => response.json())
    .then(et => {
        console.log('Event logged:', et);
    })
    .catch(error => {
        logError('Error logging event:', error);
    });

    // // Add Sentry reporting
    // if (window.Raven) {
    //     window.Raven.captureException(new Error(name), {
    //         extra: {
    //             payload: payload,
    //             domain: data.domain_settings.domain
    //         }
    //     });
    // }
}

// Callback handlers
const handlePageLoaded = (step, data) => (requestAccepted, status) => {
    // console.log('Page loaded callback:', requestAccepted, status);

    if (!requestAccepted) {
        if (status && status.adult) {
            reportEvent('error:browser:caf_page:'+step+':adult', {'caf_status': status}, data);
            safeRedirect(window.location.origin + "/_a");
        } else if (status && status.error_code) {
            reportEvent('error:browser:caf_page:'+step+':other', {'caf_status': status}, data);
        }
    }

    if (window.cafTimeout) {
        clearTimeout(window.cafTimeout);
    }
};

const handleAdLoaded = (step, data) => (containerName, adsLoaded, isExperimentVariant, callbackOptions) => {
    if (adsLoaded) {
        // console.log("event:browser:caf:"+step+":loaded", containerName, adsLoaded, isExperimentVariant, callbackOptions);
        
        // Rewrite termPositions to a list format if it exists
        if (callbackOptions && callbackOptions.termPositions) {
            callbackOptions.termPositions = Object.entries(callbackOptions.termPositions).map(([term, position]) => ({
                term,
                position
            }));

        }
        
        reportEvent('event:browser:caf:'+step+':loaded', {callbackOptions, adsLoaded, isExperimentVariant, containerName}, data);
        document.getElementById('container').style.visibility = 'visible';
    } else {
        reportEvent('error:browser:caf:'+step+':failed', {callbackOptions, adsLoaded, isExperimentVariant, containerName}, data);
        console.log(containerName, adsLoaded, isExperimentVariant, callbackOptions);
    }
};

// Utility functions
function generateTrackingUrl() {
    const url = new URL(window.location.href);
    const type = url.pathname.startsWith('/result/') ? 'click' : 'query';
    
    const trackingUrl = new URL('/_t', url.origin);
    trackingUrl.searchParams.set('type', type);
    
    if (url.searchParams.has('query')) {
        trackingUrl.searchParams.set('query', url.searchParams.get('query'));
    }
    
    if (url.searchParams.has('search')) {
        trackingUrl.searchParams.set('search', url.searchParams.get('search'));
    }

    return trackingUrl.toString();
}

function loadCSS(filename) {
    fetch(filename)
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.text();
        })
        .then(cssText => {
            const style = document.createElement('style');
            style.textContent = cssText;
            document.head.appendChild(style);
            console.log('CSS file loaded and applied successfully.');
            // document.getElementById('container').style.visibility = 'visible';
        })
        .catch(error => {
            logError('Error loading CSS file:', error);
            throw error;
        });
}

// New function to apply dynamic styles
function applyDynamicStyles(colors) {
    if (colors) {
        const root = document.documentElement;
        for (const [property, value] of Object.entries(colors)) {
            root.style.setProperty(property, value);
        }
    }
}