diff --git a/.vscode/settings.json b/.vscode/settings.json index 3170cb29..d3aeedc1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -54,5 +54,5 @@ "**/dist": true }, "editor.detectIndentation": false, // 不自动检测缩进 - "editor.tabSize": 4, + "editor.tabSize": 4 } \ No newline at end of file diff --git a/README.md b/README.md index b344748a..bca1776b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -
一个 Chrome / Firefox 扩展:主要用于微信读书做笔记,对常使用 Markdown 做笔记的读者比较有帮助。
@@ -53,3 +53,12 @@ | [chrome-plugin-demo](https://github.com/sxei/chrome-plugin-demo) | Chrome 扩展开发教程 | | [Extensions - Chrome Developers](https://developer.chrome.com/docs/extensions/) | Chrome 扩展官方文档 | +## 其他 + +
+ 加微信进交流群(备注:wereader 交流群) |
+
想法也就是你平时阅读时在书中发表的想法。当你将前后缀设置为两个星号(**)时,导出的想法在 Markdown 中将会被加粗。
` + help: `想法也就是你平时阅读时在书中发表的想法。当你将前后缀设置为两个星号(**)时,导出的想法在 Markdown 中将会被加粗。可使用{createTime}作为占位符导出想法创建时间。
` }, metaTemplate: { title: '书本信息导出模板', @@ -50,7 +50,7 @@ const helpContent: {[key: string]: any} = { }, thouMarkSuf: { title: '想法标注后缀', - help: `想法标注即想法所对应的书本内容。当你将想法标注前后缀设置为两个星号(**)时,导出的想法标注在 Markdown 中将会被加粗。
` + help: `想法标注即想法所对应的书本内容。当你将想法标注前后缀设置为两个星号(**)时,导出的想法标注在 Markdown 中将会被加粗。可使用{createTime}作为占位符导出想法创建时间。
` }, codeSuf: { title: '代码块后缀', @@ -190,4 +190,4 @@ function initHelpContent() { }); } -export { initHelpContent }; \ No newline at end of file +export { initHelpContent }; diff --git a/src/worker/types/ThoughtsInAChap.ts b/src/worker/types/ThoughtsInAChap.ts index bc301465..2e068750 100644 --- a/src/worker/types/ThoughtsInAChap.ts +++ b/src/worker/types/ThoughtsInAChap.ts @@ -4,4 +4,5 @@ export interface ThoughtsInAChap { range: string; abstract: string; content: string; + createTime: number } diff --git a/src/worker/worker-popup-process.ts b/src/worker/worker-popup-process.ts index e28b5e79..57341efe 100644 --- a/src/worker/worker-popup-process.ts +++ b/src/worker/worker-popup-process.ts @@ -21,7 +21,9 @@ import { } from './worker-vars' import { Wereader } from './types/Wereader' import { ThoughtsInAChap } from './types/ThoughtsInAChap' -import { getLocalStorage, getSyncStorage, sortByKey } from '../common/utils' +import { + formatTimestamp, getLocalStorage, getSyncStorage, sortByKey +} from '../common/utils' import { notify } from './worker-notification' // 给标题添加前后缀 @@ -77,7 +79,12 @@ export async function getMyThought() { } else { range = range.replace(/(\d*)-\d*/, '$1') } - thoughtsInAChap.push({ abstract: abstract, content: content, range: range }) + thoughtsInAChap.push({ + abstract, + content, + range, + createTime: item.review.createTime + }) } } thoughtsMap.set(chapterUid, sortByKey(thoughtsInAChap, 'range') as ThoughtsInAChap[]) @@ -369,6 +376,27 @@ function addMarkPreAndSuf(markText: string, style: number, config: ConfigType) { return pre + markText + suf } +/** + * 替换想法前后缀配置中的占位符 + * @param mark 想法标注 + * @param config 配置信息 + * @returns 替换后的各前后缀 + */ +export function getReplacedThoughtConfig(mark: ThoughtsInAChap, config: ConfigType) { + const re = /\{createTime}/g + const time = formatTimestamp(mark.createTime) + const thouPre = config.thouPre.replace(re, time) + const thouSuf = config.thouSuf.replace(re, time) + const thouMarkPre = config.thouMarkPre.replace(re, time) + const thouMarkSuf = config.thouMarkSuf.replace(re, time) + return { + thouPre, + thouSuf, + thouMarkPre, + thouMarkSuf + } +} + // 处理章内标注 export function traverseMarks( marks: (Updated | ThoughtsInAChap)[], @@ -395,11 +423,17 @@ export function traverseMarks( footnoteContent = data[1] } if (isThought(mark)) { // 如果为想法 + const { + thouPre, + thouSuf, + thouMarkPre, + thouMarkSuf + } = getReplacedThoughtConfig(mark, config) // 想法 - const thouContent = `${config.thouPre}${mark.content}${config.thouSuf}\n\n` + const thouContent = `${thouPre}${mark.content}${thouSuf}\n\n` // 想法所标注的内容 const abstract = mark.abstract - let thouAbstract = `${config.thouMarkPre}${abstract}${config.thouMarkSuf}\n\n` + let thouAbstract = `${thouMarkPre}${abstract}${thouMarkSuf}\n\n` // 想法所对应文本与上一条标注相同时 if (abstract === prevMarkText) { if (prevMarkType === '0') { diff --git a/src/worker/worker-popup.ts b/src/worker/worker-popup.ts index 2e1ee867..33715212 100644 --- a/src/worker/worker-popup.ts +++ b/src/worker/worker-popup.ts @@ -14,7 +14,7 @@ import { getBestBookMarks, getBookMarks, getChapters, - getMyThought, + getMyThought, getReplacedThoughtConfig, getTitleAddedPreAndSuf, traverseMarks } from './worker-popup-process' @@ -224,10 +224,16 @@ export async function copyThought(isAll?: boolean) { let tempRes = `${getTitleAddedPreAndSuf(contents.get(chapUid)!.title, contents.get(chapUid)!.level, config)}\n\n` let prevAbstract = '' // 保存上一条想法对应标注文本 thoughtsInAChap.forEach((thou) => { + const { + thouPre, + thouSuf, + thouMarkPre, + thouMarkSuf + } = getReplacedThoughtConfig(thou, config) // 想法 - const thouContent = `${config.thouPre}${thou.content}${config.thouSuf}\n\n` + const thouContent = `${thouPre}${thou.content}${thouSuf}\n\n` // 想法所标注的内容 - let thouAbstract = `${config.thouMarkPre}${thou.abstract}${config.thouMarkSuf}\n\n` + let thouAbstract = `${thouMarkPre}${thou.abstract}${thouMarkSuf}\n\n` // 当前标注文本和前一条标注文本内容相同、且配置去重时,不导出当前的标注 if (thou.abstract === prevAbstract && config.distinctThouMarks) { thouAbstract = '' diff --git a/src/worker/worker-vars.ts b/src/worker/worker-vars.ts index 27bb96ed..532e9e2f 100644 --- a/src/worker/worker-vars.ts +++ b/src/worker/worker-vars.ts @@ -40,7 +40,7 @@ const defaultConfig: ConfigType = { lev2Suf: '', lev3Pre: '#### ', lev3Suf: '', - thouPre: '==', + thouPre: '> {createTime}\n\n==', thouSuf: '==', /* eslint-disable */ metaTemplate: '__metaTemplate__', diff --git a/wereader.zip b/wereader.zip index 411b3b55..663e46f0 100644 Binary files a/wereader.zip and b/wereader.zip differ