From 068eb3f238e6da40444dff5d7c53d060dca15429 Mon Sep 17 00:00:00 2001 From: ipcjs Date: Sat, 9 Apr 2022 07:09:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=A7=A3=E5=86=B3=E6=89=BE?= =?UTF-8?q?=E4=B8=8D=E5=88=B0bgm=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imorz/bangumi-bgmlist.user.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/imorz/bangumi-bgmlist.user.js b/imorz/bangumi-bgmlist.user.js index 3a2931c..847d9ab 100644 --- a/imorz/bangumi-bgmlist.user.js +++ b/imorz/bangumi-bgmlist.user.js @@ -21,13 +21,12 @@ function getOnAirYearMonth() { if (date == undefined) throw "on-air date not found"; let [_, year, month] = date.parentElement.textContent .match(/(\d{4})年(\d{1,2})月/); - month = month.padStart(2, '0'); - return [year, month]; + return [+year, +month]; } // return full bgm list on given on-air date async function getBgmList(year, month) { - const url = BGMLIST_URL.replace('$Y', year).replace('$M', month); + const url = BGMLIST_URL.replace('$Y', year.toString()).replace('$M', month.toString().padStart(2, '0')); const resp = await fetch(url, FETCH_PARAMS); if (!resp.ok) throw "fail to fetch bgmlist: " + resp.status; let list = await resp.json(); @@ -70,7 +69,7 @@ function addInfoRow(title, links) { } function addOnAirSites(bgm, sites) { - const links = bgm.sites.map(({site, id, url}) => { + const links = bgm.sites.map(({ site, id, url }) => { const info = sites[site]; if (!info) return; if (!url) @@ -87,10 +86,12 @@ window.addEventListener('DOMContentLoaded', async () => { try { const bgmId = location.pathname.match(/\/subject\/(\d+)/)[1]; const [year, month] = getOnAirYearMonth(); - const bgm = (await getBgmList(year, month)).get(bgmId); + let bgm = (await getBgmList(year, month)).get(bgmId) + ?? (await getBgmList(year, month - 1)).get(bgmId) + ?? (await getBgmList(year, month + 1)).get(bgmId); if (!bgm) - throw `#${bgmId} not found in bgmlist-${year}-${month}`; + throw `#${bgmId} not found in bgmlist-${year}-${month}|${month - 1}|${month + 1}`; const sites = await getSiteInfo(); addOnAirSites(bgm, sites);