From 1540f147eb30982fb1be2100f0e00f7e7f6215cb Mon Sep 17 00:00:00 2001 From: magicdawn Date: Mon, 7 Oct 2024 23:56:35 +0800 Subject: [PATCH] feat: add GM.openInTab.options.setParent close #121 --- src/components/VideoCard/index.tsx | 2 +- src/components/VideoCard/top-marks.tsx | 1 + src/components/VideoCard/use/_pip-window.tsx | 2 +- src/components/VideoCard/use/useOpenRelated.tsx | 5 +---- src/vite-env.d.ts | 7 +++++++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/VideoCard/index.tsx b/src/components/VideoCard/index.tsx index a6426472..964d9366 100644 --- a/src/components/VideoCard/index.tsx +++ b/src/components/VideoCard/index.tsx @@ -410,7 +410,7 @@ const VideoCardInner = memo(function VideoCardInner({ function openInNewWindow() { const u = `/?dyn-mid=${authorMid}` - GM.openInTab(u, { insert: true, active: true }) + GM.openInTab(u, { insert: true, active: true, setParent: true }) } // newWindow ??= tab !== ETab.DynamicFeed diff --git a/src/components/VideoCard/top-marks.tsx b/src/components/VideoCard/top-marks.tsx index 7503a09e..39818178 100644 --- a/src/components/VideoCard/top-marks.tsx +++ b/src/components/VideoCard/top-marks.tsx @@ -126,6 +126,7 @@ export function RankingNumMark({ item }: { item: RankingItemExtend }) { GM.openInTab(new URL(`/video/${x.bvid}`, location.href).href, { active: true, insert: true, + setParent: true, }) }, } diff --git a/src/components/VideoCard/use/_pip-window.tsx b/src/components/VideoCard/use/_pip-window.tsx index 5e2a3da9..4facce3e 100644 --- a/src/components/VideoCard/use/_pip-window.tsx +++ b/src/components/VideoCard/use/_pip-window.tsx @@ -156,7 +156,7 @@ function CloseThenOpenButton({ newHref, pipWindow }: { pipWindow: Window; newHre const u = new URL(newHref) u.searchParams.delete(QueryKey.PlayerScreenMode) u.searchParams.delete(QueryKey.ForceAutoPlay) - GM.openInTab(u.href, { active: true }) + GM.openInTab(u.href, { active: true, insert: true, setParent: true }) } return ( diff --git a/src/components/VideoCard/use/useOpenRelated.tsx b/src/components/VideoCard/use/useOpenRelated.tsx index cb76129b..805c3487 100644 --- a/src/components/VideoCard/use/useOpenRelated.tsx +++ b/src/components/VideoCard/use/useOpenRelated.tsx @@ -75,10 +75,7 @@ export function useOpenRelated({ const handleCommon = () => { const active = mode !== Mode.Background - GM.openInTab(newHref, { - insert: true, - active, - }) + GM.openInTab(newHref, { insert: true, active, setParent: true }) } const handlers: Record void> = { diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index c35feb19..38f64507 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -15,3 +15,10 @@ declare global { | undefined } } + +declare global { + interface VMScriptGMTabOptions { + /** tempermonkey only, https://www.tampermonkey.net/documentation.php?locale=en#api:GM_openInTab */ + setParent?: boolean + } +}