From 753e5cf3dc6b68b39ce7815e220fb474a92c35f5 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 12 Sep 2023 19:37:40 -0700 Subject: refactor(index): furigana helper --- index.js | 90 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/index.js b/index.js index 6fced16..b96e3ed 100644 --- a/index.js +++ b/index.js @@ -1,29 +1,32 @@ -const doc = document; +const furigana = (kanji, furigana) => + `${kanji}${furigana}`; + +const days = [ + furigana("日曜日", "にちようび"), + furigana("月曜日", "げつようび"), + furigana("火曜日", "かようび"), + furigana("水曜日", "すいようび"), + furigana("木曜日", "もくようび"), + furigana("金曜日", "きんようび"), + furigana("土曜日", "どようび"), +]; + +const months = [ + "一月", + "二月", + "三月", + "四月", + "五月", + "六月", + "七月", + "八月", + "九月", + "十月", + "十一月", + "十二月", +]; function updateClock() { - var days = [ - "日曜日にちようび", - "月曜日げつようび", - "火曜日かようび", - "水曜日すいようび", - "木曜日もくようび", - "金曜日きんようび", - "土曜日どようび", - ]; - var months = [ - "一月", - "二月", - "三月", - "四月", - "五月", - "六月", - "七月", - "八月", - "九月", - "十月", - "十一月", - "十二月", - ]; var m = new Date(); var dateStr = days[m.getDay()] + @@ -39,7 +42,7 @@ function updateClock() { ("0" + m.getMinutes()).slice(-2) + ":" + ("0" + m.getSeconds()).slice(-2); - doc.getElementById("time").innerHTML = dateStr; + document.getElementById("time").innerHTML = dateStr; setTimeout(updateClock, 500); } @@ -123,26 +126,23 @@ function displayWeather(data) { 803: "broken clouds", 804: "overcast", }; - var currentWeather = `${data.current.temp.toFixed( - 0 - )} - ${ - conditions[data.current.weather[0].id] - } (体感温度たいかんおんど${data.current.feels_like.toFixed( - 0 - )})`; + var 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 - )} - ${ - conditions[data.daily[1].weather[0].id] - } (体感温度たいかんおんど${data.daily[1].feels_like.day.toFixed( - 0 - )})`; + var tmrrwWeather = `${data.daily[1].temp.day.toFixed(0)}${furigana( + "度", + "ど" + )} + ${conditions[data.daily[1].weather[0].id]} (${furigana( + "体感温度", + "たいかんおんど" + )}${data.daily[1].feels_like.day.toFixed(0)}${furigana("度", "ど")})`; - doc.getElementById("current").innerHTML += currentWeather; - doc.getElementById("tmrrw").innerHTML += tmrrwWeather; + document.getElementById("current").innerHTML += currentWeather; + document.getElementById("tmrrw").innerHTML += tmrrwWeather; } function chooseWaifu() { @@ -156,8 +156,8 @@ function chooseWaifu() { // }`; fetch("https://api.waifu.im/search").then((response) => { response.json().then((json) => { - doc.getElementById("waifu").src = json["images"][0]["url"]; - doc.getElementById("waifu-link").href = + document.getElementById("waifu").src = json["images"][0]["url"]; + document.getElementById("waifu-link").href = json["images"][0]["source"] || json["images"][0]["artist"]["twitter"] || json["images"][0]["artist"]["pixiv"]; -- cgit v1.2.3