Files
o2o-weather/frontend/public/embed/card.js
T
skkim dc8201e5f5 feat: 다른 사이트에 붙이는 날씨각 위젯 — 누구나 붙이는 카드(/embed/card, 기본형·상세형, 배경 3종)와 사용 방법 페이지(/widget, 스크립트·iframe 코드)
- 카드: 군산각 카드를 옮겨 그림, 토끼 로딩, 실패하면 '날씨각에서 날씨 보기' 링크, 8초 제한, nginx 대체 화면, '자세히 보기' 버튼만 링크
- 크기: 폭은 자리에 맞춰 자동, 높이는 폭에 따라 비율대로(기본형 245~320px, 상세형 400~520px)
- 부하: 지역별 카드 데이터 5분 저장, 저장분이 비면 지역마다 한 요청만 새로 만듦, 노출 수는 Redis 에 쌓았다가 관리자 조회 때 DB(widget_view_daily)로 옮김
- 사용 방법 페이지: 지역(앱 지역은 바꾸지 않음)·모양·배경 고르기, 미리보기, 코드 복사. 들어오는 길은 문의 창 버튼(토스에서는 숨김)과 검색
- GA: 위젯_안내_보기, 위젯_옵션_고름, 위젯_코드_복사
- 문서: docs/위젯_운영.md, 백엔드 테스트 실행법(CLAUDE.md)
2026-11-26 13:03:29 +09:00

