aboutsummaryrefslogtreecommitdiff
path: root/src/parseScheduleHtml.ts
diff options
context:
space:
mode:
authorTing Shu Lin <[email protected]>2022-01-28 01:13:05 +0900
committerGitHub <[email protected]>2022-01-28 01:13:05 +0900
commit2054eda658f98de0ec44b5f3db5b70c8c8774a0b (patch)
tree243702191126f4fe0a902ab827c386fc5acf55b1 /src/parseScheduleHtml.ts
parentchore(release): 0.5.3 [skip ci] (diff)
downloadholo-schedule-2054eda658f98de0ec44b5f3db5b70c8c8774a0b.tar.xz
holo-schedule-2054eda658f98de0ec44b5f3db5b70c8c8774a0b.zip
fix(codeql): substring sanitization warning (#30)
* Create codeql-analysis.yml * fix: substring sanitization warning
Diffstat (limited to 'src/parseScheduleHtml.ts')
-rw-r--r--src/parseScheduleHtml.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/parseScheduleHtml.ts b/src/parseScheduleHtml.ts
index 3321475..598b66a 100644
--- a/src/parseScheduleHtml.ts
+++ b/src/parseScheduleHtml.ts
@@ -5,6 +5,15 @@ function selectTrimTextContent(ele: Element, selector: string): string {
return ele.querySelector(selector)?.textContent?.trim() || ''
}
+const livePreviewImageHosts: readonly string[] = [
+ 'img.youtube.com',
+ 'schedule-static.hololive.tv',
+] as const
+
+function hostOf(src: string) {
+ return new URL(src).host
+}
+
function dataFromAThumbnail(thumb: Element) {
const time = selectTrimTextContent(thumb, '.datetime')
const name = selectTrimTextContent(thumb, '.name')
@@ -14,10 +23,9 @@ function dataFromAThumbnail(thumb: Element) {
(img) => img.src,
)
- const avatarImages = images.filter((src) => src.startsWith('https://yt3.ggpht.com'))
- const livePreviewImage = images.find(src => src.startsWith('https://img.youtube.com/')) ||
- images.find(src => src.startsWith('https://schedule-static.hololive.tv/image/')) ||
- ''
+ const avatarImages = images.filter((src) => hostOf(src) === 'yt3.ggpht.com')
+ const livePreviewImage =
+ images.find(src => livePreviewImageHosts.includes(hostOf(src))) || ''
return {
time,