From 22c4dbffb39efe909de55897b9607e13f18b82a7 Mon Sep 17 00:00:00 2001 From: oeyoews Date: Thu, 4 Apr 2024 10:55:35 +0800 Subject: [PATCH] feat: support check tiddlywiki site and setup new icon --- components.d.ts | 1 - entrypoints/background.ts | 16 ++++++++++++++++ entrypoints/content.ts | 19 +++++++++++++++++++ entrypoints/popup/Popup.vue | 2 +- package.json | 2 +- public/tw32.png | Bin 0 -> 1571 bytes utils/copyMd.ts | 7 +++++++ 7 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 public/tw32.png diff --git a/components.d.ts b/components.d.ts index f4e0246..7bf1cdc 100644 --- a/components.d.ts +++ b/components.d.ts @@ -8,7 +8,6 @@ export {} declare module 'vue' { export interface GlobalComponents { ElButton: typeof import('element-plus/es')['ElButton'] - ElDivider: typeof import('element-plus/es')['ElDivider'] ElInput: typeof import('element-plus/es')['ElInput'] ElLink: typeof import('element-plus/es')['ElLink'] ElPopconfirm: typeof import('element-plus/es')['ElPopconfirm'] diff --git a/entrypoints/background.ts b/entrypoints/background.ts index 419b8a9..d70e983 100644 --- a/entrypoints/background.ts +++ b/entrypoints/background.ts @@ -11,6 +11,21 @@ export default defineBackground(() => { // } // }); + chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + if (request.info === 'tiddlywiki-send-message') { + console.log(request); + // https://stackoverflow.com/questions/14481107/typeerror-cannot-call-method-setbadgetext-of-undefined + chrome.action.setIcon({ + path: 'tw32.png', + }); + // chrome.action.setBadgeText({ text: request.version }); + } else { + chrome.action.setIcon({ + path: 'icons/icon32.png', + }); + } + }); + chrome.tabs.onUpdated.addListener(async (tabId, info, tab) => { await chrome.sidePanel.setOptions({ tabId, @@ -26,6 +41,7 @@ export default defineBackground(() => { // 右键菜单 chrome.runtime.onInstalled.addListener(() => { + // chrome.browserAction.setBadgeText({ text: 'NEW' }); chrome.contextMenus.create({ id: 'usewiki2', title: '打开 Usewiki2', diff --git a/entrypoints/content.ts b/entrypoints/content.ts index 72bfb3e..ef25720 100644 --- a/entrypoints/content.ts +++ b/entrypoints/content.ts @@ -4,8 +4,27 @@ export default defineContentScript({ matches: [''], runAt: 'document_start', main() { + // 检查是否为 tiddlywiki site + document.addEventListener('DOMContentLoaded', () => { + const meta = document.querySelector('meta[name="generator"]'); + // @ts-ignore + if (meta && meta.content === 'TiddlyWiki') { + // const version = document.querySelector( + // 'meta[name="tiddlywiki-version"]' + // // @ts-ignore + // )?.content; + chrome.runtime.sendMessage({ + info: 'tiddlywiki-send-message', + // version, + }); + } else { + chrome.runtime.sendMessage({ info: 'general-send-message' }); + } + }); + function getDoc() { const documentClone = document.cloneNode(true) as Document; + const reader = new Readability(documentClone); const article = reader.parse(); return article; diff --git a/entrypoints/popup/Popup.vue b/entrypoints/popup/Popup.vue index d92a3e5..7f7549a 100644 --- a/entrypoints/popup/Popup.vue +++ b/entrypoints/popup/Popup.vue @@ -243,7 +243,7 @@ function savePort(port: number) {

- + {{ title }}

diff --git a/package.json b/package.json index fb11566..d6198d7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "usewiki2", "description": "Convert HTML to Markdown, and save to your computer, support nodejs tiddlywiki", "private": true, - "version": "2.0.0", + "version": "2.1.0", "type": "module", "scripts": { "dev": "wxt", diff --git a/public/tw32.png b/public/tw32.png new file mode 100644 index 0000000000000000000000000000000000000000..3b1c263d5cd44533dc353764d60dc9efae7befe8 GIT binary patch literal 1571 zcmV+;2Hg3HP)Px)-AP12R9Hu~S9@%eRTTf-uid&wyOurK!?o+$ZNL~3&47%6uMGtLFhL;@5`&5u z42FQB&Lu#21ThnW#s`SeL?NP!#vq0PL6L22nwY_s^|d~>F*o)s>$-mH+H1bA+ef>8 zE1i*(H2Lm5zjMy-o_p@Ox1`G<7qgW)onV!!W@5HEsLIw3c~1`pb$Ynd(#47RXqir@sgH(;(P}Mah@?>r z8#gqFR6`rsBqjP56oV&_(@-a1$K?v#U05O>hr*)Qs`Vdz`b8N)%NZsB^ZNmY@n3m; z`}P}Vo1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