Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

連続再生機能 #67

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
}
}
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 26 additions & 5 deletions src/content_scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
});

Expand All @@ -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);
}
}
}
});
Expand Down Expand Up @@ -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": {
Expand Down
7 changes: 5 additions & 2 deletions src/content_scripts/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ function use_state<T>(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);
}
Expand All @@ -49,8 +51,9 @@ type mode = ("list" | "nico")[];
export const [mode, set_mode, on_mode_change] = use_state<mode>(
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
Expand Down
2 changes: 2 additions & 0 deletions src/options/components/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ function Options() {
<Editor _key="enable_auto_scroll" />
<Separator />
<Editor _key="comment_area_width_px" />
<Separator />
<Editor _key="load_comments_on_next_video" />
</>
}
/>
Expand Down
19 changes: 17 additions & 2 deletions src/popup/components/search_result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
along with d-comments. If not, see <https://www.gnu.org/licenses/>.
*/

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 -> "〇時間〇分〇秒" | "〇分〇秒" | "〇秒" | "は取得できませんでした"
Expand Down Expand Up @@ -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 ? (
<ul
Expand All @@ -94,9 +109,9 @@ function SearchResult(props: { snapshot: Snapshot }) {
>
{data.map((item) => (
<li
onClick={() => 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"
>
Expand Down
58 changes: 29 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -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":
Expand Down Expand Up @@ -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"

Expand All @@ -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" "*"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down