vivaldi-redirects/service-worker.js
2024-08-28 19:11:27 +02:00

40 lines
1,012 B
JavaScript

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://yewtu.be/watch?v=${videoId}` }
)
} else {
chrome.tabs.update(
tabId,
{ url: `https://yewtu.be` }
)
}
}, {
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' },
]
})