From 2ba5d5ff91643cebda7abbf14056972b50362add Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 12 Sep 2023 19:41:27 -0700 Subject: refactor(js): update standards --- index.js | 116 ++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 55 insertions(+), 61 deletions(-) diff --git a/index.js b/index.js index b96e3ed..1267d46 100644 --- a/index.js +++ b/index.js @@ -1,58 +1,57 @@ const furigana = (kanji, furigana) => `${kanji}${furigana}`; -const days = [ - furigana("日曜日", "にちようび"), - furigana("月曜日", "げつようび"), - furigana("火曜日", "かようび"), - furigana("水曜日", "すいようび"), - furigana("木曜日", "もくようび"), - furigana("金曜日", "きんようび"), - furigana("土曜日", "どようび"), -]; - -const months = [ - "一月", - "二月", - "三月", - "四月", - "五月", - "六月", - "七月", - "八月", - "九月", - "十月", - "十一月", - "十二月", -]; - -function updateClock() { - var m = new Date(); - var dateStr = - days[m.getDay()] + +const updateClock = () => { + const days = [ + furigana("日曜日", "にちようび"), + furigana("月曜日", "げつようび"), + furigana("火曜日", "かようび"), + furigana("水曜日", "すいようび"), + furigana("木曜日", "もくようび"), + furigana("金曜日", "きんようび"), + furigana("土曜日", "どようび"), + ]; + const months = [ + "一月", + "二月", + "三月", + "四月", + "五月", + "六月", + "七月", + "八月", + "九月", + "十月", + "十一月", + "十二月", + ]; + const today = new Date(); + const dateString = + days[today.getDay()] + "、" + - months[m.getMonth()] + + months[today.getMonth()] + " " + - m.getDate() + + today.getDate() + "、" + - m.getFullYear() + + today.getFullYear() + " | " + - ("0" + m.getHours()).slice(-2) + + ("0" + today.getHours()).slice(-2) + ":" + - ("0" + m.getMinutes()).slice(-2) + + ("0" + today.getMinutes()).slice(-2) + ":" + - ("0" + m.getSeconds()).slice(-2); - document.getElementById("time").innerHTML = dateStr; + ("0" + today.getSeconds()).slice(-2); + + document.getElementById("time").innerHTML = dateString; setTimeout(updateClock, 500); -} +}; -function weather() { - var key = "40d2bf562ba19169b08d75a16f3756c1"; - var lat = "45.53929"; - var lon = "-122.38731"; +const weather = () => { + const key = "40d2bf562ba19169b08d75a16f3756c1"; + const latitude = "45.53929"; + const longitude = "-122.38731"; fetch( - `https://api.openweathermap.org/data/2.5/onecall?units=metric&lat=${lat}&lon=${lon}&exclude=minutely,hourly&appid=${key}` + `https://api.openweathermap.org/data/2.5/onecall?units=metric&lat=${latitude}&lon=${longitude}&exclude=minutely,hourly&appid=${key}` ) .then((resp) => resp.json()) .then((data) => { @@ -61,10 +60,10 @@ function weather() { .catch((e) => { console.log(`ERROR! ${e}`); }); -} +}; -function displayWeather(data) { - var conditions = { +const displayWeather = (data) => { + const conditions = { 200: "thunderstorms, light rain", 201: "thunderstorms, rain", 202: "thunderstorms, heavy rain", @@ -126,13 +125,15 @@ function displayWeather(data) { 803: "broken clouds", 804: "overcast", }; - var currentWeather = `${data.current.temp.toFixed(0)}${furigana("度", "ど")} + const currentWeather = `${data.current.temp.toFixed(0)}${furigana( + "度", + "ど" + )} ${conditions[data.current.weather[0].id]} (${furigana( "体感温度", "たいかんおんど" )}${data.current.feels_like.toFixed(0)}${furigana("度", "ど")})`; - - var tmrrwWeather = `${data.daily[1].temp.day.toFixed(0)}${furigana( + const tomorrowsWeather = `${data.daily[1].temp.day.toFixed(0)}${furigana( "度", "ど" )} @@ -142,18 +143,10 @@ function displayWeather(data) { )}${data.daily[1].feels_like.day.toFixed(0)}${furigana("度", "ど")})`; document.getElementById("current").innerHTML += currentWeather; - document.getElementById("tmrrw").innerHTML += tmrrwWeather; -} + document.getElementById("tmrrw").innerHTML += tomorrowsWeather; +}; -function chooseWaifu() { - // imgs = [ - // "https://safebooru.org//images/4328/bd9ffeae0248d21841160ee8e605856371d11c4f.jpg", - // "https://safebooru.org//samples/4328/sample_03c998b6ad2f7f36116699b383890ae113e64fca.jpg", - // "https://safebooru.org//samples/4328/sample_fe9ee936fdf55235fcb31a2276f23b1b581773bb.jpg", - // ]; - // doc.getElementById("waifu").src = `${ - // imgs[Math.floor(Math.random() * imgs.length)] - // }`; +const chooseWaifu = () => { fetch("https://api.waifu.im/search").then((response) => { response.json().then((json) => { document.getElementById("waifu").src = json["images"][0]["url"]; @@ -163,10 +156,11 @@ function chooseWaifu() { json["images"][0]["artist"]["pixiv"]; }); }); -} +}; -window.onload = function () { +window.onload = () => { chooseWaifu(); weather(); }; + updateClock(); -- cgit v1.2.3