-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
27 lines (23 loc) · 957 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
chrome.browserAction.onClicked.addListener(function (tab) {
if (isYouTubeWatchPage(tab.url)) {
console.log("On a YouTube watch page. Redirecting...");
chrome.tabs.update(tab.id, { url: modifyYouTubeURL(tab.url) });
} else {
console.log("Not on a YouTube watch page.");
// Show a badge with a "no entry" symbol
chrome.browserAction.setBadgeText({ text: "🚫" });
// Set the badge background color to white
chrome.browserAction.setBadgeBackgroundColor({ color: [255, 255, 255, 255] }); // Red background
// Clear the badge after a few seconds (adjust as needed)
setTimeout(function () {
chrome.browserAction.setBadgeText({ text: "" });
}, 3000);
}
});
function isYouTubeWatchPage(url) {
return /^(https?:\/\/)?(www\.)?youtube\.com\/watch\?v=/.test(url);
}
function modifyYouTubeURL(url) {
// Replace "watch?v=" with "embed/"
return url.replace(/youtube\.com\/watch\?v=/, "youtube.com/embed/");
}