function tebotOpen()
{
    iframe = document.getElementById('aime_fluent_chat');
    iframe.contentWindow.postMessage('_window_open_', '*');
    return false;
}
function tebotClose()
{
    iframe = document.getElementById('aime_fluent_chat');
    iframe.contentWindow.postMessage('_window_close_', '*');
    return false;
}
function myFunction() {

    if(false){
        parentUrl = window.location.href;
        if(parentUrl.includes('tebot.jp/portal/') || ! parentUrl.includes('tebot.jp/') ){
            return false;
        }
    }

    window.AIME_FLUENT_DEFAULT_OPEN = false;
    window.addEventListener("message",
        function (e) {
            if (!e) {
                return;
            }
            if (e.data === "_aime_chat_open_") {
                if(iframe$.classList.contains('pc')){
                    iframe$.style = "z-index:99998;    max-height: 565px;    height: 100%;    max-width: 100%;    width: 420px;    position: fixed;    right: 20px;    bottom: 90px;    border: none;    background: none;";
                }else{
                    iframe$.style = "z-index:99998;    max-height: 565px;    height: 100%;    max-width: 420px;    width: 100%;    position: fixed;    right: 0px;    left: 0px;    margin-left: auto;    bottom: 0px;    border: none;    background: none;";
                }
                iframe$.classList.add('chat-open');
                iframe$.classList.remove('chat-close', 'chat-shutdown');
            } else if (e.data === "_aime_chat_close_") {
                if(iframe$.classList.contains('pc')){
                    iframe$.style = "z-index: 99999;	max-height: 120px;    height: 100%;    width: 300px;    position: fixed;	right: 20px;	bottom: 90px;    border: none;    background: none;    transition-delay: 0.4s;";
                }else{
                    iframe$.style = "z-index:99998;    max-height: 110px;    height: 100%;    width: 100px;    position: fixed;    right: 10px;    bottom: 80px;    border: none;    background: none;    transition-delay: 0.4s;    overflow: hidden;";
                }
                iframe$.classList.add('chat-close');
                iframe$.classList.remove('chat-open', 'chat-shutdown');
            } else if (e.data === "_aime_chat_shut_down_") {
                iframe$.style.maxHeight = "0px";
                iframe$.style.width = "0px";
                iframe$.classList.add('chat-shutdown');
                iframe$.classList.remove('chat-open', 'chat-close');
            } else if (e.data === "_aime_chat_ready_") {
                if (window.AIME_FLUENT_DEFAULT_OPEN) {
                    iframe$.contentWindow.postMessage("_expand_", "*");
                }
            } else if (e.data === "_aime_get_href_") {
                iframe$.contentWindow.postMessage('_href_' + window.location.href, '*');
                // e.originEvent.source.postMessage("_aime_return_href_", "*", window.location.href);
            }

        }, false);


    var div$ = document.createElement("div");
    div$.setAttribute("id", "JKChatView_place_holder");
    div$.setAttribute("style", "max-height: 95px;");
    var iframe$ = document.createElement("iframe");
    iframe$.setAttribute("id", "aime_fluent_chat");
    document.body.appendChild(div$);
    div$.appendChild(iframe$);
    if ("" == "1") {
        iframe$.src = "https://tebot.jp/bot/1289/render_bot_v9?lang=ja&bot_lang=ja&allow_input_text=&code=76f0cd51c2cf4da9e086a448a0697d1a";
    } else if ('false' == 'true') {
        iframe$.src = "https://tebot.jp/bot/1289/render_bot_v9?lang=ja&bot_lang=ja&embed_page=true&code=76f0cd51c2cf4da9e086a448a0697d1a";
    } else {
        iframe$.src = "https://tebot.jp/bot/1289/render_bot_v9?lang=ja&bot_lang=ja&code=76f0cd51c2cf4da9e086a448a0697d1a";
    }

    if (window.matchMedia( "(max-width: 750px)" ).matches) {
        // for sp
        iframe$.style = "z-index:99998;    max-height: 110px;    height: 100%;    width: 100px;    position: fixed;    right: 10px;    bottom: 80px;    border: none;    background: none;    transition-delay: 0.4s;    overflow: hidden;";
        iframe$.style.display = 'none';
        iframe$.classList.add('sp');
        iframe$.classList.remove('pc');
        iframe$.onload = function(){
            iframe$.contentWindow.postMessage('_set_sp_class_', '*');
            iframe$.style.display = 'block';
        };
    } else {
        // for pc
        iframe$.style = "z-index: 99999;	max-height: 120px;    height: 100%;    width: 300px;    position: fixed;	right: 20px;	bottom: 90px;    border: none;    background: none;    transition-delay: 0.4s;";
        iframe$.classList.add('pc');
        iframe$.classList.remove('sp');
        iframe$.onload = function(){
            iframe$.contentWindow.postMessage('_set_pc_class_', '*');
        };
    }
    // update display portal page
    if (window.location.href.indexOf("https://tebot.jp/portal") !== -1) {
        // for pc
        iframe$.style = "z-index:99998;    max-height: 565px;    height: 100%;    max-width: 100%;    width: 420px;    position: fixed;    right: 20px;    bottom: 90px;    border: none;    background: none;";
        iframe$.classList.add('pc');
        iframe$.classList.add('chat-open');
        iframe$.classList.remove('sp');
        iframe$.onload = function(){
            iframe$.contentWindow.postMessage('_set_pc_class_', '*');
        };
    }
    if ('true' == 'true') {
        window.addEventListener("scroll", (event) => {
            iframe = document.getElementById('aime_fluent_chat');
            iframe.contentWindow.postMessage('_parent_scroll_' + window.scrollY, '*');
        });
    }
};
myFunction();