Skip to content

Commit

Permalink
feat:在popup页面显示当前域名是否触发规则
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Dec 11, 2023
1 parent 4bcba07 commit 27df2d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,13 +805,13 @@ async function processDomain(tab: chrome.tabs.Tab, throwErrors = true): Promise<
throw new Error('Invalid URL in processDomain:' + url)
}
const trackedDomains = await getTrackedDomains() //8.27
const rootDomain = getRootDomain(url, trackedDomains)
let rootDomain = getRootDomain(url, trackedDomains)
// if (!rootDomain) {
// throw new Error('Root domain not found in processDomain.')
// }
if (!rootDomain && !throwErrors){
//只有在手动保存,且之前没有在trackeddomain里找到对应的域名的时候才会触发这个设置 12.10
rootDomain = url.hostname
rootDomain = new URL(tab.url).hostname
}

//trackedDomains.includes(rootDomain)这个代码现在应该可以去掉12.10
Expand All @@ -820,6 +820,9 @@ async function processDomain(tab: chrome.tabs.Tab, throwErrors = true): Promise<
return [rootDomain, key]
} else {
if (throwErrors) {
chrome.storage.local.set({
error: 'This domain is not tracked:' + new URL(tab.url).hostname,
})
throw new Error(
'This domain is not tracked in processDomain. url: ' +
url
Expand All @@ -831,7 +834,7 @@ async function processDomain(tab: chrome.tabs.Tab, throwErrors = true): Promise<
}
}

function getRootDomain(url: string, trackedDomains=[]): string | null {
function getRootDomain(url: string, trackedDomains:string[]=[]): string | null {
try {
if (
url.startsWith('localhost') ||
Expand Down
5 changes: 5 additions & 0 deletions src/components/StorageManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const state = reactive({
errorMessage: ''
});
chrome.storage.local.get('error', (data) => {
console.log('error in popup from back', data.error);
state.errorMessage = data.error || [];
});
const clearError = () => {
state.errorMessage = '';
};
Expand Down

0 comments on commit 27df2d6

Please sign in to comment.