// HTMLの要素が全て準備できれば処理を行う
var setBoxId = 'lt-chat-box'; // 要素名
var ltchat_chaturl = lt_type===1 ? "https://www.inxray.jp/chat/box1" : lt_type===3 ? "https://www.inxray.jp/chat/box3" : '';
var ltchat_script = "https://www.inxray.jp/chat/ltchat.js";
window.addEventListener('load',function() {
// chat box設置
let div = document.createElement('div');
div.setAttribute("id",setBoxId);
div.style.position = "fixed"; // 位置固定
// 場所決定
if( typeof lt_chat_position=="undefined" ){
lt_chat_position = "";
}
if( lt_chat_position.indexOf('left')===-1 && lt_chat_position.indexOf('right')===-1 ) {
lt_chat_position += " right";
}
if( lt_chat_position.indexOf('top')===-1 && lt_chat_position.indexOf('bottom')===-1 ) {
lt_chat_position += " bottom";
}
if( lt_chat_position.indexOf('top')!==-1 ){ div.style.top = "10px"; }
if( lt_chat_position.indexOf('left')!==-1 ){ div.style.left = "10px"; }
if( lt_chat_position.indexOf('right')!==-1 ){ div.style.right = "10px"; }
if( lt_chat_position.indexOf('bottom')!==-1 ){ div.style.bottom = "10px"; }
// 表示
let bdy = document.getElementsByTagName("body");
let ele=bdy.item(0);
ele.appendChild(div);
// chat読み込み
htmlLoad(ltchat_chaturl, setBoxId);
});
// chat htmlの読み込み
function htmlLoad(url, id){
let xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange = function(){
//とれた場合Idにそって入れ替え
if(xmlhttp.readyState === 4 && xmlhttp.status===200){
let data = xmlhttp.responseText;
let elem = document.getElementById(id);
elem.innerHTML= data;
// javascript読み込み
// (htmlソースに書いても実行されないのでcreateElementで作る ∵https://tinyurl.com/ybgc4ekk)
var script = document.createElement('script');
script.src = ltchat_script;
elem.appendChild(script);
// タイトル
if( typeof lt_chat_title=="string" ){
let title = document.getElementById('ltchatbox-title');
title.innerHTML = lt_chat_title;
}
}
};
xmlhttp.send(null);
}