Skip to content

Commit 6ee4120

Browse files
committed
Use declarativeContent API to show/hide page action
1 parent befe630 commit 6ee4120

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

js/background.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
const boardUrl = 'trello.com/b/';
2+
13
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
24
// Match Trello board pages only
3-
var regex = new RegExp(/.*:\/\/trello\.com\/b\/.*/);
4-
var match = regex.exec(tab.url);
5+
const match = tab.url.includes(boardUrl);
56

67
// Setup page for layout changes and show page action
78
if (match) {
89
chrome.tabs.executeScript(null, {
910
file: 'js/setup-css.js'
1011
});
11-
chrome.pageAction.show(tabId);
12-
} else {
13-
chrome.pageAction.hide(tabId);
1412
}
1513
});
1614

@@ -19,3 +17,20 @@ chrome.pageAction.onClicked.addListener(function(tab) {
1917
file: 'js/toggle-layout.js'
2018
});
2119
});
20+
21+
chrome.runtime.onInstalled.addListener(function(details) {
22+
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
23+
chrome.declarativeContent.onPageChanged.addRules([{
24+
conditions: [
25+
new chrome.declarativeContent.PageStateMatcher({
26+
pageUrl: {
27+
urlContains: boardUrl
28+
}
29+
})
30+
],
31+
actions: [
32+
new chrome.declarativeContent.ShowPageAction()
33+
]
34+
}]);
35+
});
36+
});

manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"permissions": [
1717
"*://trello.com/b/*",
18+
"declarativeContent",
1819
"tabs",
1920
"storage"
2021
],

0 commit comments

Comments
 (0)