From ca6afc8445e31bb912a4e4fc7dff7fb9b036967a Mon Sep 17 00:00:00 2001 From: onePone Date: Fri, 24 Feb 2023 15:17:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=B6=E5=8C=BA=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/main.js b/js/main.js index 6035591..f01511c 100644 --- a/js/main.js +++ b/js/main.js @@ -1,3 +1,3 @@ -window.onload=function(){getIpInfo();clock(bg_autoMode);time_timer=setInterval("clock("+bg_autoMode+")",60*1000);if(rotation_mode!==""){rotation_mode=Number(rotation_mode)}else{rotation_mode=rotation_mode_default;setCookie("rotation_mode",rotation_mode,30)}rotation_mode=rotation_mode===0?3:rotation_mode-1;rotateScreen();if(hour24!==""){hour24=hour24==="true"?true:false}else{hour24=hour24_default;setCookie("hour24",hour24,30)}if(top_mode!==""){top_mode=Number(top_mode)}else{top_mode=top_mode_default;setCookie("top_mode",top_mode,30)}top_mode=top_mode===0?TOP_MODE.length-1:top_mode-1;changeTopMode();if(bottom_mode!==""){bottom_mode=Number(bottom_mode)}else{bottom_mode=bottom_mode_default;setCookie("bottom_mode",bottom_mode,30)}bottom_mode=bottom_mode===0?BOTTOM_MODE.length-1:bottom_mode-1;changeBottomMode();if(bg_mode!==""){bg_mode=Number(bg_mode);bg_mode=bg_mode===0?BG_MODE.length-1:bg_mode-1;changeBgMode()}else{bg_mode=bg_mode_default;setCookie("bg_mode",bg_mode,30)}addEvent(bg_autoMode);delayHiddenSetting()};var KEY_UNSPLASH="bXwWoUhPeVw-yvSesGMgaOENnlSzhHYB43kZIQOR8cQ";var KEY_QWEATHER=getCookie("qweatherKey");var KEY_LUNAR="LwExDtUWhF3rH5ib";var API_HITOKOTO="https://v1.hitokoto.cn?encode=json&charset=utf-8";var API_IP_INFO="https://ipapi.co/json?languages=zh-CN";var API_LUNAR="https://v2.alapi.cn/api/lunar?token=";var API_WEATHER="https://devapi.qweather.com/v7/weather/now?";var API_WEIBO="https://tenapi.cn/resou/";var TOP_MODE=["nonetop","hitokoto","poem","weibo"];var BOTTOM_MODE=["nonebtm","weather"];var BG_MODE=["none","dark","auto","pic"];var morningHour=6;var nightHour=19;var top_mode_default=1;var bottom_mode_default=1;var bg_mode_default=0;var rotation_mode_default=0;var hour24_default=false;var bg_autoMode=false;var weibo_num=3;var timezoneOffset=0;var cIp="";var city="";var cityLocation=null;var top_mode=getCookie("top_mode");var bottom_mode=getCookie("bottom_mode");var bg_mode=getCookie("bg_mode");var rotation_mode=getCookie("rotation_mode");var hour24=getCookie("hour24");var hitokoto_data=null;var weibo_data=null;var poem_data=null;var weather_data=null;var pic_data=null;var dd_data=null;var hitokoto_timer=null;var poem_timer=null;var weibo_timer=null;var time_timer=null;var weather_timer=null;var pic_timer=null;var settings_timer=null;var autoModeImg="";function createXHR(){var xhr=null;if(window.XMLHttpRequest){xhr=new XMLHttpRequest()}else{if(window.ActiveXObject){xhr=new ActiveXObject("Microsoft.XMLHTTP")}}return xhr}function hitokoto(){console.log("hitokoto update");var xhr=createXHR();xhr.open("GET",API_HITOKOTO,true);xhr.onreadystatechange=function(){if(this.readyState==4){hitokoto_data=JSON.parse(this.responseText);document.getElementById("brackets-l").innerHTML="『";document.getElementById("brackets-r").innerHTML="』";document.getElementById("hitokoto").innerHTML=hitokoto_data.hitokoto;document.getElementById("from").innerHTML=hitokoto_data.from_who?"「"+hitokoto_data.from+" "+hitokoto_data.from_who+"」":"「"+hitokoto_data.from+"」"}};xhr.send(null)}function poem(){console.log("poem update");jinrishici.load(function(result){poem_data=result.data;var sentence=document.querySelector("#poem_sentence");var info=document.querySelector("#poem_info");sentence.innerHTML=poem_data.content;info.innerHTML="【"+poem_data.origin.dynasty+"】"+poem_data.origin.author+"《"+poem_data.origin.title+"》"})}function getIpInfo(){var xhr=createXHR();xhr.open("GET",API_IP_INFO,false);xhr.onreadystatechange=function(){if(this.readyState==4){var data=JSON.parse(this.responseText);cityLocation=data.longitude+","+data.latitude;cIp=data.ip;city=data.region;timezoneOffset=parseInt(data.utc_offset)*0.6}};xhr.send(null)}function clock(autoMode){var date=new Date();var utc8DiffMinutes=date.getTimezoneOffset()+timezoneOffset;date.setMinutes(date.getMinutes()+utc8DiffMinutes);var MM=date.getMonth()+1;var dd=date.getDate();var day=date.getDay();var hour=date.getHours();var minutes=date.getMinutes();var lightMode=true;if(autoMode){if(hour>nightHour||hour12){apm="下
午";hour-=12}document.getElementById("apm").innerHTML=apm}else{document.getElementById("apm").innerHTML=""}var timeString=hour+":"+("0"+minutes).slice(-2);document.getElementById("time").innerHTML=timeString;if(!dd_data||dd!==dd_data){dd_data=dd;var dateString=MM+"月"+dd+"日";var weekList=["日","一","二","三","四","五","六"];var weekString="星期"+weekList[day];document.getElementById("date").innerHTML=dateString+" "+weekString;getLunar()}}function getLunar(){var xhr=createXHR();xhr.open("GET",API_LUNAR+KEY_LUNAR,true);xhr.onreadystatechange=function(){if(this.readyState==4){var data=JSON.parse(this.responseText); - if(data.code==200){var lunar_data=data.data;document.getElementById("lunar").innerHTML=lunar_data.ganzhi_year+"年"+lunar_data.lunar_month_chinese+lunar_data.lunar_day_chinese}else{console.error("农历数据获取失败")}}};xhr.send(null)}function weather(){if(!getCookie("qweatherKey")){document.getElementById("weaTitle").innerHTML="请刷新后点击右上角设置按钮填写 API Key~";return}console.log("weather update");var xhr=createXHR();xhr.open("GET",API_WEATHER+"key="+KEY_QWEATHER+"&location="+cityLocation,true);xhr.onreadystatechange=function(){if(this.readyState==4){var data=JSON.parse(this.responseText);var wea_now=data.now;if(data.code==="200"){var img="";var weaImg=img+"
天气:"+wea_now.text+"
";var weaTemp='
'+parseInt(wea_now.temp)+'
'+"
当前气温
";var weaInfo="
"+city+"当前天气"+"
"+"
体感温度:"+wea_now.feelsLike+"℃
"+"
湿度:"+wea_now.humidity+"%
"+"
风向:"+wea_now.windDir+"
"+"
风速:"+wea_now.windScale+"级 "+wea_now.windSpeed+"km/h
"+"
更新时间:"+wea_now.obsTime.match(/T(.+)\+/)[1]+"
";document.getElementById("weaTitle").innerHTML="";document.getElementById("weaImg").innerHTML=weaImg;document.getElementById("weaTemp").innerHTML=weaTemp;document.getElementById("weaInfo").innerHTML=weaInfo}else{console.error("天气数据获取失败");document.getElementById("weaTitle").innerHTML="数据获取失败,请检查 API Key~"}}};xhr.send(null)}function weibo(){console.log("weibo update");var xhr=createXHR();xhr.open("GET",API_WEIBO,true);xhr.onreadystatechange=function(){if(this.readyState==4){var data=JSON.parse(this.responseText);var weibo_title=document.getElementsByClassName("weibo_title")[0];var hot_word=document.getElementById("hot_word");var hot_word_num=document.getElementById("hot_word_num");if(data.data===200){weibo_data=data.list;weibo_title.innerHTML="微博实时热搜";hot_word.innerHTML="";hot_word_num.innerHTML="";for(var i=0;i"+index+". "+weibo_data[i].name+"";hot_word_num.innerHTML+="
  • "+weibo_data[i].hot+"
  • "}}else{console.error("微博热搜数据获取失败: "+data.msg);weibo_title.innerHTML="数据获取失败,请稍后再试~"}}};xhr.send(null)}function picture(){console.log("picture update")}function changeMode(pos){console.log("# change "+pos+" mode");var pos_mode=eval(pos+"_mode");var POS_MODE=eval(pos.toUpperCase()+"_MODE");if(pos_mode!==0&&eval(POS_MODE[pos_mode]+"_timer")){clearInterval(eval(POS_MODE[pos_mode]+"_timer"));eval(POS_MODE[pos_mode]+"_timer = null");console.log(POS_MODE[pos_mode]+"_timer destroyed")}pos_mode++;if(pos_mode===POS_MODE.length){pos_mode=0}eval(pos+"_mode = pos_mode");setCookie(pos+"_mode",pos_mode,30);if(pos_mode!==0){if(!eval(POS_MODE[pos_mode]+"_data")){eval(POS_MODE[pos_mode]+"()")}eval(POS_MODE[pos_mode]+'_timer = setInterval(POS_MODE[pos_mode] + "()", 60 * 1000 * 60)');console.log(POS_MODE[pos_mode]+"_timer created")}for(var i=0;inightHour||hournightHour||hour12){apm="下
    午";hour-=12}document.getElementById("apm").innerHTML=apm}else{document.getElementById("apm").innerHTML=""}var timeString=hour+":"+("0"+minutes).slice(-2);document.getElementById("time").innerHTML=timeString;if(!dd_data||dd!==dd_data){dd_data=dd;var dateString=MM+"月"+dd+"日";var weekList=["日","一","二","三","四","五","六"];var weekString="星期"+weekList[day];document.getElementById("date").innerHTML=dateString+" "+weekString;getLunar()}}function getLunar(){var xhr=createXHR();xhr.open("GET",API_LUNAR+KEY_LUNAR,true);xhr.onreadystatechange=function(){if(this.readyState==4){var data=JSON.parse(this.responseText); +if(data.code==200){var lunar_data=data.data;document.getElementById("lunar").innerHTML=lunar_data.ganzhi_year+"年"+lunar_data.lunar_month_chinese+lunar_data.lunar_day_chinese}else{console.error("农历数据获取失败")}}};xhr.send(null)}function weather(){if(!getCookie("qweatherKey")){document.getElementById("weaTitle").innerHTML="请刷新后点击右上角设置按钮填写 API Key~";return}console.log("weather update");var xhr=createXHR();xhr.open("GET",API_WEATHER+"key="+KEY_QWEATHER+"&location="+cityLocation,true);xhr.onreadystatechange=function(){if(this.readyState==4){var data=JSON.parse(this.responseText);var wea_now=data.now;if(data.code==="200"){var img="";var weaImg=img+"
    天气:"+wea_now.text+"
    ";var weaTemp='
    '+parseInt(wea_now.temp)+'
    '+"
    当前气温
    ";var weaInfo="
    "+city+"当前天气
    体感温度:"+wea_now.feelsLike+"℃
    湿度:"+wea_now.humidity+"%
    风向:"+wea_now.windDir+"
    风速:"+wea_now.windScale+"级 "+wea_now.windSpeed+"km/h
    更新时间:"+wea_now.obsTime.match(/T(.+)\+/)[1]+"
    ";document.getElementById("weaTitle").innerHTML="";document.getElementById("weaImg").innerHTML=weaImg;document.getElementById("weaTemp").innerHTML=weaTemp;document.getElementById("weaInfo").innerHTML=weaInfo}else{console.error("天气数据获取失败");document.getElementById("weaTitle").innerHTML="数据获取失败,请检查 API Key~"}}};xhr.send(null)}function weibo(){console.log("weibo update");var xhr=createXHR();xhr.open("GET",API_WEIBO,true);xhr.onreadystatechange=function(){if(this.readyState==4){var data=JSON.parse(this.responseText);var weibo_title=document.getElementsByClassName("weibo_title")[0];var hot_word=document.getElementById("hot_word");var hot_word_num=document.getElementById("hot_word_num");if(data.data===200){weibo_data=data.list;weibo_title.innerHTML="微博实时热搜";hot_word.innerHTML="";hot_word_num.innerHTML="";for(var i=0;i"+index+". "+weibo_data[i].name+"";hot_word_num.innerHTML+="
  • "+weibo_data[i].hot+"
  • "}}else{console.error("微博热搜数据获取失败: "+data.msg);weibo_title.innerHTML="数据获取失败,请稍后再试~"}}};xhr.send(null)}function picture(){console.log("picture update")}function changeMode(pos){console.log("# change "+pos+" mode");var pos_mode=eval(pos+"_mode");var POS_MODE=eval(pos.toUpperCase()+"_MODE");if(pos_mode!==0&&eval(POS_MODE[pos_mode]+"_timer")){clearInterval(eval(POS_MODE[pos_mode]+"_timer"));eval(POS_MODE[pos_mode]+"_timer = null");console.log(POS_MODE[pos_mode]+"_timer destroyed")}pos_mode++;if(pos_mode===POS_MODE.length){pos_mode=0}eval(pos+"_mode = pos_mode");setCookie(pos+"_mode",pos_mode,30);if(pos_mode!==0){if(!eval(POS_MODE[pos_mode]+"_data")){eval(POS_MODE[pos_mode]+"()")}eval(POS_MODE[pos_mode]+'_timer = setInterval(POS_MODE[pos_mode] + "()", 60 * 1000 * 60)');console.log(POS_MODE[pos_mode]+"_timer created")}for(var i=0;inightHour||hour