-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
50 lines (45 loc) · 1.2 KB
/
background.js
File metadata and controls
50 lines (45 loc) · 1.2 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
38
39
40
41
42
43
44
45
46
47
48
49
50
import {
changeIcon
} from './Utils/iconChanger.js';
import {
requestPermission,
getCurrentTab
} from './Utils/tabChanger.js';
chrome.runtime.onInstalled.addListener((reason) => {
if (reason.reason === "install") {
install_notice();
}
});
changeIconOnChange();
clickListener();
function install_notice() {
chrome.tabs.create({url: "./Pages/index.html"});
}
function clickListener() {
chrome.action.onClicked.addListener((tab) => {
if (tab.url.includes("youtube.com/shorts/")) {
chrome.permissions.contains({
permissions: ['tabs'],
origins: ['https://www.youtube.com/']
}, (granted) => {
if (granted) {
getCurrentTab();
} else {
requestPermission();
}
});
}
});
}
function changeIconOnChange() {
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
chrome.tabs.get(tabId, (tab) => {
changeIcon(tab);
});
});
chrome.tabs.onActivated.addListener((activeInfo) => {
chrome.tabs.get(activeInfo.tabId, (tab) => {
changeIcon(tab);
});
});
}