Skip to content

Commit

Permalink
feat: 更新 joplin 笔记页面的标题,以及设置页面默认输入即存储配置
Browse files Browse the repository at this point in the history
  • Loading branch information
rxliuli committed Jan 4, 2023
1 parent 6dfbdea commit 190e33f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/joplin-search-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite dev",
"dev": "vite build --watch",
"build": "vite build",
"pack-zip": "rimraf extension.zip && jszip-cli add dist/ -o ./extension.zip",
"pack-src": "rimraf src.zip && jszip-cli add src/ package.json .gitignore vite.config.ts tsconfig.json tsconfig.node.json -o ./src.zip",
Expand Down
2 changes: 1 addition & 1 deletion apps/joplin-search-integration/src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Joplin Search Integration",
"version": "0.2.4",
"version": "0.2.5",
"description": "When using search, related Joplin notes are also displayed in the search results.",
"manifest_version": 3,
"background": {
Expand Down
5 changes: 4 additions & 1 deletion apps/joplin-search-integration/src/options/views/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ function getNoteId() {

interface NoteData {
id: string
title: string
content: string
resources: string[]
}

async function getNoteData(id: string): Promise<NoteData | undefined> {
try {
const [s, r] = await Promise.all([noteApi.get(id, ['body']), noteApi.resourcesById(id, ['id'])])
const [s, r] = await Promise.all([noteApi.get(id, ['body', 'title']), noteApi.resourcesById(id, ['id'])])
return {
id: id,
title: s.title,
content: s.body,
resources: r.map((item) => item.id),
}
Expand Down Expand Up @@ -133,6 +135,7 @@ async function main() {
if (!s) {
throw new Error('查询笔记失败')
}
document.title = s.title
const html = renderNoteToHtml(s)
$content.innerHTML = html
onToggleTheme()
Expand Down
19 changes: 11 additions & 8 deletions apps/joplin-search-integration/src/options/views/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import browser, { theme } from 'webextension-polyfill'
import browser from 'webextension-polyfill'
import { loadConfig, LocalConfig } from '../utils/loadConfig'

function render() {
Expand Down Expand Up @@ -39,14 +39,17 @@ async function main() {
;($theme.querySelector(`[value="${c.theme}"]`) as HTMLOptionElement).selected = true
setTheme(c.theme)
const list = ['baseUrl', 'token', 'theme']
const handle = async (k: string, ev: Event) => {
const el = ev.target as HTMLInputElement
await browser.storage.local.set({ [k]: el.value })
if (el.name === 'theme') {
setTheme(el.value as LocalConfig['theme'])
}
}
list.forEach((k) => {
document.getElementById(k)!.addEventListener('change', async (ev) => {
const el = ev.target as HTMLInputElement
await browser.storage.local.set({ [k]: el.value })
if (el.name === 'theme') {
setTheme(el.value as LocalConfig['theme'])
}
})
const el = document.getElementById(k)!
el.addEventListener('change', (ev) => handle(k, ev))
el.addEventListener('input', (ev) => handle(k, ev))
})
}

Expand Down

0 comments on commit 190e33f

Please sign in to comment.