From b6149e28302c6443d74312448b4b5c3563390b4d Mon Sep 17 00:00:00 2001 From: xiongbao Date: Sat, 28 Mar 2020 17:42:58 +0800 Subject: [PATCH] =?UTF-8?q?Update:=20=E4=BC=98=E5=8C=96=E5=8A=A8=E6=80=81F?= =?UTF-8?q?avicon=E5=B1=95=E7=A4=BA=E5=9C=BA=E6=99=AF(=E4=BB=85PC=E7=AB=AF?= =?UTF-8?q?)=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=A4=9A=E4=B8=AA=E5=A4=A9?= =?UTF-8?q?=E6=B0=94APPKEY=EF=BC=8C=E8=BD=AE=E6=8D=A2=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 110 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 37 deletions(-) diff --git a/index.html b/index.html index 0616b28..ca51e56 100644 --- a/index.html +++ b/index.html @@ -176,28 +176,52 @@ @@ -233,23 +257,35 @@ var cond = localStorage.getItem('cond') || ''; var dateStart = new Date(localStorage.getItem('date') || new Date()); var dayDiff = date.getDate() - dateStart.getDate(); + var weatherKeys = ['fbb7fed63979495f88fc1ddc7296f497','f3488e987bce466d8ae6b523becf278f','95cf38cd40b84df9beae340c610e8550','3cad9669ecba42c39ebfd73cdb566329','6ec2f3eef9bc448ba8a72e815dd86f12']; if(city == '' || dayDiff >= 1) { - $.post( - 'https://free-api.heweather.net/s6/weather/now?location=auto_ip&key=填你自己的', - function(data){ - var weather = data.HeWeather6[0] || {}; - city = weather.basic.parent_city || ''; - cloud = weather.now.fl || '' - cond = weather.now.cond_txt || '' - localStorage.setItem('city',city); - localStorage.setItem('cloud',cloud); - localStorage.setItem('cond',cond); - localStorage.setItem('date',new Date()); - renderWeather(); - },'json' - ) // 天气结束 - } else { - renderWeather(); + var weather = {}; + for(var i=0;i < weatherKeys.length; i++) { + weather = getWeather(weatherKeys[i]); + console.log(weatherKeys[i]+':'+weather.status) + if (weather.status == 'ok') { break }; + } + city = weather.basic.parent_city || ''; + cloud = weather.now.fl || '' + cond = weather.now.cond_txt || '' + localStorage.setItem('city',city); + localStorage.setItem('cloud',cloud); + localStorage.setItem('cond',cond); + localStorage.setItem('date',new Date()); + } + renderWeather(); + + function getWeather(key) { + var weatherData = {}; + $.ajax({ + url: 'https://free-api.heweather.net/s6/weather/now?location=auto_ip&key='+key, + type: 'get', + async: false, + success : function(data){ + weatherData = data.HeWeather6[0]; + } + }); + return weatherData; } function renderWeather(){ var weatherHTML = ''+city+'·'+cond+'·'+cloud+'℃' -- GitLab