diff options
feat: exttool
Diffstat (limited to 'examples')
-rw-r--r-- | examples/breeze-wiki.ts | 4 | ||||
-rw-r--r-- | examples/i2p.ts | 4 | ||||
-rw-r--r-- | examples/imgur-redirect.ts | 4 | ||||
-rw-r--r-- | examples/open-loopback-as-new-window.ts | 29 |
4 files changed, 35 insertions, 6 deletions
diff --git a/examples/breeze-wiki.ts b/examples/breeze-wiki.ts index 7e0d5d6..af218a9 100644 --- a/examples/breeze-wiki.ts +++ b/examples/breeze-wiki.ts @@ -1,7 +1,7 @@ // This example redirects all fandom pages to breezewiki (or for minecraft.fandom.com, the minecraft wiki) -import type Browser from 'webextension-polyfill'; -declare const browser: typeof Browser; +import type { Browser } from 'webextension-polyfill'; +declare const browser: Browser; // ^ above 2 lines are optional, and only useful to allow the examples directory to not complain. The extension's monaco already defines the type of the browser global. browser.webRequest.onBeforeRequest.addListener( diff --git a/examples/i2p.ts b/examples/i2p.ts index b9b29c4..7a2cb14 100644 --- a/examples/i2p.ts +++ b/examples/i2p.ts @@ -1,7 +1,7 @@ // This example allows entering i2p eepsites into your URL bar - and assuming you're using duckduckgo, it will send you to the eepsite instead. -import type Browser from 'webextension-polyfill'; -declare const browser: typeof Browser; +import type { Browser } from 'webextension-polyfill'; +declare const browser: Browser; // ^ above 2 lines are optional, and only useful to allow the examples directory to not complain. The extension's monaco already defines the type of the browser global. browser.webRequest.onBeforeRequest.addListener( diff --git a/examples/imgur-redirect.ts b/examples/imgur-redirect.ts index 97d7c81..72ff7d9 100644 --- a/examples/imgur-redirect.ts +++ b/examples/imgur-redirect.ts @@ -1,5 +1,5 @@ -import type Browser from 'webextension-polyfill'; -declare const browser: typeof Browser; +import type { Browser } from 'webextension-polyfill'; +declare const browser: Browser; // ^ above 2 lines are optional, and only useful to allow the examples directory to not complain. The extension's monaco already defines the type of the browser global. browser.webRequest.onBeforeRequest.addListener( diff --git a/examples/open-loopback-as-new-window.ts b/examples/open-loopback-as-new-window.ts new file mode 100644 index 0000000..5806d4c --- /dev/null +++ b/examples/open-loopback-as-new-window.ts @@ -0,0 +1,29 @@ +import type { Browser } from 'webextension-polyfill'; +declare const browser: Browser; + +browser.webRequest.onBeforeRequest.addListener( + (requestDetails) => { + const url = new URL(requestDetails.url); + if (url.searchParams.has('open-tab')) { + url.searchParams.delete('open-tab'); + (async () => { + const oldTab = await browser.tabs.get(requestDetails.tabId) + console.warn(url.href); + + await browser.windows.create({ + type: 'popup', + width: 768, + height: 512, + url: [url.href] + }); + + await browser.tabs.remove(oldTab.id!) + })() + return { + cancel: true + }; + } + }, + { urls: ['http://127.0.0.1/*', 'http://localhost/*'] }, + ['blocking'] +); |