mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-06 05:29:02 +00:00
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
/**
|
|
* notion-enhancer: quick note
|
|
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
|
|
* (https://notion-enhancer.github.io/) under the MIT license
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
export default async function ({ web, components, notion }, db) {
|
|
const targetDbId = await db.get(['target_db']);
|
|
if (!targetDbId) return;
|
|
|
|
const newQuickNote = async () => {
|
|
try {
|
|
const { collection_id } = await notion.get(targetDbId),
|
|
noteID = await notion.create(
|
|
{
|
|
recordValue: {
|
|
properties: { title: [[`quick note: ${new Date().toLocaleString()}`]] },
|
|
},
|
|
recordType: 'page',
|
|
},
|
|
{ parentID: collection_id, parentTable: 'collection' }
|
|
);
|
|
location.assign(`https://www.notion.so/${noteID.replace(/-/g, '')}`);
|
|
} catch {
|
|
alert('quick note failed: target database id did not match any known databases');
|
|
}
|
|
};
|
|
|
|
await components.addCornerAction(await components.feather('feather'), newQuickNote);
|
|
web.addHotkeyListener(await db.get(['hotkey']), newQuickNote);
|
|
}
|