diff --git a/package.json b/package.json
index 32e3fb15..fdfb9168 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
},
"dependencies": {
"@element-plus/icons": "^0.0.11",
+ "@types/chrome": "^0.0.157",
"axios": "^0.21.1",
"dayjs": "^1.10.7",
"diff-match-patch": "^1.0.5",
diff --git a/src/env.d.ts b/src/env.d.ts
index a735ff23..95db616d 100644
--- a/src/env.d.ts
+++ b/src/env.d.ts
@@ -1,4 +1,5 @@
///
+///
declare module '*.vue' {
import { DefineComponent } from 'vue';
diff --git a/src/i18n/zh/content/message.ts b/src/i18n/zh/content/message.ts
index 1ea49500..df0a8204 100644
--- a/src/i18n/zh/content/message.ts
+++ b/src/i18n/zh/content/message.ts
@@ -1,3 +1,4 @@
export default {
saved: '保存成功',
+ extensionNotInstalled: '你尚未安装浏览器插件,请安装浏览器插件。'
};
diff --git a/src/pages/content/platform/Index.vue b/src/pages/content/platform/Index.vue
index d9783f77..b226eed3 100644
--- a/src/pages/content/platform/Index.vue
+++ b/src/pages/content/platform/Index.vue
@@ -6,6 +6,15 @@
+
+
+
+
@@ -14,10 +23,9 @@
-
-
+
{{ $t('common.button.setup') }}
@@ -34,6 +42,7 @@ import { Breadcrumb } from '@/components/common/index';
import PlatformService from '@/services/content/platform/service';
import { IPlatform, IPlatformListResponse } from '@/services/content/platform/types';
import { defineComponent } from 'vue';
+import { getDomainByAlias, IAlias } from '@/settings/platform';
interface IData {
items: IPlatform[];
@@ -50,6 +59,17 @@ export default defineComponent({
loading: false
};
},
+ computed: {
+ extensionInstalled() {
+ return document.getElementById('extension-id');
+ },
+ extensionId() {
+ return document.getElementById('extension-id')?.getAttribute('value');
+ },
+ extensionVersion() {
+ return document.getElementById('extension-version')?.getAttribute('value');
+ }
+ },
async mounted() {
this.loading = true;
PlatformService.getAll().then(({ data: data }: { data: IPlatformListResponse }): void => {
@@ -59,8 +79,17 @@ export default defineComponent({
});
},
methods: {
- onSetup(row) {
- console.log('333');
+ onSetup(alias: string) {
+ const domain = getDomainByAlias(alias as IAlias);
+ if (window.hasOwnProperty('chrome') && this.extensionId) {
+ chrome.runtime.sendMessage(this.extensionId?.toString(), { command: 'getCookies', domain }, (cookies) => {
+ console.log(cookies);
+ this.$store.dispatch('setCookies', {
+ alias,
+ value: cookies
+ });
+ });
+ }
}
}
});
diff --git a/src/services/content/platform/types.ts b/src/services/content/platform/types.ts
index 3a4a3b5c..7e42f8f2 100644
--- a/src/services/content/platform/types.ts
+++ b/src/services/content/platform/types.ts
@@ -1,6 +1,7 @@
export interface IPlatform {
id: number;
name: string;
+ alias: string;
description?: string;
}
diff --git a/src/settings/platform.ts b/src/settings/platform.ts
new file mode 100644
index 00000000..a82ace2b
--- /dev/null
+++ b/src/settings/platform.ts
@@ -0,0 +1,21 @@
+export const PLATFORM_ALIAS_JUEJIN = 'juejin';
+export const PLATFORM_ALIAS_CSDN = 'csdn';
+export const PLATFORM_ALIAS_ZHIHU = 'zhihu';
+export const PLATFORM_ALIAS_SIFOU = 'sifou';
+export const PLATFORM_DOMAIN_JUEJIN = '.juejin.cn';
+export const PLATFORM_DOMAIN_CSDN = '.csdn.net';
+export const PLATFORM_DOMAIN_ZHIHU = '.zhihu.com';
+export const PLATFORM_DOMAIN_SIFOU = '.segmentfault.com';
+
+export const PLATFORM_ALIAS_DOMAIN_MAP = {
+ [PLATFORM_ALIAS_JUEJIN]: PLATFORM_DOMAIN_JUEJIN,
+ [PLATFORM_ALIAS_CSDN]: PLATFORM_DOMAIN_CSDN,
+ [PLATFORM_ALIAS_ZHIHU]: PLATFORM_DOMAIN_ZHIHU,
+ [PLATFORM_ALIAS_SIFOU]: PLATFORM_DOMAIN_SIFOU
+};
+
+export type IAlias = typeof PLATFORM_ALIAS_JUEJIN | typeof PLATFORM_ALIAS_CSDN | typeof PLATFORM_ALIAS_ZHIHU;
+
+export const getDomainByAlias = (alias: IAlias) => {
+ return PLATFORM_ALIAS_DOMAIN_MAP[alias];
+};
diff --git a/src/store/index.ts b/src/store/index.ts
index 860e3496..3354659e 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -1,12 +1,16 @@
import { createStore, ActionContext } from 'vuex';
import { IUser } from '@/services/common/user/types';
import createPersistedState from 'vuex-persistedstate';
+import { IAlias as IPlatformAlias, PLATFORM_ALIAS_JUEJIN } from '@/settings/platform';
export interface IState {
count: number;
accessToken: string | undefined;
refreshToken: string | undefined;
user: IUser | undefined;
+ cookies: {
+ [PLATFORM_ALIAS_JUEJIN]: string;
+ };
}
const store = createStore({
@@ -15,7 +19,10 @@ const store = createStore({
count: 0,
accessToken: undefined,
refreshToken: undefined,
- user: undefined
+ user: undefined,
+ cookies: {
+ [PLATFORM_ALIAS_JUEJIN]: ''
+ }
};
},
mutations: {
@@ -33,6 +40,17 @@ const store = createStore({
...state.user,
...payload
};
+ },
+ setCookies(
+ state: IState,
+ payload: {
+ alias: IPlatformAlias;
+ value: Array;
+ }
+ ): void {
+ console.log('cookies', payload);
+ console.log('cookies', JSON.stringify(payload.value));
+ state.cookies[payload.alias] = JSON.stringify(payload.value);
}
},
actions: {
@@ -49,6 +67,16 @@ const store = createStore({
},
setUser({ commit }: ActionContext, payload: IUser) {
commit('setUser', payload);
+ },
+ setCookies(
+ { commit }: ActionContext,
+ payload: {
+ alias: IPlatformAlias;
+ value: Array;
+ }
+ ) {
+ console.log('setCookies', payload);
+ commit('setCookies', payload);
}
},
getters: {
@@ -63,6 +91,11 @@ const store = createStore({
},
user(state): IUser | undefined {
return state.user;
+ },
+ cookies(state) {
+ return (alias: string) => {
+ return JSON.parse(state.cookies[alias]);
+ };
}
},
plugins: [createPersistedState()]
diff --git a/yarn.lock b/yarn.lock
index 71b71227..847bd20b 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -195,6 +195,14 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"
+"@types/chrome@^0.0.157":
+ version "0.0.157"
+ resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.157.tgz#5a50bd378f4f632383c6ebbc34c88fb87d501f58"
+ integrity sha512-q5SSmA9nKaDzFi8QkJW9kW8MYwWg9O7PKPUdBxsz+3rPcIF1Kxw0Bexpd70Uq1mU6PN4DBp4qKMXQDybUeiI9w==
+ dependencies:
+ "@types/filesystem" "*"
+ "@types/har-format" "*"
+
"@types/estree@0.0.39":
version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
@@ -205,6 +213,23 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.48.tgz#18dc8091b285df90db2f25aa7d906cfc394b7f74"
integrity sha512-LfZwXoGUDo0C3me81HXgkBg5CTQYb6xzEl+fNmbO4JdRiSKQ8A0GD1OBBvKAIsbCUgoyAty7m99GqqMQe784ew==
+"@types/filesystem@*":
+ version "0.0.32"
+ resolved "https://registry.yarnpkg.com/@types/filesystem/-/filesystem-0.0.32.tgz#307df7cc084a2293c3c1a31151b178063e0a8edf"
+ integrity sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==
+ dependencies:
+ "@types/filewriter" "*"
+
+"@types/filewriter@*":
+ version "0.0.29"
+ resolved "https://registry.yarnpkg.com/@types/filewriter/-/filewriter-0.0.29.tgz#a48795ecadf957f6c0d10e0c34af86c098fa5bee"
+ integrity sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==
+
+"@types/har-format@*":
+ version "1.2.7"
+ resolved "https://registry.yarnpkg.com/@types/har-format/-/har-format-1.2.7.tgz#debfe36378f26c4fc2abca1df99f00a8ff94fd29"
+ integrity sha512-/TPzUG0tJn5x1TUcVLlDx2LqbE58hyOzDVAc9kf8SpOEmguHjU6bKUyfqb211AdqLOmU/SNyXvLKPNP5qTlfRw==
+
"@types/lodash@^4.14.172":
version "4.14.172"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.172.tgz#aad774c28e7bfd7a67de25408e03ee5a8c3d028a"