-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
47 lines (44 loc) · 2.06 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
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2020 Linchpin, LLC. All rights reserved.
chrome.runtime.onInstalled.addListener(function () {
// On change clear all rules
chrome.declarativeContent.onPageChanged.removeRules(undefined, function () {
chrome.declarativeContent.onPageChanged.addRules([
{
// Define our viewable actions
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: {urlContains: 'wp-admin/plugins.php'},
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: {urlContains: 'wp-admin/network/plugins.php'},
}),
new chrome.declarativeContent.PageStateMatcher({
pageUrl: {urlContains: 'wp-admin/update-core.php'},
}),
],
// Show the extension's page action.
actions: [new chrome.declarativeContent.ShowPageAction()]
}
]);
});
});
chrome.tabs.onActivated.addListener((info) => {
chrome.tabs.get(info.tabId, (change) => {
if (typeof (change) !== 'undefined' && !change.url) {
chrome.browserAction.setIcon({path: './images/report32.png', tabId: info.tabId});
} else if (typeof (change) !== 'undefined' && change.url.match(/wp-admin(\/network)?\/(plugins|update-core)\.php/) == null) {
chrome.browserAction.setIcon({path: './images/report32.png', tabId: info.tabId});
} else {
chrome.browserAction.setIcon({path: './images/report_active32.png', tabId: info.tabId});
}
});
});
chrome.tabs.onUpdated.addListener(( tabId, change, tab ) => {
if ( typeof (tab) === 'undefined' || ! tab.url ) {
return;
} else if (tab.url.match(/wp-admin(\/network)?\/(plugins|update-core)\.php/) == null) {
chrome.browserAction.setIcon({path: './images/report32.png', tabId: tabId});
} else {
chrome.browserAction.setIcon({path: './images/report_active32.png', tabId: tabId});
}
});