const sitekey = '6Lf2uycUAAAAALo3u8D10FqNuSpUvUXlfP7BzHOk';

let verifyCallback = (response) => {
    console.log('verifyCallback: ', response);
    window.webkit.messageHandlers.dkbmHandler.postMessage({ token: response });
};

window.addEventListener('load', (event) => {
    if(window.top == window.self) {
        let meta = document.createElement('meta'); meta
        meta.setAttribute( 'name', 'viewport' );
        meta.setAttribute( 'content', 'width = device-width' );
        document.getElementsByTagName('head')[0].appendChild(meta);
        
        document.body.innerHTML = '';
        window.webkit.messageHandlers.dkbmHandler.postMessage({ event: 'show-checkbox' });
        grecaptcha.render(document.body, {
            'sitekey' : sitekey,
            'callback' : verifyCallback
        });
    } else {
        let checkbox = document.getElementById('recaptcha-anchor');
        if(checkbox) {
            checkbox.click();
            window.webkit.messageHandlers.dkbmHandler.postMessage({ event: 'show-challenge', location: location.href });
        }
    }
});
