Skip to content

Commit

Permalink
feat: support check tiddlywiki site and setup new icon
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Apr 4, 2024
1 parent 0b375f7 commit 22c4dbf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 3 deletions.
1 change: 0 additions & 1 deletion components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
16 changes: 16 additions & 0 deletions entrypoints/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,6 +41,7 @@ export default defineBackground(() => {

// 右键菜单
chrome.runtime.onInstalled.addListener(() => {
// chrome.browserAction.setBadgeText({ text: 'NEW' });
chrome.contextMenus.create({
id: 'usewiki2',
title: '打开 Usewiki2',
Expand Down
19 changes: 19 additions & 0 deletions entrypoints/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@ export default defineContentScript({
matches: ['<all_urls>'],
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;
Expand Down
2 changes: 1 addition & 1 deletion entrypoints/popup/Popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function savePort(port: number) {
<div class="flex items-center justify-center gap-2">
<h2>
<a :href="link" target="_blank" v-if="link">
<img :src="faviconUrl" class="rounded-full size-4" />
<img alt="" :src="faviconUrl" class="rounded-full size-4" />
</a>
{{ title }}
</h2>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file added public/tw32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions utils/copyMd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { ElMessage as notify } from 'element-plus';

export function copyMd(text: string) {
if (!text) {
notify({
message: '内容为空',
type: 'warning',
});
return;
}
navigator.clipboard.writeText(text);
notify({
message: '复制成功',
Expand Down

0 comments on commit 22c4dbf

Please sign in to comment.