From 12e71f2e97c2af21ae66646a3639bf371972094f Mon Sep 17 00:00:00 2001 From: gobosan Date: Wed, 10 Apr 2024 21:08:24 +0900 Subject: [PATCH] load comments on next video --- bun.lockb | Bin 336406 -> 336406 bytes package.json | 16 +++---- src/config.ts | 5 +++ src/content_scripts/index.ts | 31 ++++++++++--- src/content_scripts/state.ts | 7 ++- src/options/components/options.tsx | 2 + src/popup/components/search_result.tsx | 19 +++++++- yarn.lock | 58 ++++++++++++------------- 8 files changed, 92 insertions(+), 46 deletions(-) diff --git a/bun.lockb b/bun.lockb index 28acd7dba00f5780398e9c1ec8f2b9b9502cf0fd..5eb89ad91707feb2de6ea3a9545b247aaabd0af1 100755 GIT binary patch delta 773 zcmV+g1N!`y#1xjq6p$_;HYb8~B%?PWH?fjXBiK3adXFx#GbE$^u?3OOI$u}*qu z0SJ@vG$)fVH3+l#XiNwJZjOfZx9@jmnfcehR@n5| z+S9r3708ho*bMGe(HzGW4%d?nzilqj^J*|!q@k2&oZZPogjH+qTdSW#9Nie*fGfA1 zf&p*~K#4=Fr~UcB=_`Ot;(?i2BlDqG6dCX-v5n^4A~(_xGeMfOSd9nDN|%at>e>)j z#XyY0|1X#A*;Lb*-G=&~wbnbKrP?F(Ra5L`h^0=o8QR?RSm(Awe>-Umy(iaO-^ybYoqPO41_C>> z^}@H+E&_-SKy+a?R{tEOTkzY<{2U|d$-O)iHo;LGL#F6Sy*lo(C{%oD;T#s94#M3_ zQ6YyMi|7(i6YZQ&cSAf2{xJ@yFSngN0)QAmaNe$^!kzOu2Froe^j&`b&wL)bdJlsR zaw=&ngXj~(nMQahgm!6cne`gRgD*cjGONcng!SHW?>3`7p~OdKmt9r@7(n z%wa{RC_0C=Rsy%RRs&!h8#gTg000aC0Du}5B@uxmQ_KhfUNJZ>GA=hYmoRe!838nx zN^=9V0W_EXa|0OxIJX#d1BC$rHkY1t17`s^w+40tqU-@Ux2a+TlnVhiw?1wJBZdJu zmtyn;R{=M-y7UCR5CJr|cLfCx7ni|-1RX|y^EPSTd*1r$@x1E9k za0@^JTOT|t7egd5?+h#=4BRN<{VxEx_rl093O;i|EadqIC9U_z377&&5}>LHS!I%8 z0TQ;Wx%2qb;?nklE%v#$O^yNZpFopd4_M-hBdSbkEWo&HQ}`$JVq!7ZZ2e$rC*Rs9 zXp?gAGQoTjYt9cvKuM$k&Sj)FeI0KE&>=p%?%A;?>mPhdS16B za;kfO##>z0(SCuJHN!6*Gtj5i6t4m_n2y&6Kb*V2*6Z~`m5Mflt-;aA?v`Kdtxn5< zx798Jhz>w1v)$bCnh3i4@W!QrED4+qxi)VH0%veHd6-d#U>p1*%!)k`sHZhl2>1Mh zYWr0c6LyDrJh}bGEPJ60$OIm@ojn487(itX^}+#;PGH!kcCXq=xA|u&eSjnz!eERo52>h2_RstA6UBR89-3gBW zI2_=+H=N>Qe153C0DfzmyrY@+5@RQ9o#a72DTvmE)1$Y4JA2X3h2i9O2nF@4Q;G8t zw;&oshqYD$x3yLSU>qAVEdT%j3;+Ot8WklGfg@AQ2mxL(I4&|SH#3(oa|0OxGnYzp z1G51$m;Q4D838x97<2=L0Rc0Yo^=Cf0XMe>b_1g90XMg)Vg!^60W-HgZUiHS0XLUo z^aNJ{GPk<)1iTOdGq-mI1rHaOfja~tm!MMw2A8cI1r(QoI|Lz@pi=|}x9A)NE(J?@ BQqTYZ diff --git a/package.json b/package.json index 58e61ad..e0d968d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "d-anime comments viewer", "description": "Player addon for d-anime", "author": "sopi", - "version": "2024.4.1", + "version": "2024.4.10", "private": true, "license": "GPL-3.0", "type": "module", @@ -30,11 +30,11 @@ "@xpadev-net/niconicomments": "^0.2.71", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", - "lucide-react": "^0.363.0", + "lucide-react": "^0.366.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-markdown": "^9.0.1", - "react-virtuoso": "^4.7.7", + "react-virtuoso": "^4.7.8", "rehype-raw": "^7.0.0", "rehype-slug": "^6.0.0", "remark-gfm": "^4.0.0", @@ -47,17 +47,17 @@ "devDependencies": { "@biomejs/biome": "latest", "@types/bun": "latest", - "@types/node": "^20.12.2", - "@types/react": "^18.2.73", - "@types/react-dom": "^18.2.23", + "@types/node": "^20.12.7", + "@types/react": "^18.2.75", + "@types/react-dom": "^18.2.24", "@types/webextension-polyfill": "^0.10.7", "@vitejs/plugin-react-swc": "^3.6.0", "autoprefixer": "^10.4.19", "postcss": "^8.4.38", "tailwindcss": "^3.4.3", "terser": "latest", - "typescript": "^5.4.3", - "vite": "^5.2.7", + "typescript": "^5.4.4", + "vite": "^5.2.8", "web-ext": "^7.11.0" } } diff --git a/src/config.ts b/src/config.ts index 66c1dd5..56cd426 100644 --- a/src/config.ts +++ b/src/config.ts @@ -35,6 +35,11 @@ function get_default_configs() { type: "number", text: "コメント欄の幅 (px)", }, + load_comments_on_next_video: { + value: true as boolean, + type: "switch", + text: "連続再生時に自動で次の動画のコメントを読み込む", + }, comment_area_background_color: { value: "#000000" as string, type: "color", diff --git a/src/content_scripts/index.ts b/src/content_scripts/index.ts index 21cef5d..e2ab684 100644 --- a/src/content_scripts/index.ts +++ b/src/content_scripts/index.ts @@ -29,6 +29,7 @@ import { setWorkInfo, smooth_player } from "./danime/watch"; import exportJson from "./export"; import { on_partId_change, + partId as getPartId, push_message, set_messages, set_partId, @@ -55,7 +56,10 @@ switch (url.pathname) { requestAnimationFrame(function loop() { const partId = new URLSearchParams(location.search).get("partId"); - set_partId(partId?.toString()); + set_partId({ + workId: partId?.toString(), + videoId: getPartId()?.videoId, + }); requestAnimationFrame(loop); }); @@ -68,7 +72,19 @@ switch (url.pathname) { description: "コメントを再取得してください", }; push_message(message); - set_threads(undefined); + const prev_videoId = prev.videoId; + if (!prev_videoId) { + set_threads(undefined); + return; + } + const prefix = prev_videoId.slice(0, 2); + const prev_videoId_num = Number(prev_videoId.slice(2)); + const videoId = `${prefix}${prev_videoId_num + 1}`; + if ((await getConfig("load_comments_on_next_video")) && videoId) { + await render_comments(videoId as VideoId); + } else { + set_threads(undefined); + } } } }); @@ -123,9 +139,14 @@ browser.runtime.onMessage.addListener(async (message: messages) => { if (url.pathname !== "/animestore/sc_d_pc") return; switch (message.type) { case "render_comments": { - console.log("render_comments", message.data.videoId); - - await render_comments(message.data.videoId); + const videoId = message.data.videoId; + console.log("render_comments", videoId); + + set_partId({ + videoId: videoId, + workId: getPartId()?.workId, + }); + await render_comments(videoId); break; } case "export_comments_json": { diff --git a/src/content_scripts/state.ts b/src/content_scripts/state.ts index b75849c..a2a93cc 100644 --- a/src/content_scripts/state.ts +++ b/src/content_scripts/state.ts @@ -28,7 +28,9 @@ function use_state(initial: T) { function set_state(next: T) { const prev = state; - if (Object.is(prev, next)) return; + if (typeof next === "object") { + if (JSON.stringify(prev) === JSON.stringify(next)) return; + } else if (prev === next) return; state = next; for (const listener of listeners) listener(prev, next); } @@ -49,8 +51,9 @@ type mode = ("list" | "nico")[]; export const [mode, set_mode, on_mode_change] = use_state( await get_mode_arr() ); + export const [partId, set_partId, on_partId_change] = use_state< - string | undefined + { workId?: string; videoId?: VideoId } | undefined >(undefined); export const [threads, set_threads, on_threads_change] = use_state< Threads | undefined diff --git a/src/options/components/options.tsx b/src/options/components/options.tsx index db2f021..2c910d4 100644 --- a/src/options/components/options.tsx +++ b/src/options/components/options.tsx @@ -95,6 +95,8 @@ function Options() { + + } /> diff --git a/src/popup/components/search_result.tsx b/src/popup/components/search_result.tsx index b967fb9..8384aa2 100644 --- a/src/popup/components/search_result.tsx +++ b/src/popup/components/search_result.tsx @@ -15,9 +15,11 @@ along with d-comments. If not, see . */ +import { useToast } from "@/components/ui/use-toast"; import { Suspense, useContext, useEffect, useState } from "react"; import { get_owner_info } from "../api/owner_info"; import { VideoIdContext } from "../popup"; +import { ErrorMessage } from "../utils"; /** * lengthSeconds -> "〇時間〇分〇秒" | "〇分〇秒" | "〇秒" | "は取得できませんでした" @@ -86,6 +88,19 @@ function SearchResult(props: { snapshot: Snapshot }) { const data = snapshot.data; const { videoId, setVideoId } = useContext(VideoIdContext); + const { toast } = useToast(); + + function handler(contentId: string) { + if (contentId === videoId) { + ErrorMessage(toast, { + message: { + title: "Error", + description: "既に入力されている動画IDです。", + }, + }); + } + setVideoId(contentId); + } return data.length > 0 ? (
    {data.map((item) => (
  • setVideoId(item.contentId)} + onClick={() => handler(item.contentId)} onKeyDown={(e) => { - if (e.key === "Enter") setVideoId(item.contentId); + if (e.key === "Enter") handler(item.contentId); }} className="cursor-pointer rounded hover:bg-gray-200 border-t-2 border-gray-300" > diff --git a/yarn.lock b/yarn.lock index 60f5e57..f748422 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1,6 +1,6 @@ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 -# bun ./bun.lockb --hash: 23211399A9C6013E-68104c9f22f75dc4-180CCADBCAD84AA6-31828b815f06e88d +# bun ./bun.lockb --hash: 3627827424A33721-37b1925023d839ee-7A8F2EB13324A3FD-b10591cf3aafb3a2 "@aashutoshrathi/word-wrap@^1.2.3": @@ -1249,10 +1249,10 @@ dependencies: undici-types "~5.26.4" -"@types/node@^18.0.0 || >=20.0.0", "@types/node@^20.12.2": - version "20.12.2" - resolved "https://registry.npmjs.org/@types/node/-/node-20.12.2.tgz" - integrity sha512-zQ0NYO87hyN6Xrclcqp7f8ZbXNbRfoGWNcMvHTPQp9UUrwI0mI7XBz+cu7/W6/VClYo2g63B0cjull/srU7LgQ== +"@types/node@^18.0.0 || >=20.0.0", "@types/node@^20.12.7": + version "20.12.7" + resolved "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz" + integrity sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg== dependencies: undici-types "~5.26.4" @@ -1270,18 +1270,18 @@ "@types/scheduler" "*" csstype "^3.0.2" -"@types/react@*", "@types/react@^18.2.73": - version "18.2.73" - resolved "https://registry.npmjs.org/@types/react/-/react-18.2.73.tgz" - integrity sha512-XcGdod0Jjv84HOC7N5ziY3x+qL0AfmubvKOZ9hJjJ2yd5EE+KYjWhdOjt387e9HPheHkdggF9atTifMRtyAaRA== +"@types/react@*", "@types/react@^18.2.75": + version "18.2.75" + resolved "https://registry.npmjs.org/@types/react/-/react-18.2.75.tgz" + integrity sha512-+DNnF7yc5y0bHkBTiLKqXFe+L4B3nvOphiMY3tuA5X10esmjqk7smyBZzbGTy2vsiy/Bnzj8yFIBL8xhRacoOg== dependencies: "@types/prop-types" "*" csstype "^3.0.2" -"@types/react-dom@^18.2.23": - version "18.2.23" - resolved "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.23.tgz" - integrity sha512-ZQ71wgGOTmDYpnav2knkjr3qXdAFu0vsk8Ci5w3pGAIdj7/kKAyn+VsQDhXsmzzzepAiI9leWMmubXz690AI/A== +"@types/react-dom@^18.2.24": + version "18.2.24" + resolved "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.24.tgz" + integrity sha512-cN6upcKd8zkGy4HU9F1+/s98Hrp6D4MOcippK4PoE8OZRngohHZpbJn1GsaDLz87MqvHNoT13nHvNqM9ocRHZg== dependencies: "@types/react" "*" @@ -3582,10 +3582,10 @@ lru-cache@^6.0.0: resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-10.1.0.tgz" integrity sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag== -lucide-react@^0.363.0: - version "0.363.0" - resolved "https://registry.npmjs.org/lucide-react/-/lucide-react-0.363.0.tgz" - integrity sha512-AlsfPCsXQyQx7wwsIgzcKOL9LwC498LIMAo+c0Es5PkHJa33xwmYAkkSoKoJWWWSYQEStqu58/jT4tL2gi32uQ== +lucide-react@^0.366.0: + version "0.366.0" + resolved "https://registry.npmjs.org/lucide-react/-/lucide-react-0.366.0.tgz" + integrity sha512-iUOsp/35wOkrgEzigZlZI/OhVxQZ8CmxjebdIjfSDzNBmrNYjQfKSpeKderaEFfGt3OycF1BE+wLlaqWRuoh4w== make-error@^1.3.2: version "1.3.6" @@ -4777,10 +4777,10 @@ react-style-singleton@^2.2.1: get-nonce "^1.0.0" invariant "^2.2.4" -react-virtuoso@^4.7.7: - version "4.7.7" - resolved "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-4.7.7.tgz" - integrity sha512-n9NdMNaAtxHYH6e3H6zr1Kb08sp+1XPVnfE4cEMgrvmPBLugd9eeJtQo/1uA+SHhGaPX3uqZOuQsfKbX1r8P/A== +react-virtuoso@^4.7.8: + version "4.7.8" + resolved "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-4.7.8.tgz" + integrity sha512-P0BHOsLrmfnXv1bY9Nja07nvFciRGNgM7lTRHMcVDteTDb9tLtHzajBapKGUZ5zdyUOEVWvuW6ufQxzdGN2AKw== read-cache@^1.0.0: version "1.0.0" @@ -5597,10 +5597,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@^5.4.3: - version "5.4.3" - resolved "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz" - integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg== +typescript@^5.4.4: + version "5.4.4" + resolved "https://registry.npmjs.org/typescript/-/typescript-5.4.4.tgz" + integrity sha512-dGE2Vv8cpVvw28v8HCPqyb08EzbBURxDpuhJvTrusShUfGnhHBafDsLdS1EhhxyL6BJQE+2cT3dDPAv+MQ6oLw== undici-types@~5.26.4: version "5.26.5" @@ -5803,10 +5803,10 @@ vfile-message@^4.0.0: optionalDependencies: fsevents "~2.3.3" -vite@^5.2.7: - version "5.2.7" - resolved "https://registry.npmjs.org/vite/-/vite-5.2.7.tgz" - integrity sha512-k14PWOKLI6pMaSzAuGtT+Cf0YmIx12z9YGon39onaJNy8DLBfBJrzg9FQEmkAM5lpHBZs9wksWAsyF/HkpEwJA== +vite@^5.2.8: + version "5.2.8" + resolved "https://registry.npmjs.org/vite/-/vite-5.2.8.tgz" + integrity sha512-OyZR+c1CE8yeHw5V5t59aXsUPPVTHMDjEZz8MgguLL/Q7NblxhZUlTu9xSPqlsUO/y+X7dlU05jdhvyycD55DA== dependencies: esbuild "^0.20.1" postcss "^8.4.38"