From abf72b183f64ab6da40d7c4d6fc7dbbe9fa77009 Mon Sep 17 00:00:00 2001 From: oeyoews Date: Sat, 23 Mar 2024 12:40:29 +0800 Subject: [PATCH] feat: support tags --- README.md | 1 - auto-imports.d.ts | 2 +- components.d.ts | 1 + entrypoints/content.ts | 1 - entrypoints/popup/Popup.vue | 66 +++++++++++++++++++++++++++++++++---- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dc95add..2fa47fa 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ * 完成 welcome page * tour: https://element-plus.org/zh-CN/component/tour.html -* tag * port 通知优化 * extension icon * 统计大小 diff --git a/auto-imports.d.ts b/auto-imports.d.ts index 1d89ee8..78813d8 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -5,5 +5,5 @@ // Generated by unplugin-auto-import export {} declare global { - + const ElMessage: typeof import('element-plus/es')['ElMessage'] } diff --git a/components.d.ts b/components.d.ts index 52be6c6..b7a22ad 100644 --- a/components.d.ts +++ b/components.d.ts @@ -13,5 +13,6 @@ declare module 'vue' { ElInput: typeof import('element-plus/es')['ElInput'] ElTabPane: typeof import('element-plus/es')['ElTabPane'] ElTabs: typeof import('element-plus/es')['ElTabs'] + ElTag: typeof import('element-plus/es')['ElTag'] } } diff --git a/entrypoints/content.ts b/entrypoints/content.ts index 54996cf..72bfb3e 100644 --- a/entrypoints/content.ts +++ b/entrypoints/content.ts @@ -8,7 +8,6 @@ export default defineContentScript({ const documentClone = document.cloneNode(true) as Document; const reader = new Readability(documentClone); const article = reader.parse(); - console.log(article); return article; } diff --git a/entrypoints/popup/Popup.vue b/entrypoints/popup/Popup.vue index d8fd5af..e0d0f22 100644 --- a/entrypoints/popup/Popup.vue +++ b/entrypoints/popup/Popup.vue @@ -18,7 +18,6 @@ import FaRegularSave from '~icons/fa-regular/save'; import { ref, } from 'vue'; import saveMarkdown from '@/utils/saveMarkdown' import { html2md, md2html } from '@/utils/parser' -import { ElMessage } from 'element-plus'; dayjs.extend(utc) const html = ref('') @@ -28,6 +27,37 @@ const faviconUrl = ref('') const title = ref('') const username = ref('oeyoews') +const inputValue = ref() + +const dynamicTags = ref() + +chrome.storage.local.get(['tags'], function (result) { + dynamicTags.value = Object.values(result.tags) || ['剪藏'] +}); + +const inputVisible = ref(false) +const InputRef = ref() + + +const handleClose = (tag: string) => { + dynamicTags.value.splice(dynamicTags.value.indexOf(tag), 1) +} + +const showInput = () => { + inputVisible.value = true + nextTick(() => { + InputRef.value!.input!.focus() + }) +} +const handleInputConfirm = () => { + if (inputValue.value) { + dynamicTags.value.push(inputValue.value.trim()) + chrome.storage.local.set({ tags: toRaw(dynamicTags.value) }) + } + inputVisible.value = false + inputValue.value = '' +} + const port = ref('') chrome.storage.local.get(['port'], function (result) { @@ -103,7 +133,15 @@ watch(port, () => { }) const currentTime = dayjs(new Date()).utc().format('YYYYMMDDHHmmss') -const save2TiddlyWiki = async (title: string, text: string, port: string, url: string) => { +const save2TiddlyWiki = async (title: string, text: string, port: string, url: string, tag: string[]) => { + const tags = tag.map(function (tag) { + if (tag.includes(' ')) { + return '[[' + tag + ']]'; + } else { + return tag; + } + }).join(' '); + if (!status.value.tiddlywiki_version) { ElMessage({ message: '请先连接 TiddlyWiki', @@ -123,7 +161,8 @@ const save2TiddlyWiki = async (title: string, text: string, port: string, url: s type: 'text/markdown', url, created: currentTime, - modified: currentTime + modified: currentTime, + tags }) }).then((res) => { if (res.ok) { @@ -155,7 +194,7 @@ const save2TiddlyWiki = async (title: string, text: string, port: string, url: s - + @@ -201,11 +240,24 @@ const save2TiddlyWiki = async (title: string, text: string, port: string, url: s -
+
- 端口 +

+ 端口 +

+ +
+

标签

+ +
+ + {{ tag }} + + + + +
-