diff --git a/src/excmds.ts b/src/excmds.ts index c9c11f09..a2d78b6a 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -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`. diff --git a/src/lib/config.ts b/src/lib/config.ts index dc15b1d7..03d66b53 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -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)", diff --git a/src/lib/webext.ts b/src/lib/webext.ts index e833588c..b4282871 100644 --- a/src/lib/webext.ts +++ b/src/lib/webext.ts @@ -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