-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventPage.js
42 lines (38 loc) · 1.18 KB
/
eventPage.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
38
39
40
41
42
const mainRegex104 = '*://www.104.com.tw/*';
const memberCenterRegex104 = '*://pda.104.com.tw/*';
// onInstalled
chrome.runtime.onInstalled.addListener(function () {
queryTabsAndShowPageActions({
"active": false,
"currentWindow": true,
"url": [mainRegex104, memberCenterRegex104]
});
});
// tabs.onUpdated
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
queryTabsAndShowPageActions({
"active": true,
"currentWindow": true,
"url": [mainRegex104, memberCenterRegex104]
});
});
// tabs.onActivated
chrome.tabs.onActivated.addListener(function (tabId, changeInfo, tab) {
queryTabsAndShowPageActions({
"active": true,
"currentWindow": true,
"url": [mainRegex104, memberCenterRegex104]
});
});
// find all tabs on the browser
function queryTabsAndShowPageActions(queryObject) {
chrome.tabs.query(queryObject, (tabs) => {
if (tabs && tabs.length > 0) {
for (var i = 0; i < tabs.length; i++) {
// pageAction.show on loaded tabs
if (tabs[i].status === "complete") chrome.pageAction.show(tabs[i].id);
}
}
}
);
}