feat: 날씨 위젯에서 아침·낮·저녁·밤을 눌러 그 시간대 점수와 한마디 보기

- 서버가 카드 데이터에 시간대별 날씨 점수와 한마디(앱과 같은 65점 규칙: '오늘 낮은 ○○각!'/'…쉬어 가요')를 넣음
- 카드 4칸을 버튼으로: 누르면 점수·하늘·해와 달·한마디가 그 시간대로 바뀌고, 상세형 요약·상태 줄은 숨김(자리는 유지)
- 같은 칸을 다시 누르면 다시 그리지 않음, 누른 칸에 초점 유지, 휴대폰 터치 반짝임 없앰
- ASSET_VERSION 11
This commit is contained in:
skkim committed 2026-11-26 13:43:31 +09:00
1 parent dc8201e5f5
commit c5129d14ed
6 files changed
+259 -40

No files matched your search

+32 -3
View File
@@ -19,6 +19,8 @@
로딩·실패 화면은 상자(.wx) 안에 있어 같은 모서리로 잘린다.
8. 원본은 다 그린 카드 전체가 링크(.wx-go::after 가 카드를 덮음)다. 여기서는 '자세히 보기 ›' 버튼만 링크다 — 붙인 사이트
방문자가 카드를 잘못 눌러 페이지를 떠나지 않게. ::after 는 버튼의 눌리는 자리를 위아래로 넓히는 데만 쓴다.
9. 아래 4칸이 버튼(.wx-cell, card.js 가 누르면 그 시간대로 다시 그린다)이다. 모양은 원본 칸 그대로이고, 원본의 '지금'
칸 강조(li.is-now)를 보이는 칸 강조(.wx-cell.is-on)로 옮겼다. 다른 시간대를 보일 때 상세형 요약·상태 줄은 자리만 남긴다.
배경(상자 클래스 wx-bg-*, card.js 는 몰라도 된다):
- sky: 군산각 그대로, 시간대별 하늘.
- light: 밝은 바탕 사이트용. 시간대별 하늘을 옅은 파스텔로, 어두운 글자, 얇은 안쪽 테두리, 별 없음, 흰 구름.
@@ -539,13 +541,32 @@ html, body {
border-radius: 18px;
background: var(--wx-strip);
}
/* 칸은 버튼(.wx-cell, 원본은 li 자체가 칸). 버튼 기본 테두리·바탕·글자를 지워 원본 칸 모양 그대로 */
.wx-strip li {
display: flex;
min-width: 0;
}
.wx-cell {
flex: 1 1 auto;
display: flex;
flex-direction: column;
align-items: center;
min-width: 0;
margin: 0;
padding: 6px 0;
border: 0;
border-radius: 14px;
background: none;
color: inherit;
font: inherit;
letter-spacing: inherit;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
touch-action: manipulation;
}
.wx-cell:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 2px;
}
.wx-cn {
max-width: 100%;
@@ -566,12 +587,12 @@ html, body {
font-synthesis: none;
letter-spacing: 0;
}
.wx-strip li.is-now {
.wx-cell.is-on {
background: #fff;
color: #28304a;
box-shadow: 0 4px 12px rgba(40, 48, 74, .1);
}
.wx-strip li.is-now .wx-cn {
.wx-cell.is-on .wx-cn {
color: #c2471b;
opacity: 1;
}
@@ -627,7 +648,7 @@ html, body {
margin-top: 6px;
border-radius: 14px;
}
.wx-side .wx-strip li {
.wx-side .wx-cell {
padding: 4px 0;
border-radius: 11px;
}
@@ -796,6 +817,10 @@ html, body {
max-height: 42px;
overflow: hidden;
}
/* 더한 것: 다른 시간대 칸을 고르면 지금 값인 요약·상태 줄을 감춘다. 자리는 남겨 카드가 움직이지 않게 (card.js 가 is-hidden 을 붙인다) */
.wx-sum.is-hidden, .wx-st.is-hidden {
visibility: hidden;
}
/* 움직임 */
@media (prefers-reduced-motion: no-preference) {
@@ -805,6 +830,10 @@ html, body {
.wx-home :is(.wx-cl, .wx-ob) {
animation: wx-drop 1.05s cubic-bezier(.22, .9, .3, 1) var(--d, 0s) backwards;
}
/* 칸을 눌러 다시 그린 카드(is-again, card.js)는 해·구름이 다시 떨어지지 않고 제자리에 있다 */
.wx-home.is-again :is(.wx-cl, .wx-ob) {
animation: none;
}
.wx :is(.wx-cb, .wx-orb) {
animation: wx-float var(--f, 4.8s) ease-in-out calc(var(--d, 0s) + 1.05s) infinite;
}
+73 -31
View File
@@ -2,7 +2,7 @@
군산각(https://gunsan.webforai.kr/assets/weather.js, 2026-11-25 받은 것)의 카드 스크립트를 옮겨 왔다. 군산각의 이
카드는 날씨각 첫 화면 카드를 그대로 그린 위젯이라 점수·달 모양·하늘·4칸 줄이 날씨각과 같다. 원본과 다른 곳:
1. 날씨 값을 fetch 두 번(data-wx, data-wx-day)으로 받지 않고, 백엔드가 이 페이지에 넣어 둔 #wx-data JSON
({name, link, hero, today})을 읽어 usable() 에 {hero}, today 로 넘긴다. 8초 제한·ask()·화면에 가까워지면 묻기는
({name, link, hero, picks, today})을 읽어 usable() 에 {hero}, today 로 넘긴다. 8초 제한·ask()·화면에 가까워지면 묻기는
뺐고, 바로 그린다. fetch 가 없는 브라우저는 카드 전체가 아니라 글꼴만 포기한다.
2. 문구(지금 날씨 점수, 아침·낮·저녁·밤·지금, 자세히 보기, 하늘 이름)는 data-wx-w 대신 이 파일의 WORDS 에 둔다.
외국어 갈래(wx-intl: 숫자만 보이는 줄, 접힌 줄)는 빼고 한국어 갈래만 남겼다. 날짜는 한국어 긴 꼴로만 쓴다.
@@ -15,6 +15,11 @@
is-failed 가 붙으면 card.css 가 감춘다. 못 그렸을 때 링크 글자는 서버가 넣은 '날씨각에서 날씨 보기 ›'(원본은 '○○ 날씨
보기'와 새 창 그림)이고, 실패할 때 이 파일은 그 글자를 바꾸지 않는다. 이 파일이 아예 안 오면 card.css 가 8초 뒤 같은
링크를 보인다.
7. 아래 4칸은 버튼이다(원본은 보기만 하는 칸). 날씨각 앱 첫 화면처럼 칸을 누르면 그 시간대로 카드를 다시 그린다: 하늘
(data-t·data-sky, 구름·비·눈, 저녁·밤이면 오늘 밤 달)은 그 칸 그림과 같은 예보 칸, 점수는 hero.weather_slots, 한마디는
서버가 앱과 같은 규칙으로 만든 picks. 상세형 요약·상태 줄은 지금 값이라 자리만 두고 감춘다. '지금' 칸을 누르면 처음
모습이고, 점수나 picks 가 없는 칸도 지금 모습이다. 다시 그릴 때는 본문을 비우고 처음과 같이 만든다(글꼴은 처음 한 번만
받으므로 picks 의 한마디도 처음 글자 목록에 넣는다).
그대로 둔 것: 오늘(한국 날짜) 값이 아니면 그리지 않음, 날씨각 둥근 글꼴(Jua, Bagel Fat One)을 Google Fonts 에서
카드 글자만 받기(2.5초 넘으면 기본 글꼴), 화면 밖이면 움직임 멈춤(is-off), 그리다 실패하면 is-failed.
밖으로 나가는 요청은 이 글꼴뿐이다(쿠키·localStorage·통계 없음). 글은 textContent 로만 넣는다.
@@ -44,7 +49,7 @@
// the card's words (군산각's data-wx-w on its Korean pages)
var WORDS = {
more: "자세히 보기",
score: "지금 날씨 점수",
score: "날씨 점수", // after the cell's name: '지금 날씨 점수', '아침 날씨 점수'
slots: { morning: "아침", day: "낮", sunset: "저녁", night: "밤", now: "지금" },
sky: { sun: "맑음", sun_cloud: "구름 조금", cloud: "흐림", rain: "비", snow: "눈", moon: "맑음" }
};
@@ -245,14 +250,24 @@
}
// ------------------------------------------------------------ the card
function draw(box, D) {
// the cell shown other than now: one with its own score and words (picks, from the server); null shows now
function chosen(D, mode, k) {
var p = D.picks[k], ws = D.hero.weather_slots;
return k && k !== mode && p && typeof p.bubble === "string" && p.bubble.trim() && ws && num(ws[k]) ? k : null;
}
// k: the cell pressed (null at first: now)
function draw(box, D, k) {
var w = WORDS, side = box.classList.contains("wx-side"), h = D.hero, slots = D.slots;
var S = w.slots, SKY = w.sky;
var mode = HOUR[h.sky_mode] ? h.sky_mode : clockSky();
var now = nearest(slots), skyNow = kind(now);
var now = nearest(slots), at = chosen(D, mode, k), cell = at || mode, pk = at ? D.picks[at] : null;
box.setAttribute("data-wx-at", at || "");
// the sky of the cell shown: the same forecast as its picture in the cells below
var skyNow = kind(at ? pick(slots, HOUR[at]) : now);
var body = box.querySelector("[data-wx-b]");
if (!body) return;
box.setAttribute("data-t", mode);
body.textContent = ""; // drawn again (a cell pressed): its stars, rain and snow made anew, never twice
box.setAttribute("data-t", cell);
box.setAttribute("data-sky", skyNow);
var dt = box.querySelector("[data-wx-dt]");
if (dt && !side) dt.textContent = dateWords();
@@ -265,26 +280,29 @@
c.appendChild(el("span", "wx-cb"));
stage.appendChild(c);
}
var mn = (mode === "sunset" || mode === "night") && h.moon_name && num(h.moon_pct)
// tonight's moon from 저녁 on (the cell shown, now or pressed)
var mn = (cell === "sunset" || cell === "night") && h.moon_name && num(h.moon_pct)
? { pct: Math.max(0, Math.min(100, h.moon_pct)), waning: WANING.indexOf(h.moon_name) > -1 } : null;
var orb = el("div", "wx-orb" + (mn ? " wx-moon " + (mn.pct >= 50 ? "is-lit" : "is-dim") : ""));
if (mn) orb.appendChild(moon(mn.pct, !mn.waning, mode === "sunset" ? "dusk" : "night"));
if (mn) orb.appendChild(moon(mn.pct, !mn.waning, cell === "sunset" ? "dusk" : "night"));
var ob = el("div", "wx-ob");
ob.appendChild(orb);
stage.appendChild(ob);
body.appendChild(stage);
var score = el("p", "wx-sc");
score.appendChild(el("small", "", w.score));
score.appendChild(el("b", "", String(Math.round(h.weather_score))));
score.appendChild(el("small", "", (at ? S[at] : S.now) + " " + w.score));
score.appendChild(el("b", "", String(Math.round(at ? h.weather_slots[at] : h.weather_score))));
orb.appendChild(score);
// the words: 날씨각's own
// the words: 날씨각's own (of the cell pressed: its picks). The summary and the status line tell of now: kept in their
// place but unseen when another cell is shown (the card does not move)
var say = el("div", "wx-say");
if (typeof h.bubble === "string" && h.bubble.trim()) say.appendChild(el("p", "wx-bub", h.bubble.trim()));
var bub = at ? pk.bubble : h.bubble;
if (typeof bub === "string" && bub.trim()) say.appendChild(el("p", "wx-bub", bub.trim()));
var sum = h.top1 && typeof h.top1.summary === "string" ? h.top1.summary.trim() : "";
if (!side && sum) say.appendChild(el("p", "wx-sum", sum));
if (!side && sum) say.appendChild(el("p", "wx-sum" + (at ? " is-hidden" : ""), sum));
var st = (Array.isArray(h.status) ? h.status : []).filter(function (x) { return x && typeof x.label === "string" && typeof x.value === "string"; });
if (!side && st.length) {
var p = el("p", "wx-st");
var p = el("p", "wx-st" + (at ? " is-hidden" : ""));
st.forEach(function (x, i) {
if (i) { var dot = el("span", "wx-dot", "·"); dot.setAttribute("aria-hidden", "true"); p.appendChild(dot); }
var one = el("span", "wx-si" + (x.tone === "warn" ? " is-warn" : ""));
@@ -295,21 +313,29 @@
});
say.appendChild(p);
}
if (say.childNodes.length) body.appendChild(say);
// the four cells: 아침 · 낮 · 저녁 · 밤, the one it is now '지금'
body.appendChild(say); // always, even empty: its room stays the same whichever cell is shown
// the four cells: 아침 · 낮 · 저녁 · 밤, the one it is now '지금'; a button each, the one shown pressed
var ol = el("ol", "wx-strip");
COLS.forEach(function (k) {
var isNow = k === mode, s = isNow ? now : pick(slots, HOUR[k]), sk = kind(s);
var ic = k === "night" && sk === "clear" ? "moon" : ICON[sk];
var li = el("li", isNow ? "is-now" : "");
li.appendChild(el("span", "wx-cn", isNow ? S.now : S[k]));
COLS.forEach(function (c) {
var isNow = c === mode, s = isNow ? now : pick(slots, HOUR[c]), sk = kind(s);
var ic = c === "night" && sk === "clear" ? "moon" : ICON[sk];
var name = isNow ? S.now : S[c], tc = isNow && num(h.temp_c) ? h.temp_c : s && s.temp_c;
var li = el("li");
var b = el("button", "wx-cell" + (c === cell ? " is-on" : ""));
b.type = "button";
b.setAttribute("data-wx-k", c);
b.setAttribute("aria-pressed", c === cell ? "true" : "false");
b.setAttribute("aria-label", num(tc) ? name + " " + Math.round(tc) + "도" : name);
b.appendChild(el("span", "wx-cn", name));
var img = el("img", "wx-ic");
img.src = ICONS + ic + ".webp";
img.alt = SKY[ic] || "";
img.width = img.height = side ? 18 : 22;
img.decoding = "async";
li.appendChild(img);
li.appendChild(el("b", "wx-tc", deg(isNow && num(h.temp_c) ? h.temp_c : s && s.temp_c)));
b.appendChild(img);
b.appendChild(el("b", "wx-tc", deg(tc)));
b.addEventListener("click", function () { again(box, D, c); });
li.appendChild(b);
ol.appendChild(li);
});
body.appendChild(ol);
@@ -334,6 +360,7 @@
s += (b.querySelector(".wx-t") || {}).textContent || "";
s += WORDS.score + S.morning + S.day + S.sunset + S.night + S.now;
s += typeof h.bubble === "string" ? h.bubble : "";
COLS.forEach(function (k) { var p = D.picks[k]; s += p && typeof p.bubble === "string" ? p.bubble : ""; });
(Array.isArray(h.status) ? h.status : []).forEach(function (x) { s += (x && x.label || "") + (x && x.value || ""); });
});
return letters(s + "0123456789-–°·");
@@ -347,19 +374,34 @@
try { return JSON.parse(x.textContent); } catch (e) { return null; }
}
function fail() { boxes.forEach(function (b) { b.classList.add("is-failed"); }); }
// draw a card for cell k (null: now); one that cannot be drawn shows the link (is-failed)
function show(b, D, k) {
// oxlint-disable-next-line no-unused-vars -- 옛 브라우저용 catch 바인딩 (seoul() 참고)
try { draw(b, D, k); } catch (e) {
var x = b.querySelector("[data-wx-b]");
if (x) x.textContent = "";
b.classList.remove("is-ready");
b.classList.add("is-failed");
}
}
// a cell pressed: the card drawn again for it (is-again: the sun and clouds do not fall in again, card.css), the
// focus on that cell's new button (the cells are made anew), so the next Tab goes on to the cell after it
// a press that would show what is already shown (the same cell, or a cell without its own values) draws nothing
function again(box, D, k) {
var h = D.hero, mode = HOUR[h.sky_mode] ? h.sky_mode : clockSky();
if ((chosen(D, mode, k) || "") !== box.getAttribute("data-wx-at")) {
box.classList.add("is-again");
show(box, D, k);
}
var b = box.querySelector('[data-wx-k="' + k + '"]');
if (b) b.focus({ preventScroll: true });
}
function start() {
var g = given(), D = g && typeof g === "object" ? usable({ hero: g.hero }, g.today) : null;
if (!D) return fail();
D.picks = g.picks && typeof g.picks === "object" ? g.picks : {};
fonts(roundText(D), "0123456789", function () {
boxes.forEach(function (b) {
// oxlint-disable-next-line no-unused-vars -- 옛 브라우저용 catch 바인딩 (seoul() 참고)
try { draw(b, D); } catch (e) {
var x = b.querySelector("[data-wx-b]");
if (x) x.textContent = "";
b.classList.remove("is-ready");
b.classList.add("is-failed");
}
});
boxes.forEach(function (b) { show(b, D, null); });
});
}
start();