diff --git a/service-worker.js b/service-worker.js index 8f9ff7d..c0add7c 100644 --- a/service-worker.js +++ b/service-worker.js @@ -1,42 +1,49 @@ -const youtubeAlternative = 'https://invidious.nerdvpn.de' -const twitterAlternative = 'https://xcancel.com' +const youtubeAlternative = "https://inv.nadeko.net"; +const twitterAlternative = "https://xcancel.com"; +const blockList = ["google.com", "google.dk", "google.co.uk", "google.pt"]; -chrome.webNavigation.onBeforeNavigate.addListener(({ url, tabId, frameType }) => { - if (frameType === 'sub_frame') return +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) + 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: `${youtubeAlternative}/watch?v=${videoId}` } - ) + const videoId = match[4] ?? match[6]; + chrome.tabs.update(tabId, { + url: `${youtubeAlternative}/watch?v=${videoId}`, + }); } else { - chrome.tabs.update( - tabId, - { url: `https://invidious.nerdvpn.de` } - ) + chrome.tabs.update(tabId, { url: youtubeAlternative }); } -}, { - url: [ - { hostEquals: 'youtu.be' }, - { hostSuffix: 'youtube.com' }, - ] -}) + }, + { + url: [{ hostEquals: "youtu.be" }, { hostSuffix: "youtube.com" }], + } +); -chrome.webNavigation.onBeforeNavigate.addListener(({ url, tabId, frameType }) => { - if (frameType === 'sub_frame') return +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: `${twitterAlternative}/${path}` } - ) -}, { - url: [ - { hostSuffix: '.x.com' }, - { hostSuffix: '.twitter.com' }, - ] -}) + const match = /\.com\/(.*)/.exec(url); + const path = match[1]; + chrome.tabs.update(tabId, { url: `${twitterAlternative}/${path}` }); + }, + { + url: [{ hostSuffix: ".x.com" }, { hostSuffix: ".twitter.com" }], + } +); +chrome.webNavigation.onBeforeNavigate.addListener( + ({ tabId }) => { + if (frameType === "sub_frame") return; + + chrome.tabs.update(tabId, { url: "https://kagi.com" }); + }, + { + url: blockList.map((url) => ({ hostSuffix: url })), + } +);