-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbackground-chrome.js
More file actions
37 lines (32 loc) · 1.22 KB
/
background-chrome.js
File metadata and controls
37 lines (32 loc) · 1.22 KB
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
28
29
30
31
32
33
34
35
36
37
const urlPattern = /https?:\/\/(www|m)\.youtube\.com\/shorts\/([a-zA-Z0-9_-]{11})/;
let shortsInOriginalVideoPlayer = false;
function onTabUpdated(tabId, changeInfo, x) {
if (!shortsInOriginalVideoPlayer || !changeInfo.url) return;
const found = changeInfo.url.match(urlPattern);
if (found) {
chrome.tabs.update(tabId, {
url: `https://${found[1]}.youtube.com/watch?v=${found[2]}`
});
}
}
function setupBackground() {
chrome.storage.local.get(null, function (value) {
if (value.shortsInOriginalVideoPlayer == undefined)
chrome.storage.local.set({ shortsInOriginalVideoPlayer: shortsInOriginalVideoPlayer });
shortsInOriginalVideoPlayer = value.shortsInOriginalVideoPlayer
if (shortsInOriginalVideoPlayer) {
if (!chrome.tabs.onUpdated.hasListener(onTabUpdated)) {
chrome.tabs.onUpdated.addListener(onTabUpdated);
}
}
else {
if (chrome.tabs.onUpdated.hasListener(onTabUpdated)) {
chrome.tabs.onUpdated.removeListener(onTabUpdated);
}
}
});
}
chrome.storage.onChanged.addListener(function () {
setupBackground()
});
setupBackground()