
var topcontent = [];


function topcontents(){
    var contents_json_url = "https://script.googleusercontent.com/macros/echo?user_content_key=s1BYA4Z_TqlU25rpOiiLbTz01cc1KZvUmmbQp7_0eKbYesJOvIbcDkirM3IU5bDhKimENvraa91dCUww2kHCCygIyYmXVJxQm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnMnDTo5lIsL1257bUjFRGmUCONhi87waLjLlZVrRf8Mohka-Kg9WOeCc2ImrE39WhggQTRlLkh_cFr8yUg3eOgemWJejxuzCntz9Jw9Md8uu&lib=Ms-rm9gkw5XSAED_Dx0r52NiSLq2dBohQ"

    //APIを使って非同期データを取得する
    fetch(contents_json_url)
    .then(response => response.json())
    /*成功した処理*/
    .then(data => {
        //JSONから配列に変換
        topcontent = data;
        topchenge(topcontent);
        console.log("データ取得" + topcontent);
    });
    

}


function topchenge(contents){

    var contentslist = contents[0];
    var contentskeys = Object.keys(contentslist);

    for(var i=0; i<contentskeys.length;++i){
        var content = document.getElementById(contentskeys[i]);
        console.log(content);
        if(content){
            if (contentskeys[i] == "topimage" || contentskeys[i] == "topmap"){
                if(contentslist[contentskeys[i]]){
                    if(contentslist[contentskeys[i]].match(/https:\/\/drive.google.com\/file\/d\//) != null){
                        content.src = contentslist[contentskeys[i]].replace(/https:\/\/drive.google.com\/file\/d\//, "http://drive.google.com/uc?export=view&id=").replace(/\/view\?usp=sharing/,"");
                    }else{
                        content.src = contentslist[contentskeys[i]];
                    }
                }else{
                    content.src = "img/errer.jpg";
                }
                
            } else{
                content.innerHTML = contentslist[contentskeys[i]];
            }
        }
        console.log(content+ "終了");
    }
}