Skip to content

Commit 4eaeac6

Browse files
committed
Remove globals.js, use user-agent to identify Chrome
1 parent 47aa5ca commit 4eaeac6

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

src/background.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ declare global {
55
const chrome: any;
66
}
77

8+
const isChrome = window.navigator.userAgent.toLowerCase().includes('chrome');
9+
810
function checkTab(tabId: number, changeInfo: object, tab: browser.tabs.Tab) {
911
browser.tabs.sendMessage(tabId, {
1012
action: MessageAction.CheckTab,
@@ -31,23 +33,31 @@ function send(tabId: number, message: string) {
3133
});
3234
}
3335

36+
function enablePageAction(tabId: number) {
37+
if (isChrome) {
38+
chrome.pageAction.show(tabId);
39+
} else {
40+
browser.pageAction.show(tabId);
41+
}
42+
}
43+
44+
function disablePageAction(tabId: number) {
45+
if (isChrome) {
46+
chrome.pageAction.hide(tabId);
47+
} else {
48+
browser.pageAction.hide(tabId);
49+
}
50+
}
51+
3452
function handleMessage(message: Message, sender: browser.runtime.MessageSender) {
3553
if (!sender.tab) return;
3654

3755
switch (message.action) {
3856
case MessageAction.EnableParsing:
39-
if ((window as any).hasChromeAPIs) {
40-
chrome.pageAction.show(message.payload.tabId);
41-
} else {
42-
browser.pageAction.show(message.payload.tabId);
43-
}
57+
enablePageAction(message.payload.tabId);
4458
break;
4559
case MessageAction.DisableParsing:
46-
if ((window as any).hasChromeAPIs) {
47-
chrome.pageAction.hide(message.payload.tabId);
48-
} else {
49-
browser.pageAction.hide(message.payload.tabId);
50-
}
60+
disablePageAction(message.payload.tabId);
5161
break;
5262
case MessageAction.SendTask:
5363
send(sender.tab.id, message.payload.message);

src/globals.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

static/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
"matches": ["Filled by build script"],
3232
"exclude_matches": ["Filled by build script"],
3333
"css": ["css/nprogress.css", "css/noty.css"],
34-
"js": ["js/globals.js", "js/browser-polyfill.js", "js/content.js"]
34+
"js": ["js/browser-polyfill.js", "js/content.js"]
3535
}
3636
],
3737

3838
"background": {
39-
"scripts": ["js/globals.js", "js/browser-polyfill.js", "js/background.js"]
39+
"scripts": ["js/browser-polyfill.js", "js/background.js"]
4040
},
4141

4242
"page_action": {

webpack.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ const config = {
7979
from: path.resolve(__dirname, 'icons'),
8080
to: path.resolve(__dirname, 'build/icons'),
8181
},
82-
{
83-
from: path.resolve(__dirname, 'src/globals.js'),
84-
to: path.resolve(__dirname, 'build/js'),
85-
},
8682
{
8783
from: path.resolve(__dirname, 'src/vendor/browser-polyfill.js'),
8884
to: path.resolve(__dirname, 'build/js'),

0 commit comments

Comments
 (0)