From 21aceb31ce6e8e6f43abbd5eeba4e90042adfa7e Mon Sep 17 00:00:00 2001 From: Liuweiqing <121866954+14790897@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:59:43 +0800 Subject: [PATCH] alias function and style modify --- _locales/en/messages.json | 10 +++- _locales/zh_CN/messages.json | 8 +++ src/background/index.ts | 66 ++++++++++------------ src/options/app.vue | 11 +++- src/options/index.html | 2 +- src/options/index.scss | 8 +-- src/options/pages/index.vue | 9 ++- src/popup/app.vue | 2 +- src/popup/pages/index.vue | 104 +++++++++++++++++++++++------------ 9 files changed, 135 insertions(+), 85 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 87331cb..9b8944d 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -11,6 +11,10 @@ "message": "Add", "description": "Label for the Add button" }, + "renameAccount": { + "message": "Rename", + "description": "Label for the Rename button" + }, "trackedDomainManagement": { "message": "Tracked Domain Management", "description": "Title for the tracked domain management section" @@ -28,7 +32,7 @@ "description": "Description for the first checkbox" }, "modifyLinkEnabled": { - "message": "Restrict tracked domain links to open only in the current tab", + "message": "Restrict tracked domain's links to open only in the current tab", "description": "Description for the second checkbox" }, "delete": { @@ -67,6 +71,10 @@ "message": "Load All Cookies", "description": "Title for the Load All Cookies button" }, + "options": { + "message": "Options", + "description": "open options" + }, "greeting": { "message": "Hello", "description": "Greeting text" diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json index 666f7c4..019e486 100644 --- a/_locales/zh_CN/messages.json +++ b/_locales/zh_CN/messages.json @@ -11,6 +11,10 @@ "message": "添加", "description": "添加按钮的标签" }, + "renameAccount": { + "message": "重命名", + "description": "重命名按钮的标签" + }, "trackedDomainManagement": { "message": "追踪域名管理", "description": "追踪域名管理部分的标题" @@ -66,6 +70,10 @@ "loadAllCookies": { "message": "加载所有Cookies", "description": "加载所有Cookies按钮的标题" + }, + "options": { + "message": "选项", + "description": "打开选项界面" }, "greeting": { "message": "Hello", diff --git a/src/background/index.ts b/src/background/index.ts index 0576f1d..50bb29a 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -10,6 +10,7 @@ interface Account { manualSave?: boolean closed?: boolean refresh?: boolean //加载全部cookie后,是否需要手动刷新? + alias?: string //用户手动修改的别名 9.13 } // 定义变量的类型 @@ -45,7 +46,7 @@ async function getStorageData(storageKey: string, defaultValue: T = {} as T): try { const result = await chrome.storage.local.get(storageKey) if (!result[storageKey]) { - console.log('Notice: the value is null in getStorageData.') + console.log('Notice: the value is null in getStorageData. storageKey:', storageKey)//这里不应该抛出错误,因为这个函数是用来获取数据的,如果没有数据,就返回默认值 9.13 } return (result[storageKey] || defaultValue) as T } catch (error) { @@ -172,19 +173,6 @@ chrome.runtime.onMessage.addListener(async (request: any, _sender: chrome.runtim } }) -//useless -// // 监听来自Content Script或Popup的消息 -// chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { -// if (request.type === 'LOAD_LOCALSTORAGE') { -// // 从某个存储(例如IndexedDB、chrome.storage等)中获取数据 -// const data = /* 对应账户的localStorage数据 */ loadLocalStorage(sender.tab.id, data) -// sendResponse({ status: 'Data loaded' }) -// } else if (request.type === 'SAVE_AND_CLEAR_LOCALSTORAGE') { -// saveAndClearLocalStorage(sender.tab.id) -// sendResponse({ status: 'Data saved and cleared' }) -// } -// }) - async function loadLocalStorage(tabId: number, data: Record) { try { console.log('data in loadLocalStorage:', data) @@ -446,15 +434,18 @@ async function handleTabChange(tabId: number) { const [rootDomain, key] = (await processDomain(tab)) as [string, string] // chrome.tabs.sendMessage(tabId, { action: 'showMask' }) // To show the mask in the content script, corresponding with onUpdated 8.26 - await saveCurrentCookies(rootDomain, key)//todo 这里可以将里面的保存提到外面来执行 9.13 - - const result = await saveAndClearLocalStorage(currentTabId) // save and clear localstorage 9.13 - if (result && result[0] && result[0].result) { - accounts[key].localstorage = result[0].result - await chrome.storage.local.set({ accounts: accounts }) - } - else { - console.log("can't get result in saveAndClearLocalStorage in handleTabChange.") + await saveCurrentCookies(rootDomain, key) //todo 这里可以将里面的保存提到外面来执行 9.13 + // save and clear localstorage 9.13 + const result = await saveAndClearLocalStorage(currentTabId) + try { + if (result && result[0] && result[0].result) { + accounts[key].localstorage = result[0].result + await chrome.storage.local.set({ accounts: accounts }) + } else { + console.log("can't get result in saveAndClearLocalStorage in handleTabChange.") + } + } catch (error) { + console.log('在handletapchange中需要忽视的报错 in saveAndClearLocalStorage:', error) } console.log('handleTabChange中saveCurrentCookies已触发') @@ -600,11 +591,12 @@ async function loadCookies(rootDomain: string, cookies: chrome.cookies.Cookie[]) } // 清除特定域名的所有 cookies +// todo 增加对local storage的清除 async function clearCookiesForDomain(domain: string) { try { const cookies = await chrome.cookies.getAll({ domain }) - console.log('%c ----------------------', 'background: #00ff00; color: #000') + console.log('%c clear----------------------', 'background: #00ff00; color: #000') console.log(`%c Found ${cookies.length} cookies for domain: ${domain}`, 'background: #00ff00; color: #000') const promises = cookies.map(async (cookie) => { @@ -622,7 +614,7 @@ async function clearCookiesForDomain(domain: string) { // Once all cookies are removed, print the final log line await Promise.all(promises) - console.log('%c ----------------------', 'background: #00ff00; color: #000') + console.log('%c clear----------------------', 'background: #00ff00; color: #000') } catch (error) { console.error('%c Error during cookie operation:', 'background: #ff0000; color: #fff', error) } @@ -777,24 +769,24 @@ async function modifyLinksInTab(tabId: number) { document.querySelectorAll('a').forEach(function (link) { link.target = '_self' }) - document.querySelectorAll('form').forEach(function (form) { - form.addEventListener('submit', function (event) { - event.preventDefault() - window.location.href = form.action - }) - }) + // document.querySelectorAll('form').forEach(function (form) { + // form.addEventListener('submit', function (event) { + // event.preventDefault() + // window.location.href = form.action + // }) + // }) } // 初始调用 modifyLinksAndForms() // 添加点击事件监听器 - document.body.addEventListener('click', function (event) { - if (event.target && event.target.tagName === 'A') { - event.preventDefault() - window.location.href = event.target.href - } - }) + // document.body.addEventListener('click', function (event) { + // if (event.target && event.target.tagName === 'A') { + // event.preventDefault() + // window.location.href = event.target.href + // } + // }) // 重写window.open window.open = function (url) { diff --git a/src/options/app.vue b/src/options/app.vue index f389a1c..7eb394f 100644 --- a/src/options/app.vue +++ b/src/options/app.vue @@ -10,7 +10,7 @@ -