summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-09-12 19:37:40 -0700
committerFuwn <[email protected]>2023-09-12 19:38:52 -0700
commit753e5cf3dc6b68b39ce7815e220fb474a92c35f5 (patch)
treefbafb53e8ebed3bff93c180034b64914658a26c7
parentfeat(html): add reddit (diff)
downloadstartpage-753e5cf3dc6b68b39ce7815e220fb474a92c35f5.tar.xz
startpage-753e5cf3dc6b68b39ce7815e220fb474a92c35f5.zip
refactor(index): furigana helper
-rw-r--r--index.js90
1 files 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) =>
+ `<ruby>${kanji}<rt>${furigana}</rt></ruby>`;
+
+const days = [
+ furigana("日曜日", "にちようび"),
+ furigana("月曜日", "げつようび"),
+ furigana("火曜日", "かようび"),
+ furigana("水曜日", "すいようび"),
+ furigana("木曜日", "もくようび"),
+ furigana("金曜日", "きんようび"),
+ furigana("土曜日", "どようび"),
+];
+
+const months = [
+ "一月",
+ "二月",
+ "三月",
+ "四月",
+ "五月",
+ "六月",
+ "七月",
+ "八月",
+ "九月",
+ "十月",
+ "十一月",
+ "十二月",
+];
function updateClock() {
- var days = [
- "<ruby>日曜日<rt>にちようび</rt></ruby>",
- "<ruby>月曜日<rt>げつようび</rt></ruby>",
- "<ruby>火曜日<rt>かようび</rt></ruby>",
- "<ruby>水曜日<rt>すいようび</rt></ruby>",
- "<ruby>木曜日<rt>もくようび</rt></ruby>",
- "<ruby>金曜日<rt>きんようび</rt></ruby>",
- "<ruby>土曜日<rt>どようび</rt></ruby>",
- ];
- 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
- )}<ruby>度<rt>ど</rt></ruby>
- ${
- conditions[data.current.weather[0].id]
- } (<ruby>体感温度<rt>たいかんおんど</rt></ruby>${data.current.feels_like.toFixed(
- 0
- )}<ruby>度<rt>ど</rt></ruby>)`;
+ 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
- )}<ruby>度<rt>ど</rt></ruby>
- ${
- conditions[data.daily[1].weather[0].id]
- } (<ruby>体感温度<rt>たいかんおんど</rt></ruby>${data.daily[1].feels_like.day.toFixed(
- 0
- )}<ruby>度<rt>ど</rt></ruby>)`;
+ 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"];