diff options
author | 2025-02-24 01:09:00 +0100 | |
---|---|---|
committer | 2025-02-24 01:09:00 +0100 | |
commit | 54a41f2431c3d60f5845a15447f13413299e41f2 (patch) | |
tree | f9395bb35ae4223a8ee944299ce430168de4d657 /examples | |
download | httptool-54a41f2431c3d60f5845a15447f13413299e41f2.tar.gz httptool-54a41f2431c3d60f5845a15447f13413299e41f2.tar.bz2 httptool-54a41f2431c3d60f5845a15447f13413299e41f2.tar.lz httptool-54a41f2431c3d60f5845a15447f13413299e41f2.zip |
feat: da extension
Diffstat (limited to 'examples')
-rw-r--r-- | examples/breeze-wiki.ts | 20 | ||||
-rw-r--r-- | examples/i2p.ts | 48 | ||||
-rw-r--r-- | examples/imgur-redirect.ts | 15 |
3 files changed, 83 insertions, 0 deletions
diff --git a/examples/breeze-wiki.ts b/examples/breeze-wiki.ts new file mode 100644 index 0000000..7e0d5d6 --- /dev/null +++ b/examples/breeze-wiki.ts @@ -0,0 +1,20 @@ +// 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; +// ^ 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( + (requestDetails) => { + const url = new URL(requestDetails.url); + url.host = + url.hostname === 'minecraft.fandom.com' + ? 'minecraft.wiki' + : url.hostname.replace('fandom.com', 'breezewiki.com'); + return { + redirectUrl: url.href, + }; + }, + { urls: ['https://fandom.com/*', 'https://*.fandom.com/*'] }, + ['blocking'] +); diff --git a/examples/i2p.ts b/examples/i2p.ts new file mode 100644 index 0000000..b9b29c4 --- /dev/null +++ b/examples/i2p.ts @@ -0,0 +1,48 @@ +// 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; +// ^ 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( + (requestDetails) => { + const url = new URL(requestDetails.url); + const params = url.searchParams; + let query = params.get('q'); + if (!query || !query.includes('.i2p')) { + return; + } else { + try { + query = query.trim(); + if (!query.startsWith('http://') && !query.startsWith('https://')) + query = `https://${query}`; + let url = new URL(query); + if (url.hostname === 'uwu' && url.protocol === 'https') { + url.protocol = 'http'; + url = new URL(url.href.replace('bad.b32.i2p/', '')); + } + if (url.hostname.endsWith('.i2p')) + return { + redirectUrl: url.href, + }; + else return; + } catch (error) { + console.warn( + 'Failed to get i2p link for', + query, + '-', + error, + '\nThis may be someone just searching a genuine search.' + ); + // Comment the below out if you don't want to cancel failed attempts at loading eepsites. Note that continuing as if nothing happened can leak information. It's recommended to only ever temporarily comment it out. + return { + cancel: true, + }; + } + } + }, + { + urls: ['https://duckduckgo.com/*q=*', 'https://*.duckduckgo.com/*q=*'], + }, + ['blocking'] +); diff --git a/examples/imgur-redirect.ts b/examples/imgur-redirect.ts new file mode 100644 index 0000000..97d7c81 --- /dev/null +++ b/examples/imgur-redirect.ts @@ -0,0 +1,15 @@ +import type Browser from 'webextension-polyfill'; +declare const browser: typeof 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( + (requestDetails) => { + const url = new URL(requestDetails.url); + url.host = 'imgur.010032.xyz'; + return { + redirectUrl: url.href, + }; + }, + { urls: ['https://imgur.com/*', 'https://www.imgur.com/*'] }, + ['blocking'] +); |