378 lines
21 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* 날씨각 카드 — 다른 사이트가 iframe 으로 붙이는 /embed/card 의 카드를 그린다 (모양은 card.css).
군산각(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()·화면에 가까워지면 묻기는
뺐고, 바로 그린다. fetch 가 없는 브라우저는 카드 전체가 아니라 글꼴만 포기한다.
2. 문구(지금 날씨 점수, 아침·낮·저녁·밤·지금, 자세히 보기, 하늘 이름)는 data-wx-w 대신 이 파일의 WORDS 에 둔다.
외국어 갈래(wx-intl: 숫자만 보이는 줄, 접힌 줄)는 빼고 한국어 갈래만 남겼다. 날짜는 한국어 긴 꼴로만 쓴다.
3. 아이콘 경로 /assets/wx/ → /icons/ (날씨각 아이콘). 일출·일몰([data-sd-days]) 부분을 뺐다.
4. 원본의 빈 catch 두 곳(FontFace 만들기, document.fonts.add)을 뺐다. 글꼴 하나가 잘못되면 그 글꼴만 포기하고
(faces 의 catch), 글꼴을 붙이다 오류가 나도 카드는 그린다(finally).
5. 상세형(home) 날짜(.wx-dt)는 통째로 들어갈 때만 보인다. 원본은 좁으면 '1…' 처럼 말줄임으로 잘렸다. 카드를 그린 직후와
iframe 폭이 바뀔 때(resize) 글자 폭과 칸 폭을 비교해, 안 들어가면 상자에 is-nodt 를 붙여 숨긴다(card.css).
6. 그리기 전에는 원본의 빈 자리 표시 대신 서버 HTML 에 처음부터 든 토끼 로딩 화면(.wx-load)이 보이고, is-ready·
is-failed 가 붙으면 card.css 가 감춘다. 못 그렸을 때 링크 글자는 서버가 넣은 '날씨각에서 날씨 보기 ›'(원본은 '○○ 날씨
보기'와 새 창 그림)이고, 실패할 때 이 파일은 그 글자를 바꾸지 않는다. 이 파일이 아예 안 오면 card.css 가 8초 뒤 같은
링크를 보인다.
그대로 둔 것: 오늘(한국 날짜) 값이 아니면 그리지 않음, 날씨각 둥근 글꼴(Jua, Bagel Fat One)을 Google Fonts 에서
카드 글자만 받기(2.5초 넘으면 기본 글꼴), 화면 밖이면 움직임 멈춤(is-off), 그리다 실패하면 is-failed.
밖으로 나가는 요청은 이 글꼴뿐이다(쿠키·localStorage·통계 없음). 글은 textContent 로만 넣는다.
움직임 줄이기 설정이면 떨어지기·떠 있기·별똥별·반짝임·비 내리기·토끼 뛰기가 없다(card.css). */
(function () {
"use strict";
var doc = document, win = window;
var SVG = "http://www.w3.org/2000/svg";
function $all(sel, el) { return Array.prototype.slice.call((el || doc).querySelectorAll(sel)); }
// the visitor's date and time in Korea
function seoul() {
var o = {};
try {
new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Seoul", year: "numeric", month: "2-digit", day: "2-digit",
hour: "2-digit", minute: "2-digit", hourCycle: "h23" }).formatToParts(new Date()).forEach(function (p) { o[p.type] = p.value; });
// oxlint-disable-next-line no-unused-vars -- 바인딩 없는 catch 는 옛 브라우저에서 파일 전체가 문법 오류가 된다
} catch (e) { return null; }
if (!(o.year && o.month && o.day)) return null;
return { iso: o.year + "-" + o.month + "-" + o.day, mo: +o.month, h: (+o.hour || 0) % 24, mi: +o.minute || 0 };
}
var T = seoul(), day = T ? T.iso : "";
// ------------------------------------------------------------ weather
var boxes = $all(".wx");
if (!boxes.length) return;
// the card's words (군산각's data-wx-w on its Korean pages)
var WORDS = {
more: "자세히 보기",
score: "지금 날씨 점수",
slots: { morning: "아침", day: "낮", sunset: "저녁", night: "밤", now: "지금" },
sky: { sun: "맑음", sun_cloud: "구름 조금", cloud: "흐림", rain: "비", snow: "눈", moon: "맑음" }
};
// 날씨각's own tables (its app: the hero card)
var COLS = ["morning", "day", "sunset", "night"];
var HOUR = { morning: 7, day: 13, sunset: 18, night: 22 };
var ICON = { clear: "sun", partly: "sun_cloud", cloudy: "cloud", rain: "rain", snow: "snow", sleet: "snow" };
var CLOUDS = { clear: 0, partly: 2, cloudy: 3, rain: 3, snow: 3, sleet: 3 };
var WANING = ["기우는 달", "하현달", "그믐달"];
var SUNSET = [17.7, 18.2, 18.6, 19.1, 19.5, 19.9, 19.9, 19.5, 18.9, 18.2, 17.6, 17.3]; // its sky by the clock
var ICONS = "/icons/";
function num(v) { return typeof v === "number" && isFinite(v); }
function deg(v) { return num(v) ? Math.round(v) + "°" : "–"; }
function el(tag, cls, text) {
var e = doc.createElement(tag);
if (cls) e.className = cls;
if (text != null) e.textContent = text;
return e;
}
function clockSky() {
if (!T) return "day";
var h = T.h + T.mi / 60, s = SUNSET[T.mo - 1] || 18.5;
return h >= 5 && h < 11 ? "morning" : h >= 11 && h < s + 1 ? (h < s - 2 ? "day" : "sunset") : "night";
}
// a slot's sky as 날씨각 reads it (rain_type: 2 rain · 3 sleet · 4 snow · 5 shower; sky: 2 partly · 3 cloudy)
function kind(s) {
if (!s) return "clear";
var r = s.rain_type, k = s.sky;
if (r === 2 || r === 5) return "rain";
if (r === 4) return "snow";
if (r === 3) return "sleet";
if (k === 3) return "cloudy";
if (k === 2) return "partly";
if (r == null && k == null) return { cloud: "cloudy", rain: "rain", snow: "snow" }[s.icon] || "clear";
return "clear";
}
// the slot for a cell: the last at or before its hour (one with a figure after it when that one has none)
function pick(slots, hour) {
var n = null;
slots.forEach(function (s) { if (s.hh <= hour) n = s; });
n = n || slots[0];
if (!num(n.temp_c)) n = slots.filter(function (s) { return s.hh > hour && num(s.temp_c); })[0] || n;
return n;
}
function nearest(slots) {
var t = Date.now(), have = slots.filter(function (s) { return num(s.temp_c); });
return have.reduce(function (a, s) { return Math.abs(s.ms - t) < Math.abs(a.ms - t) ? s : a; }, have[0]);
}
function usable(feed, today) {
var h = feed && feed.hero;
if (!h || typeof h !== "object" || !num(h.weather_score)) return null;
if (!today || typeof today !== "object") return null;
if (day && (String(h.now_at || "").slice(0, 10) !== day || today.day !== day)) return null;
var slots = (today.slots || []).filter(function (s) { return s && !isNaN(Date.parse(s.at)); }).map(function (s) {
var ms = Date.parse(s.at), k = new Date(ms + 324e5); // its hour in Korea
return { ms: ms, hh: k.getUTCHours() + k.getUTCMinutes() / 60, temp_c: s.temp_c, sky: s.sky, rain_type: s.rain_type, icon: s.icon };
});
if (!slots.some(function (s) { return num(s.temp_c); })) return null;
return { hero: h, slots: slots };
}
// 날씨각's moon (its app's own drawing: the disc, its seas and craters, the shade of its phase)
var SEAS = [[-.32, -.36, .3, .26], [.12, -.36, .17, .15], [.3, -.06, .2, .17], [-.56, .06, .26, .42], [.66, -.26, .1, .12],
[.52, .22, .13, .15], [-.14, .44, .18, .13], [-.46, .5, .1, .09]];
var CRATERS = [[.1, .72, .07], [.42, .52, .05], [-.66, -.5, .05], [.62, .52, .04], [-.2, .08, .04]];
var TONES = { night: { body: ["#fffcf2", "#f6ebcb", "#e0cc98"], shade: "#1a2050" },
dusk: { body: ["#fff8ee", "#ffe2cc", "#f2b9a2"], shade: "#4a2a63" } };
var uid = 0;
function node(tag, at, kids) {
var e = doc.createElementNS(SVG, tag);
Object.keys(at || {}).forEach(function (k) { e.setAttribute(k, at[k]); });
(kids || []).forEach(function (c) { if (c) e.appendChild(c); });
return e;
}
function shadePath(pct, r) {
var f = pct / 100;
return "M0," + (-r) + " A" + r + "," + r + " 0 0 0 0," + r + " A" + (r * Math.abs(1 - 2 * f)) + "," + r + " 0 0 " + (f < .5 ? 0 : 1) + " 0," + (-r);
}
function moon(pct, waxing, tone) {
var id = "wxm" + (++uid), a = TONES[tone], o = pct / 100, full = pct >= 99, nw = pct <= 1;
var stop = function (off, c, op) { return node("stop", op == null ? { offset: off, "stop-color": c } : { offset: off, "stop-color": c, "stop-opacity": op }); };
var defs = node("defs", {}, [
node("radialGradient", { id: id + "g" }, [stop("0.6", "#fff4cf", "0.55"), stop("0.8", "#ffe9a8", "0.16"), stop("1", "#ffe9a8", "0")]),
node("radialGradient", { id: id + "b", cx: "0.4", cy: "0.36", r: "0.72" }, [stop("0", a.body[0]), stop("0.6", a.body[1]), stop("1", a.body[2])]),
node("radialGradient", { id: id + "l" }, [stop("0.72", "#8a6f3c", "0"), stop("1", "#8a6f3c", "0.28")]),
node("clipPath", { id: id + "c" }, [node("circle", { r: "1" })]),
node("filter", { id: id + "f", x: "-0.2", y: "-0.2", width: "1.4", height: "1.4" }, [node("feGaussianBlur", { stdDeviation: "0.035" })])
]);
var seas = node("g", { filter: "url(#" + id + "f)", fill: "#c4b287", opacity: "0.55" },
SEAS.map(function (e) { return node("ellipse", { cx: e[0], cy: e[1], rx: e[2], ry: e[3] }); }));
var disc = node("g", { "clip-path": "url(#" + id + "c)" }, [node("circle", { r: "1", fill: "url(#" + id + "b)" }), seas]
.concat(CRATERS.map(function (e) { return node("circle", { cx: e[0], cy: e[1], r: e[2], fill: "#efe2bd", stroke: "#cdbb8c", "stroke-width": "0.018", opacity: "0.8" }); }))
.concat([node("circle", { r: "1", fill: "url(#" + id + "l)" }),
full ? null : node("path", waxing ? { d: shadePath(pct, 1.04), fill: a.shade, opacity: "0.94", filter: "url(#" + id + "f)" }
: { d: shadePath(pct, 1.04), fill: a.shade, opacity: "0.94", filter: "url(#" + id + "f)", transform: "scale(-1,1)" })]));
return node("svg", { viewBox: "-1.5 -1.5 3 3", class: "wx-mo", "aria-hidden": "true", focusable: "false" }, [defs,
nw ? null : node("circle", { r: "1.5", fill: "url(#" + id + "g)", opacity: String(full ? 1 : .12 + .8 * o) }), disc,
nw ? node("circle", { r: "1", fill: "none", stroke: "#fff", "stroke-opacity": "0.18", "stroke-width": "0.025" }) : null]);
}
// the night sky: 날씨각's 26 stars (kept between the head and the words: a star by a letter reads as part of it,
// one behind the see-through link as a dot after it) and 3 shooting stars; rain and snow
function sky(kindNow) {
var s = el("div", "wx-stars");
s.setAttribute("aria-hidden", "true");
for (var i = 0; i < 26; i++) {
var st = el("i", i % 3 ? "" : "wx-tw");
st.style.left = (i * 37 % 100) + "%";
st.style.top = (12 + (i * 53 % 60) * .55).toFixed(1) + "%";
st.style.opacity = String(.4 + i * 7 % 6 / 10);
st.style.setProperty("--dl", (i * 0.7 % 5).toFixed(1) + "s");
s.appendChild(st);
}
[["6%", "80%", "90px", "7s", "1.5s"], ["20%", "52%", "70px", "9s", "4s"], ["34%", "94%", "80px", "11s", "6.5s"]].forEach(function (x) {
var sh = el("span", "wx-shoot");
sh.style.top = x[0];
sh.style.left = x[1];
sh.style.setProperty("--len", x[2]);
sh.style.setProperty("--dur", x[3]);
sh.style.setProperty("--dl", x[4]);
s.appendChild(sh);
});
var out = [s];
var rain = kindNow === "rain" || kindNow === "sleet", snow = kindNow === "snow" || kindNow === "sleet";
if (rain || snow) {
var f = el("div", "wx-fx");
f.setAttribute("aria-hidden", "true");
var add = function (n, cls, step, a, b, c, d) {
for (var i = 0; i < n; i++) {
var x = el("i", cls);
x.style.left = (i * step % 100) + "%";
x.style.setProperty("--top", (i * a % 90) + "%");
x.style.setProperty("--dl", (i * b % 100 / c) + "s");
x.style.setProperty("--dur", d(i) + "s");
f.appendChild(x);
}
};
if (rain) add(22, "wx-drop", 41, 29, 37, 100, function (i) { return .55 + i * 13 % 5 / 10; });
if (snow) add(16, "wx-flake", 47, 31, 53, 25, function (i) { return 3.2 + i * 7 % 5 / 2; });
out.push(f);
}
return out;
}
// the date as 날씨각 writes it ('10월 31일 토요일')
function dateWords() {
try {
return new Intl.DateTimeFormat("ko", { timeZone: "Asia/Seoul", month: "long", day: "numeric", weekday: "long" }).format(new Date());
// oxlint-disable-next-line no-unused-vars -- 옛 브라우저용 catch 바인딩 (seoul() 참고)
} catch (e) { return ""; }
}
// the date shows only whole: hidden (is-nodt, card.css) when its letters are wider than its room, never cut ('1…')
function fitDate(box) {
var dt = box.querySelector("[data-wx-dt]");
if (!dt || !dt.textContent) return;
box.classList.remove("is-nodt");
var r = doc.createRange();
r.selectNodeContents(dt);
box.classList.toggle("is-nodt", r.getBoundingClientRect().width > dt.getBoundingClientRect().width + .01);
}
// ------------------------------------------------------------ 날씨각's round fonts, only the letters the card shows
var FONTS = "https://fonts.googleapis.com/css2?family=";
function faces(family, as, text) {
// the stylesheet's faces (one or more, each with its unicode-range), loaded before they join the page; none when
// the stylesheet or a face does not come
var url = FONTS + family + "&text=" + encodeURIComponent(text) + "&display=swap";
return win.fetch(url, { mode: "cors", credentials: "omit" }).then(function (r) { return r.ok ? r.text() : ""; }).then(function (css) {
var out = [];
(css.match(/@font-face\s*{[^}]*}/g) || []).forEach(function (blk) {
var src = /src:\s*url\((https:\/\/fonts\.gstatic\.com\/[^)\s]+)\)\s*format\(['"]?woff2['"]?\)/.exec(blk);
var ur = /unicode-range:\s*([^;]+);/.exec(blk);
if (!src) return;
out.push(new win.FontFace(as, "url(" + src[1] + ") format('woff2')", ur ? { unicodeRange: ur[1].trim() } : {}));
});
return Promise.all(out.map(function (f) { return f.load(); }));
}).catch(function () { return []; });
}
function fonts(round, digits, done) {
var over = false;
var end = function (list) {
if (over) return;
over = true;
clearTimeout(t);
// they join the page now, before the card is drawn in them — never afterwards (nothing changes its letters)
try {
(list || []).forEach(function (fs) { (fs || []).forEach(function (f) { doc.fonts.add(f); }); });
} finally {
done();
}
};
var t = setTimeout(function () { end(null); }, 2500);
if (!win.FontFace || !doc.fonts || !win.Promise || !win.fetch) return end(null);
Promise.all([faces("Jua", "WxJua", round), faces("Bagel+Fat+One", "WxBagel", digits)]).then(end);
}
function letters(s) {
var seen = {}, out = "";
s.replace(/\s+/g, "").split("").forEach(function (c) { if (!seen[c]) { seen[c] = 1; out += c; } });
return out;
}
// ------------------------------------------------------------ the card
function draw(box, D) {
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 body = box.querySelector("[data-wx-b]");
if (!body) return;
box.setAttribute("data-t", mode);
box.setAttribute("data-sky", skyNow);
var dt = box.querySelector("[data-wx-dt]");
if (dt && !side) dt.textContent = dateWords();
sky(skyNow).forEach(function (x) { body.appendChild(x); });
// the sun, or the moon, with the score; 날씨각's clouds for the sky now
var stage = el("div", "wx-sky");
for (var i = 0; i < CLOUDS[skyNow]; i++) {
var c = el("span", "wx-cl wx-c" + (i + 1));
c.setAttribute("aria-hidden", "true");
c.appendChild(el("span", "wx-cb"));
stage.appendChild(c);
}
var mn = (mode === "sunset" || mode === "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"));
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))));
orb.appendChild(score);
// the words: 날씨각's own
var say = el("div", "wx-say");
if (typeof h.bubble === "string" && h.bubble.trim()) say.appendChild(el("p", "wx-bub", h.bubble.trim()));
var sum = h.top1 && typeof h.top1.summary === "string" ? h.top1.summary.trim() : "";
if (!side && sum) say.appendChild(el("p", "wx-sum", 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");
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" : ""));
one.appendChild(el("span", "wx-sl", x.label));
one.appendChild(doc.createTextNode(" "));
one.appendChild(el("b", "", x.value));
p.appendChild(one);
});
say.appendChild(p);
}
if (say.childNodes.length) body.appendChild(say);
// the four cells: 아침 · 낮 · 저녁 · 밤, the one it is now '지금'
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]));
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)));
ol.appendChild(li);
});
body.appendChild(ol);
// the link: only the 자세히 보기 button goes to 날씨각 (the rest of the card is not a link)
var go = box.querySelector("[data-wx-gl]");
if (go) {
var t = box.querySelector(".wx-t");
go.textContent = "";
go.appendChild(el("span", "vh", (t ? t.textContent : "") + " "));
go.appendChild(doc.createTextNode(w.more));
var arr = el("span", "wx-ar", "›");
arr.setAttribute("aria-hidden", "true");
go.appendChild(arr);
}
box.classList.add("is-ready");
if (!side) fitDate(box);
}
// the letters the card will show in 날씨각's round font (Jua) and in its score font (Bagel Fat One)
function roundText(D) {
var h = D.hero, S = WORDS.slots, s = "";
boxes.forEach(function (b) {
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 : "";
(Array.isArray(h.status) ? h.status : []).forEach(function (x) { s += (x && x.label || "") + (x && x.value || ""); });
});
return letters(s + "0123456789-–°·");
}
// the values the server put in the page (#wx-data); null when missing or broken
function given() {
var x = doc.getElementById("wx-data");
if (!x) return null;
// oxlint-disable-next-line no-unused-vars -- 옛 브라우저용 catch 바인딩 (seoul() 참고)
try { return JSON.parse(x.textContent); } catch (e) { return null; }
}
function fail() { boxes.forEach(function (b) { b.classList.add("is-failed"); }); }
function start() {
var g = given(), D = g && typeof g === "object" ? usable({ hero: g.hero }, g.today) : null;
if (!D) return fail();
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");
}
});
});
}
start();
// the iframe's width changed (the host page resized): look again whether the date fits
win.addEventListener("resize", function () {
boxes.forEach(function (b) { if (b.classList.contains("is-ready") && !b.classList.contains("wx-side")) fitDate(b); });
});
// a card off the screen (the host page scrolled it away) rests: its motion paused
if (win.IntersectionObserver) {
var rest = new win.IntersectionObserver(function (seen) {
seen.forEach(function (e) { e.target.classList.toggle("is-off", !e.isIntersecting); });
});
boxes.forEach(function (b) { rest.observe(b); });
}
})();