diff --git a/background.js b/background.js index 060d8db75..21be04f97 100644 --- a/background.js +++ b/background.js @@ -237,18 +237,25 @@ async function saveWholePage() { toast("Page has been saved to Trilium.", resp.noteId); } -async function saveNote(title, content) { +async function saveLinkWithNote(title, content) { + const activeTab = await getActiveTab(); + + if (!title.trim()) { + title = activeTab.title; + } + const resp = await triliumServerFacade.callService('POST', 'notes', { title: title, content: content, - clipType: 'note' + clipType: 'note', + pageUrl: activeTab.url }); if (!resp) { return false; } - toast("Note has been saved to Trilium.", resp.noteId); + toast("Link with note has been saved to Trilium.", resp.noteId); return true; } @@ -330,8 +337,8 @@ browser.runtime.onMessage.addListener(async request => { else if (request.name === 'save-whole-page') { return await saveWholePage(); } - else if (request.name === 'save-note') { - return await saveNote(request.title, request.content); + else if (request.name === 'save-link-with-note') { + return await saveLinkWithNote(request.title, request.content); } else if (request.name === 'trigger-trilium-search') { triliumServerFacade.triggerSearchForTrilium(); diff --git a/content.js b/content.js index 1fb006636..3cc1c7bbf 100644 --- a/content.js +++ b/content.js @@ -23,24 +23,6 @@ function pageTitle() { return titleElements.length ? titleElements[0].text.trim() : document.title.trim(); } -function getPageLocationOrigin() { - // location.origin normally returns the protocol + domain + port (eg. https://example.com:8080) - // but for file:// protocol this is browser dependant and in particular Firefox returns "null" in this case. - return location.protocol === 'file:' ? 'file://' : location.origin; -} - -function getBaseUrl() { - let output = getPageLocationOrigin() + location.pathname; - - if (output[output.length - 1] !== '/') { - output = output.split('/'); - output.pop(); - output = output.join('/'); - } - - return output; -} - function getReadableDocument() { // Readability directly change the passed document so clone it so as // to preserve the original web page. @@ -304,4 +286,4 @@ async function requireLib(libPath) { await browser.runtime.sendMessage({name: 'load-script', file: libPath}); } -} \ No newline at end of file +} diff --git a/popup/popup.css b/popup/popup.css index 5fdd46a1b..7d1258a1c 100644 --- a/popup/popup.css +++ b/popup/popup.css @@ -24,11 +24,11 @@ body { width: 100%; } -#create-text-note-wrapper { +#save-link-with-note-wrapper { display: none; } -#create-text-note-textarea { +#save-link-with-note-textarea { width: 100%; } @@ -45,4 +45,4 @@ body { button[disabled] { color: #aaa; -} \ No newline at end of file +} diff --git a/popup/popup.html b/popup/popup.html index fe94eed29..51dbcb2cf 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -20,10 +20,10 @@ - + -
- +