diff --git a/_locales/en/messages.json b/_locales/en/messages.json new file mode 100644 index 0000000..87331cb --- /dev/null +++ b/_locales/en/messages.json @@ -0,0 +1,78 @@ +{ + "title":{ + "message": "CookiesClerk", + "description": "Title text" + }, + "accountManagement": { + "message": "Account Management", + "description": "Title for the account management section" + }, + "addAccount": { + "message": "Add", + "description": "Label for the Add button" + }, + "trackedDomainManagement": { + "message": "Tracked Domain Management", + "description": "Title for the tracked domain management section" + }, + "domainExample": { + "message": "Example: google.com", + "description": "Placeholder for the new domain input box" + }, + "addNewDomain": { + "message": "Add", + "description": "Placeholder for the new domain input box" + }, + "clearCookiesEnabled": { + "message": "Enable cookie clearing for new tabs in tracked domains", + "description": "Description for the first checkbox" + }, + "modifyLinkEnabled": { + "message": "Restrict tracked domain links to open only in the current tab", + "description": "Description for the second checkbox" + }, + "delete": { + "message": "Delete", + "description": "Label for the Delete button" + }, + "saveCookiesToAccount": { + "message": "Save Cookies To Account", + "description": "Title for the Save Cookies button" + }, + "loadCookiesFromAccount": { + "message": "Load Cookies From Account", + "description": "Title for the Load Cookies button" + }, + "deleteAccount": { + "message": "Delete Account", + "description": "Title for the Delete Account button" + }, + "deleteAllAccount": { + "message": "Delete All Account", + "description": "Title for the Delete All Account button" + }, + "clearAllClosedCookies": { + "message": "Clear All Closed Cookies", + "description": "Title for the Clear All Closed Cookies button" + }, + "clearCookies": { + "message": "Clear Cookies", + "description": "Title for the Clear Cookies button" + }, + "saveAllCookies": { + "message": "Save All Cookies", + "description": "Title for the Save All Cookies button" + }, + "loadAllCookies": { + "message": "Load All Cookies", + "description": "Title for the Load All Cookies button" + }, + "greeting": { + "message": "Hello", + "description": "Greeting text" + }, + "farewell": { + "message": "Goodbye", + "description": "Farewell text" + } +} diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json new file mode 100644 index 0000000..666f7c4 --- /dev/null +++ b/_locales/zh_CN/messages.json @@ -0,0 +1,78 @@ +{ + "title":{ + "message": "Cookies店员", + "description": "Title text" + }, + "accountManagement": { + "message": "账户管理", + "description": "账户管理部分的标题" + }, + "addAccount": { + "message": "添加", + "description": "添加按钮的标签" + }, + "trackedDomainManagement": { + "message": "追踪域名管理", + "description": "追踪域名管理部分的标题" + }, + "domainExample": { + "message": "例如: google.com", + "description": "域名输入框的占位符" + }, + "addNewDomain": { + "message": "添加", + "description": "新域名输入框的占位符" + }, + "clearCookiesEnabled": { + "message": "开启对追踪域名的新选项卡清除cookie功能", + "description": "第一个复选框的描述" + }, + "modifyLinkEnabled": { + "message": "限制追踪域名网页的链接只能在当前页面打开", + "description": "第二个复选框的描述" + }, + "delete": { + "message": "删除", + "description": "删除按钮的标签" + }, + "saveCookiesToAccount": { + "message": "保存Cookies到账户", + "description": "保存Cookies按钮的标题" + }, + "loadCookiesFromAccount": { + "message": "从账户加载Cookies", + "description": "加载Cookies按钮的标题" + }, + "deleteAccount": { + "message": "删除账户", + "description": "删除账户按钮的标题" + }, + "deleteAllAccount": { + "message": "删除所有账户", + "description": "删除所有账户按钮的标题" + }, + "clearAllClosedCookies": { + "message": "清除所有已关闭的Cookies", + "description": "清除所有已关闭的Cookies按钮的标题" + }, + "clearCookies": { + "message": "清除Cookies", + "description": "清除Cookies按钮的标题" + }, + "saveAllCookies": { + "message": "保存所有Cookies", + "description": "保存所有Cookies按钮的标题" + }, + "loadAllCookies": { + "message": "加载所有Cookies", + "description": "加载所有Cookies按钮的标题" + }, + "greeting": { + "message": "Hello", + "description": "Greeting text" + }, + "farewell": { + "message": "Goodbye", + "description": "Farewell text" + } +} diff --git a/manifest.config.ts b/manifest.config.ts index 484b71e..b858461 100644 --- a/manifest.config.ts +++ b/manifest.config.ts @@ -17,6 +17,7 @@ export default defineManifest(async (env) => ({ // semver is OK in "version_name" version_name: version, manifest_version: 3, + default_locale: 'en', // key: 'ekgmcbpgglflmgczajnglpbcbdccdnje', action: { default_popup: 'src/popup/index.html', diff --git a/package.json b/package.json index 4a07199..39a2781 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "vue": "^3.3.4", + "vue-i18n": "^9.4.0", "vue-router": "^4.2.2" }, "devDependencies": { @@ -57,5 +58,5 @@ "preview": "vite preview" }, "type": "module", - "version": "1.0.1" + "version": "1.0.2" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b61af53..7a89281 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ dependencies: vue: specifier: ^3.3.4 version: 3.3.4 + vue-i18n: + specifier: ^9.4.0 + version: 9.4.0(vue@3.3.4) vue-router: specifier: ^4.2.2 version: 4.2.2(vue@3.3.4) @@ -447,6 +450,27 @@ packages: - supports-color dev: true + /@intlify/core-base@9.4.0: + resolution: {integrity: sha512-bIvtuEjLES35l39R0OccYbmr/fatSr4VSRThhouvFc05mnoAZyJGgj3st1iLaHGlFTmvd507uww1427o56r36Q==} + engines: {node: '>= 16'} + dependencies: + '@intlify/message-compiler': 9.4.0 + '@intlify/shared': 9.4.0 + dev: false + + /@intlify/message-compiler@9.4.0: + resolution: {integrity: sha512-EdjqOH3bQqEjZcUOwo90wuW4ZuFr41FDxVni6WNKS0V0myKgwz9EuvLDcnEbjJMIX8vKAWPjWfnSTt5fMwKHLA==} + engines: {node: '>= 16'} + dependencies: + '@intlify/shared': 9.4.0 + source-map-js: 1.0.2 + dev: false + + /@intlify/shared@9.4.0: + resolution: {integrity: sha512-AFqymip2kToqA0B6KZPg5jSrdcVHoli9t/VhGKE2iiMq9utFuMoGdDC/JOCIZgwxo6aXAk86QyU2XtzEoMuZ6A==} + engines: {node: '>= 16'} + dev: false + /@jridgewell/gen-mapping@0.3.3: resolution: {integrity: sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==} engines: {node: '>=6.0.0'} @@ -3015,6 +3039,18 @@ packages: - supports-color dev: true + /vue-i18n@9.4.0(vue@3.3.4): + resolution: {integrity: sha512-701V7wv6m/Fesbu58rRJv9Rd3en/9F7Nxyn/NiwcR7bJkEfwflMJg5wVezkeHy1tIqjXME1e1zbHhK1dNaR8mg==} + engines: {node: '>= 16'} + peerDependencies: + vue: ^3.0.0 + dependencies: + '@intlify/core-base': 9.4.0 + '@intlify/shared': 9.4.0 + '@vue/devtools-api': 6.5.0 + vue: 3.3.4 + dev: false + /vue-router@4.2.2(vue@3.3.4): resolution: {integrity: sha512-cChBPPmAflgBGmy3tBsjeoe3f3VOSG6naKyY5pjtrqLGbNEXdzCigFUHgBvp9e3ysAtFtEx7OLqcSDh/1Cq2TQ==} peerDependencies: diff --git a/src/background/index.ts b/src/background/index.ts index 016526b..bf67e54 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -233,27 +233,41 @@ async function handleLoadAllCookies(loadSavedSelectedAccounts: boolean) { // 监听标签页更新事件 chrome.tabs.onUpdated.addListener(async function (tabId, changeInfo, tab) { try { - const tabIdDataMap: Record = await getStorageData('tabIdDataMap') - // 检查是否存在映射数据 - if (Object.prototype.hasOwnProperty.call(tabIdDataMap, tabId) && changeInfo.status === 'complete') { - const { key, account } = tabIdDataMap[tabId] - console.log(`Tab ${tabId} loaded for account key in onUpdated: ${key}`) - const tab = await chrome.tabs.get(tabId) //At first it is currenttabID, but now I change it to tabID. - const [rootDomain, _] = (await processDomain(tab)) as [string, string] - await chrome.storage.sync.set({ selectedAccount: key }) - await loadCookies(rootDomain, account.cookies) - delete tabIdDataMap[tabId] // 从映射中移除数据 - await chrome.storage.local.set({ tabIdDataMap }) // 更新存储中的映射数据 - await chrome.tabs.reload(tabId) - // 可能同时刷新多个标签页,要对符合条件的都执行脚本 9.12 - } + // 可能同时刷新多个标签页,要对符合条件的都执行脚本 9.12 const modifyLinkEnabled = await getStorageData('modifyLinkEnabled', false) //9.12 if (modifyLinkEnabled) { modifyLinksInTab(tabId) - console.log('modifyLinksInTab已经触发') } - } - catch(error) { + // const tabIdDataMap: Record = await getStorageData('tabIdDataMap') + // // 检查是否存在映射数据 + // if (Object.prototype.hasOwnProperty.call(tabIdDataMap, tabId) && changeInfo.status === 'complete') { + // const { key, account } = tabIdDataMap[tabId] + // console.log(`Tab ${tabId} loaded for account key in onUpdated: ${key}`) + // const tab = await chrome.tabs.get(tabId) //At first it is currenttabID, but now I change it to tabID. + // const [rootDomain, _] = (await processDomain(tab)) as [string, string] + // await chrome.storage.sync.set({ selectedAccount: key }) + // await loadCookies(rootDomain, account.cookies) + // delete tabIdDataMap[tabId] // 从映射中移除数据 + // await chrome.storage.local.set({ tabIdDataMap }) // 更新存储中的映射数据 + // await chrome.tabs.reload(tabId) + // } + //下面的代码是为了在刷新界面的时候如果目标网址是要追踪的网址那么就加载对应的cookies,主要是为上面的加载所有保存的账户的网页所服务的,因为它会立即切换到第一个网页,但是这时候还没有运行loadcookies的代码,所以需要在这里运行一下 9.12 + const accounts = await getStorageData>('accounts') + if (changeInfo.status === 'complete') { + for (const [key, account] of Object.entries(accounts)) { + if (account.refresh) { + if (key.includes(tabId.toString())) { + const [rootDomain, _] = (await processDomain(tab)) as [string, string] + await chrome.storage.sync.set({ selectedAccount: key }) + await loadCookies(rootDomain, account.cookies) + await chrome.tabs.reload(tabId) + account.refresh = false + } + } + } + } + await chrome.storage.local.set({ accounts: accounts }) + } catch (error) { console.log('An error occurred in onUpdated:', error) } }) @@ -407,7 +421,7 @@ async function handleTabChange(tabId: number) { //make new links only open in the current tab 8.26 // modifyLinksInTab(tabId) //It is not necessary to use await 9.9 - + // Load the appropriate cookies if (key in accounts && accounts[key]) { //让popup页面显示当前所在的账户,popup页面的显示是通过sync.get来实现的(由于每次打开会自动获取,所以不需要持续监听) 为什么要写把这个放在if语句里面?因为这说明这是一个新打开的页面,暂时不保存可以方便用户创建自己的账户 @@ -733,13 +747,12 @@ async function modifyLinksInTab(tabId: number) { observer.observe(document.body, config) }, }) - console.log('Links and forms modified to open in the same tab.') + console.log('Links and forms are modified to open in the same tab.') } catch (error) { console.log('Failed to modify links and forms', error) } } - // 清除旧通知 const clearPreviousNotification = (notificationId: string) => { chrome.notifications.clear(notificationId, (wasCleared) => { diff --git a/src/popup/index.scss b/src/popup/index.scss index 43943a9..6578bc0 100644 --- a/src/popup/index.scss +++ b/src/popup/index.scss @@ -1,5 +1,5 @@ body { - width: 480px; + width: 355px; margin: 0 auto; } diff --git a/src/popup/index.ts b/src/popup/index.ts index 4b1e124..1deecf4 100644 --- a/src/popup/index.ts +++ b/src/popup/index.ts @@ -4,6 +4,27 @@ import routes from '~pages' import '../assets/base.scss' import App from './app.vue' import './index.scss' +import { createI18n } from 'vue-i18n' + +const messages = { + en: { + title: 'Cookie Clerk', + accountManagement: 'Account Management', + add: 'Add', + saveCookies: 'Save Cookies To Account', + }, + zh_CN: { + title: 'Cookie 管理员', + accountManagement: '账户管理', + add: '添加', + saveCookies: '保存 Cookies 到账户', + }, +} + +const i18n = createI18n({ + locale: 'en', // 设置默认语言 + messages, +}) const router = createRouter({ history: createWebHashHistory(import.meta.env.BASE_URL), @@ -14,4 +35,4 @@ router.beforeEach((to) => { if (to.path === '/') return '/popup' }) -createApp(App).use(router).mount('#app') +createApp(App).use(router).use(i18n).mount('#app') diff --git a/src/popup/pages/index.vue b/src/popup/pages/index.vue index 67e80ff..90fc12e 100644 --- a/src/popup/pages/index.vue +++ b/src/popup/pages/index.vue @@ -1,11 +1,11 @@ -