Skip to content

Commit

Permalink
feat: add GM.openInTab.options.setParent close #121
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdawn committed Oct 7, 2024
1 parent e2c6229 commit 1540f14
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/VideoCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/components/VideoCard/top-marks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/VideoCard/use/_pip-window.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 1 addition & 4 deletions src/components/VideoCard/use/useOpenRelated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mode, () => void> = {
Expand Down
7 changes: 7 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 1540f14

Please sign in to comment.