From 5b8d15a4feb6c06f31a5fd6b026c0235fd49d681 Mon Sep 17 00:00:00 2001 From: Roman Musin <995612+roman-r-m@users.noreply.github.com> Date: Mon, 27 Feb 2023 22:00:14 +0000 Subject: [PATCH] PoC add new button --- plugin.config.json | 4 +++- src/dummyContentScript.ts | 22 ++++++++++++++++++++++ src/index.ts | 8 +++++++- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/dummyContentScript.ts diff --git a/plugin.config.json b/plugin.config.json index c2efd61..18aa592 100644 --- a/plugin.config.json +++ b/plugin.config.json @@ -1,3 +1,5 @@ { - "extraScripts": [] + "extraScripts": [ + "dummyContentScript.ts" + ] } \ No newline at end of file diff --git a/src/dummyContentScript.ts b/src/dummyContentScript.ts new file mode 100644 index 0000000..da08092 --- /dev/null +++ b/src/dummyContentScript.ts @@ -0,0 +1,22 @@ +export default function(context: any) { + const plugin = (_cm) => { + try { + const newNoteButton = document.getElementsByClassName('new-note-button')[0] + const container = newNoteButton.parentElement + + const button = newNoteButton.cloneNode(true) as Element + button.children[1].innerHTML = 'Template' + container.append(button) + + button.addEventListener('click', () => { + context.postMessage({ command: 'newFromTemplate' }); + }) + } catch (e) { + console.log('Error', e) + } + } + + return { + plugin: plugin + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index c59e5a4..81ace64 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import joplin from "api"; -import { MenuItemLocation, SettingItemType } from "api/types"; +import { ContentScriptType, MenuItemLocation, SettingItemType } from "api/types"; import { Parser } from "./parser"; import { DateAndTimeUtils } from "./utils/dateAndTime"; import { getTemplateFromId, getUserTemplateSelection, Note } from "./utils/templates"; @@ -243,5 +243,11 @@ joplin.plugins.register({ // Folder context menu await joplin.views.menuItems.create("templates_folderid", "copyFolderID", MenuItemLocation.FolderContextMenu); + + await joplin.contentScripts.register(ContentScriptType.CodeMirrorPlugin, 'dummy', './dummyContentScript.js'); + + await joplin.contentScripts.onMessage('dummy', () => { + joplin.commands.execute("createNoteFromDefaultTemplate") + }) }, });