This commit is contained in:
Filipe Medeiros 2024-08-06 21:06:42 +02:00
commit 386fd14a92
Signed by: filipe
GPG key ID: 9533BD5467CC1E78
5 changed files with 53 additions and 0 deletions

1
htmx.min.js vendored Normal file

File diff suppressed because one or more lines are too long

0
images/icon-128.png Normal file
View file

0
images/icon-16.png Normal file
View file

13
manifest.json Normal file
View file

@ -0,0 +1,13 @@
{
"manifest_version": 3,
"name": "Redirecter",
"version": "1.0.0",
"background": {
"service_worker": "service-worker.js",
"type": "module"
},
"permissions": [
"webNavigation",
"tabs"
]
}

39
service-worker.js Normal file
View file

@ -0,0 +1,39 @@
chrome.webNavigation.onBeforeNavigate.addListener(({ url, tabId, frameType }) => {
if (frameType === 'sub_frame') return
const match = /https?:\/\/(www\.)?((youtube.com\/watch\?v=(.{11}))|(youtu.be\/(.{11}))).*/.exec(url)
if (match) {
const videoId = match[4] ?? match[6]
chrome.tabs.update(
tabId,
{ url: `https://piped.video/watch?v=${videoId}` }
)
} else {
chrome.tabs.update(
tabId,
{ url: `https://piped.video` }
)
}
}, {
url: [
{ hostEquals: 'youtu.be' },
{ hostSuffix: 'youtube.com' },
]
})
chrome.webNavigation.onBeforeNavigate.addListener(({ url, tabId, frameType }) => {
if (frameType === 'sub_frame') return
const match = /\.com\/(.*)/.exec(url)
const path = match[1]
chrome.tabs.update(
tabId,
{ url: `https://xcancel.com/${path}` }
)
}, {
url: [
{ hostSuffix: 'x.com' },
{ hostSuffix: 'twitter.com' },
]
})