Add tabopen --discard and ;gd bind - fix #4694

This commit is contained in:
Oliver Blanthorn 2023-05-20 16:51:55 +02:00
parent b4bb596de8
commit 71f9e59c1c
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
3 changed files with 14 additions and 1 deletions

View file

@ -2731,6 +2731,7 @@ export async function tabopen_helper({ addressarr = [], waitForDom = false }): P
let active
let container
let bypassFocusHack = false
let discarded = false
const win = await browser.windows.getCurrent()
@ -2748,6 +2749,11 @@ export async function tabopen_helper({ addressarr = [], waitForDom = false }): P
bypassFocusHack = true
args.shift()
argParse(args)
} else if (args[0] === "--discard") {
discarded = true
active = false
args.shift()
argParse(args)
} else if (args[0] === "-c") {
if (args.length < 2) throw new Error(`You must provide a container name!`)
// Ignore the -c flag if incognito as containers are disabled.
@ -2793,6 +2799,7 @@ export async function tabopen_helper({ addressarr = [], waitForDom = false }): P
args.cookieStoreId = containerId
}
args.bypassFocusHack = bypassFocusHack
args.discarded = discarded
const maybeURL = await queryAndURLwrangler(query)
if (typeof maybeURL === "string") {
return openInNewTab(maybeURL, args, waitForDom)
@ -5170,6 +5177,7 @@ const KILL_STACK: Element[] = []
- `;gv` - "open link in MPV" - only available if you have [[native]] installed and `mpv` on your PATH
- `;m` and `;M` - do a reverse image search using Google in the current tab and a new tab
- `;x` and `;X` - move cursor to element and perform a real click or ctrl-shift-click (to open in a new foreground tab). Only available on Linux, if you have [[native]] installed and `xdotool` on your PATH
- `;d` and `;gd` - open links in discarded background tabs (defer loading until tab is switched to)
NB: by default, hinting respects whether links say they should be opened in new tabs (i.e. `target=_blank`). If you wish to override this you can use `:hint -JW open` to force the hints to open in the current tab. JavaScript hints (grey ones) will always open wherever they want, but if you want to include these anyway you can use `:hint -W open`.

View file

@ -328,6 +328,8 @@ export class default_config {
";O": "hint -W fillcmdline_notrail open ",
";W": "hint -W fillcmdline_notrail winopen ",
";T": "hint -W fillcmdline_notrail tabopen ",
";d": "hint -W tabopen --discard",
";gd": "hint -qW tabopen --discard",
";z": "hint -z",
";m": "hint -JFc img i => tri.excmds.open('https://lens.google.com/uploadbyurl?url='+i.src)",
";M": "hint -JFc img i => tri.excmds.tabopen('https://lens.google.com/uploadbyurl?url='+i.src)",

View file

@ -177,11 +177,12 @@ export async function openInNewTab(
url: string,
// NB: defaults are actually enforced just below
kwargs: { active?; related?; cookieStoreId?; bypassFocusHack? } = {
kwargs: { active?; related?; cookieStoreId?; bypassFocusHack?; discarded? } = {
active: true,
related: false,
cookieStoreId: undefined,
bypassFocusHack: false,
discarded: false,
},
waitForDOM = false,
@ -192,6 +193,7 @@ export async function openInNewTab(
related: false,
cookieStoreId: undefined,
bypassFocusHack: false,
discarded: false,
})
const thisTab = await activeTab()
@ -199,6 +201,7 @@ export async function openInNewTab(
active: kwargs.bypassFocusHack,
url,
cookieStoreId: kwargs.cookieStoreId,
discarded: kwargs.discarded,
}
// Be nice to behrmann, #342