Skip to content

Commit

Permalink
refactor: update sidepanel
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Jul 14, 2024
1 parent 0b48b67 commit 8e24987
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
52 changes: 31 additions & 21 deletions entrypoints/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,46 @@ export default defineBackground(() => {

setTimeout(() => {
browser.tabs.onUpdated.addListener((tabId, info, tab) => {
if (!tab.url) return;
if (!tab.url || tab.url === 'null') {
chrome.sidePanel.setOptions({
tabId,
enabled: false,
});
return;
}

const url = new URL(tab.url);
const domains = [
'https://www.google.com',
'https://www.bing.com',
'https://baidu.com',
'https://www.baidu.com',
];

// 部分页面不开启侧边栏
if (!domains.includes(url.origin) && !tab.url?.startsWith('chrome://')) {
chrome.sidePanel.setOptions({
tabId,
path: pages.sidePanelPage,
enabled: true,
});
} else {
chrome.sidePanel.setOptions({
tabId,
enabled: false,
});
return;
const origin = tab.url;

switch (true) {
case origin.startsWith('https://') && !domains.includes(url.origin):
chrome.sidePanel.setOptions({
tabId,
enabled: true,
path: pages.sidePanelPage,
});
if (info.status === 'complete') {
chrome.tabs.sendMessage(tabId, {
type: 'routeUpdate',
// data: origin
});
}
break;

default:
chrome.sidePanel.setOptions({
tabId,
enabled: false,
});
}

// 页面路由发生变化通知侧边栏前端页面更新
if (info.status === 'complete') {
chrome.tabs.sendMessage(tabId, {
type: 'routeUpdate',
data: tab.url,
});
}
});
}, 1000);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "usewiki2",
"description": "Convert HTML to Markdown, and save to your computer, support nodejs tiddlywiki",
"private": true,
"version": "4.5.7",
"version": "4.5.8",
"type": "module",
"scripts": {
"dev": "wxt --mode development",
Expand Down
2 changes: 1 addition & 1 deletion wxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default defineConfig({
},
// NOTE: 这会影响网络请求,比如获取 status, 开发环境下无影响
host_permissions: ['<all_urls>'],
// host_permissions: ['https://*/*'],
// host_permissions: ['https://*/*', 'http://*/*'],
// optional_permissions: ['https://google.com/**', 'https://bing.com/'],
// https://developer.chrome.com/docs/extensions/reference/api/sidePanel
// sidebar_action: {
Expand Down

0 comments on commit 8e24987

Please sign in to comment.