//////////////////////////////////////////////////////////////////// // 今日と明日の日付部分の処理。 // 基本はサーバ側のHEADERの時刻を使うようにして // 取得できない時だけクライアント側の端末の日付を使う。 //////////////////////////////////////////////////////////////////// $(function () { $.ajax({ type: 'HEAD', url: window.location.href, cache: false }).done(function (data, textStatus, xhr) { try { //Firefoxの場合必ず.doneに入るのでheaderDateがnullになっていないかを確認する var headerDate = xhr.getResponseHeader("Date"); var result = headerDate ? new Date(headerDate) : new Date(); } catch (e) { var result = new Date(); } var weekday = ["日", "月", "火", "水", "木", "金", "土"]; var format_today = 'YYYY.MM.DD(WW)' var format_tomorrow = 'YYYY.MM.DD(WW)' var todays_date_pc = $('.todays_date_pc').text(); var tomorrows_date_pc = $('.tomorrows_date_pc').text(); var todays_date_sp = $('.todays_date_sp').text(); var tomorrows_date_sp = $('.tomorrows_date_sp').text(); format_today = format_today.replace("YYYY", result.getFullYear()); format_today = format_today.replace("MM", ('0' + (result.getMonth() + 1)).slice(-2)); format_today = format_today.replace("DD", ('0' + result.getDate()).slice(-2)); format_today = format_today.replace("WW", weekday[result.getDay()]); //一日進める result.setDate(result.getDate() +1); format_tomorrow = format_tomorrow.replace("YYYY", result.getFullYear()); format_tomorrow = format_tomorrow.replace("MM", ('0' + (result.getMonth() + 1)).slice(-2)); format_tomorrow = format_tomorrow.replace("DD", ('0' + result.getDate()).slice(-2)); format_tomorrow = format_tomorrow.replace("WW", weekday[result.getDay()]); todays_date_pc = todays_date_pc.replace("todays_date_pc", format_today); tomorrows_date_pc = tomorrows_date_pc.replace("tomorrows_date_pc", format_tomorrow); todays_date_sp = todays_date_sp.replace("todays_date_sp", format_today); tomorrows_date_sp = tomorrows_date_sp.replace("tomorrows_date_sp", format_tomorrow); $('.todays_date_pc').text(todays_date_pc); $('.tomorrows_date_pc').text(tomorrows_date_pc); $('.todays_date_sp').text(todays_date_sp); $('.tomorrows_date_sp').text(tomorrows_date_sp); }).fail(function () { var result = new Date(); var weekday = ["日", "月", "火", "水", "木", "金", "土"]; var format_today = 'YYYY.MM.DD(WW)' var format_tomorrow = 'YYYY.MM.DD(WW)' var todays_date_pc = $('.todays_date_pc').text(); var tomorrows_date_pc = $('.tomorrows_date_pc').text(); var todays_date_sp = $('.todays_date_sp').text(); var tomorrows_date_sp = $('.tomorrows_date_sp').text(); format_today = format_today.replace("YYYY", result.getFullYear()); format_today = format_today.replace("MM", ('0' + (result.getMonth() + 1)).slice(-2)); format_today = format_today.replace("DD", ('0' + result.getDate()).slice(-2)); format_today = format_today.replace("WW", weekday[result.getDay()]); //一日進める result.setDate(result.getDate() +1); format_tomorrow = format_tomorrow.replace("YYYY", result.getFullYear()); format_tomorrow = format_tomorrow.replace("MM", ('0' + (result.getMonth() + 1)).slice(-2)); format_tomorrow = format_tomorrow.replace("DD", ('0' + (result.getDate())).slice(-2)); format_tomorrow = format_tomorrow.replace("WW", weekday[(result.getDay())]); todays_date_pc = todays_date_pc.replace("todays_date_pc", format_today); tomorrows_date_pc = tomorrows_date_pc.replace("tomorrows_date_pc", format_tomorrow); todays_date_sp = todays_date_sp.replace("todays_date_sp", format_today); tomorrows_date_sp = tomorrows_date_sp.replace("tomorrows_date_sp", format_tomorrow); $('.todays_date_pc').text(todays_date_pc); $('.tomorrows_date_pc').text(tomorrows_date_pc); $('.todays_date_sp').text(todays_date_sp); $('.tomorrows_date_sp').text(tomorrows_date_sp); }); }); //////////////////////////////////////////////////////////////////// // // 天気マークと風向表示のために // Lifesocket連携サーバから吐き出されたcsvの対象コード行を使用し // 対応する天気マークと風向きを算出するための関数 // //////////////////////////////////////////////////////////////////// function csvToArray(path) { var csvData = new Array(); var data = new XMLHttpRequest(); data.open("GET", path, false); data.send(null); var LF = String.fromCharCode(10); var lines = data.responseText.split(LF); for (var i = 0; i < lines.length; ++i) { var cells = lines[i].split(","); if (cells.length != 1) { csvData.push(cells); } } return csvData; } function gettenki_codeData(tenki_code, src) { var tenki_dst = new Array(); for (var i = 0; i < src.length; i++) if (src[i][0].indexOf(tenki_code) !== -1) { tenki_dst.push(src[i]); } return tenki_dst; }; function getwind_codeData(wind_code, src) { var wind_dst = new Array(); for (var i = 0; i < src.length; i++) if (src[i][0].indexOf(wind_code) !== -1) { wind_dst.push(src[i]); } return wind_dst; }; //////////////////////////////////////////////////////////////////// // // 今日の分の表示処理(天気マーク以外) // //////////////////////////////////////////////////////////////////// $(function () { $.ajax({ url: 'today.txt', success: function (data) { var arr = data.split(/\r\n|\r|\n/); var rain_todayText_pc = $('.s-weather__rain_1').text(); var rain_todayText_sp = $('.s-weather__rain_3').text(); var temp_high_todayText_pc = $('.s-weather-deg--high_1').text(); var temp_high_todayText_sp = $('.s-weather-deg--high_3').text(); var temp_low_todayText_pc = $('.s-weather-deg--low_1').text(); var temp_low_todayText_sp = $('.s-weather-deg--low_3').text(); var temp_wind_todayText_pc = $('.s-weather__wind_1').text(); var temp_wind_todayText_sp = $('.s-weather__wind_3').text(); var temp_wind_dir_todayText_pc = $('.s-weather__dir_1').text(); var temp_wind_dir_todayText_sp = $('.s-weather__dir_3').text(); todayTenkiCode = arr[0]; todayWindCode = arr[4]; var csvWindData = csvToArray("wind_code.txt"); todays_wind_code = todayWindCode; var todays_wind_dir = getwind_codeData(todays_wind_code, csvWindData); rain_todayText_pc = rain_todayText_pc.replace("rain_today", arr[3]); rain_todayText_sp = rain_todayText_pc.replace("rain_today", arr[3]); temp_high_todayText_pc = temp_high_todayText_pc.replace("temp_high_today", arr[1]); temp_high_todayText_sp = temp_high_todayText_sp.replace("temp_high_today", arr[1]); temp_low_todayText_pc = temp_low_todayText_pc.replace("temp_low_today", arr[2]); temp_low_todayText_sp = temp_low_todayText_sp.replace("temp_low_today", arr[2]); temp_wind_todayText_pc = temp_wind_todayText_pc.replace("wind_today", arr[5]); temp_wind_todayText_sp = temp_wind_todayText_sp.replace("wind_today", arr[5]); temp_wind_dir_todayText_pc = temp_wind_dir_todayText_pc.replace("wind_dir_today", todays_wind_dir[0][1]); temp_wind_dir_todayText_sp = temp_wind_dir_todayText_sp.replace("wind_dir_today", todays_wind_dir[0][1]); $('.s-weather__rain_1').text(rain_todayText_pc); $('.s-weather__rain_3').text(rain_todayText_sp); $('.s-weather-deg--high_1').text(temp_high_todayText_pc); $('.s-weather-deg--high_3').text(temp_high_todayText_sp); $('.s-weather-deg--low_1').text(temp_low_todayText_pc); $('.s-weather-deg--low_3').text(temp_low_todayText_sp); $('.s-weather__wind_1').text(temp_wind_todayText_pc); $('.s-weather__wind_3').text(temp_wind_todayText_sp); $('.s-weather__dir_1').text(temp_wind_dir_todayText_pc); $('.s-weather__dir_3').text(temp_wind_dir_todayText_sp); } }); }); //////////////////////////////////////////////////////////////////// // // 明日の分の表示処理(天気マーク以外) // //////////////////////////////////////////////////////////////////// $(function () { $.ajax({ url: 'tomorrow.txt', success: function (data) { var arr = data.split(/\r\n|\r|\n/); var rain_tomorrowText_pc = $('.s-weather__rain_2').text(); var rain_tomorrowText_sp = $('.s-weather__rain_4').text(); var temp_high_tomorrowText_pc = $('.s-weather-deg--high_2').text(); var temp_high_tomorrowText_sp = $('.s-weather-deg--high_4').text(); var temp_low_tomorrowText_pc = $('.s-weather-deg--low_2').text(); var temp_low_tomorrowText_sp = $('.s-weather-deg--low_4').text(); var temp_wind_tomorrowText_pc = $('.s-weather__wind_2').text(); var temp_wind_tomorrowText_sp = $('.s-weather__wind_4').text(); var temp_wind_dir_tomorrowText_pc = $('.s-weather__dir_2').text(); var temp_wind_dir_tomorrowText_sp = $('.s-weather__dir_4').text(); tomorrowTenkiCode = arr[0]; tomorrowWindCode = arr[4]; var csvWindData = csvToArray("wind_code.txt"); tomorrows_wind_code = tomorrowWindCode; var tomorrows_wind_dir = getwind_codeData(tomorrows_wind_code, csvWindData); rain_tomorrowText_pc = rain_tomorrowText_pc.replace("rain_tomorrow", arr[3]); rain_tomorrowText_sp = rain_tomorrowText_pc.replace("rain_tomorrow", arr[3]); temp_high_tomorrowText_pc = temp_high_tomorrowText_pc.replace("temp_high_tomorrow", arr[1]); temp_high_tomorrowText_sp = temp_high_tomorrowText_sp.replace("temp_high_tomorrow", arr[1]); temp_low_tomorrowText_pc = temp_low_tomorrowText_pc.replace("temp_low_tomorrow", arr[2]); temp_low_tomorrowText_sp = temp_low_tomorrowText_sp.replace("temp_low_tomorrow", arr[2]); temp_wind_tomorrowText_pc = temp_wind_tomorrowText_pc.replace("wind_tomorrow", arr[5]); temp_wind_tomorrowText_sp = temp_wind_tomorrowText_sp.replace("wind_tomorrow", arr[5]); temp_wind_dir_tomorrowText_pc = temp_wind_dir_tomorrowText_pc.replace("wind_dir_tomorrow", tomorrows_wind_dir[0][1]); temp_wind_dir_tomorrowText_sp = temp_wind_dir_tomorrowText_sp.replace("wind_dir_tomorrow", tomorrows_wind_dir[0][1]); $('.s-weather__rain_2').text(rain_tomorrowText_pc); $('.s-weather__rain_4').text(rain_tomorrowText_sp); $('.s-weather-deg--high_2').text(temp_high_tomorrowText_pc); $('.s-weather-deg--high_4').text(temp_high_tomorrowText_sp); $('.s-weather-deg--low_2').text(temp_low_tomorrowText_pc); $('.s-weather-deg--low_4').text(temp_low_tomorrowText_sp); $('.s-weather__wind_2').text(temp_wind_tomorrowText_pc); $('.s-weather__wind_4').text(temp_wind_tomorrowText_sp); $('.s-weather__dir_2').text(temp_wind_dir_tomorrowText_pc); $('.s-weather__dir_4').text(temp_wind_dir_tomorrowText_sp); } }); }); //////////////////////////////////////////////////////////////////// // // 天気マークの今日&明日の表示処理 // //////////////////////////////////////////////////////////////////// $(function () { $.ajax({ type: 'GET', url: 'index.html', dataType: 'html', success: function (data) { var csvData = csvToArray("tenki_code.txt"); todays_tenki_code = todayTenkiCode; tomorrows_tenki_code = tomorrowTenkiCode; var todays_tenki_icon = gettenki_codeData(todays_tenki_code, csvData); var tomorrows_tenki_icon = gettenki_codeData(tomorrows_tenki_code, csvData); var img_today_weather_icon_pc = $("#today_weather_icon_pc").attr('src'); var img_today_weather_icon_sp = $("#today_weather_icon_sp").attr('src'); var img_tomorrow_weather_icon_pc = $("#tomorrow_weather_icon_pc").attr('src'); var img_tomorrow_weather_icon_sp = $("#tomorrow_weather_icon_sp").attr('src'); img_today_weather_icon_pc = $("#today_weather_icon_pc").attr('src', "./assets/imgs/weather_icon/" + todays_tenki_icon[0][1]); img_today_weather_icon_sp = $("#today_weather_icon_sp").attr('src', "./assets/imgs/weather_icon/" + todays_tenki_icon[0][1]); img_tomorrow_weather_icon_pc = $("#tomorrow_weather_icon_pc").attr('src', "./assets/imgs/weather_icon/" + tomorrows_tenki_icon[0][1]); img_tomorrow_weather_icon_sp = $("#tomorrow_weather_icon_sp").attr('src', "./assets/imgs/weather_icon/" + tomorrows_tenki_icon[0][1]); } }); });