-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbackground.js
37 lines (33 loc) · 1.14 KB
/
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
28
29
30
31
32
33
34
35
36
37
// Make the extension icon turn on when visiting Last.FM
chrome.runtime.onInstalled.addListener(() => {
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'www.last.fm' }
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}
]);
});
});
// Manifest V3
const onClickAction = () => {
chrome.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
const tabId = tabs[0].id;
chrome.scripting.executeScript({ target: { tabId }, files: ['unscrobbler.js'] });
chrome.scripting.insertCSS({ target: { tabId }, files: ['unscrobbler.css'] });
});
};
chrome.action.onClicked.addListener(onClickAction);
// Manifest V2
/**
const onClickAction = () => {
chrome.tabs.executeScript(null, { file: 'unscrobbler.js' });
chrome.tabs.insertCSS(null, { file: 'unscrobbler.css' });
}
chrome.pageAction.onClicked.addListener(onClickAction);
browser.browserAction.onClicked.addListener(onClickAction);
*/