Skip to content

Build your personal knowledge base with Trilium Notes

"save note" is now "save link with note" - i.e. we're saving a current URL together with the text note

zadam0811276fbbf0
diff --git a/background.js b/background.js
index 060d8db756..21be04f974 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 1fb0066364..3cc1c7bbff 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 5fdd46a1bf..7d1258a1ce 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 fe94eed292..51dbcb2cf5 100644
--- a/popup/popup.html
+++ b/popup/popup.html
@@ -20,10 +20,10 @@
<button class="button full needs-connection" id="clip-screenshot-button">Clip screenshot</button>
<button class="button full needs-connection" id="save-whole-page-button">Save whole page</button>
- <button class="button full needs-connection" id="create-text-note-button">Create text note</button>
+ <button class="button full needs-connection" id="save-link-with-note-button">Save link with a note</button>
- <div id="create-text-note-wrapper">
- <textarea id="create-text-note-textarea" rows="5"></textarea>
+ <div id="save-link-with-note-wrapper">
+ <textarea id="save-link-with-note-textarea" rows="5"></textarea>
<div style="display: flex;">
<button type="submit" class="button wide" id="save-button">Save</button>
@@ -41,6 +41,7 @@
<script src="../lib/browser-polyfill.js"></script>
<script src="../lib/cash.min.js"></script>
<script src="popup.js"></script>
+ <script src="../utils.js"></script>
</body>
-</html>
\ No newline at end of file
+</html>
diff --git a/popup/popup.js b/popup/popup.js
index ff61ca423f..5a11a79d65 100644
--- a/popup/popup.js
+++ b/popup/popup.js
@@ -19,54 +19,55 @@ $clipScreenShotButton.on("click", () => sendMessage({name: 'save-screenshot'}));
$saveWholePageButton.on("click", () => sendMessage({name: 'save-whole-page'}));
-const $createTextNoteWrapper = $("#create-text-note-wrapper");
-const $textNote = $("#create-text-note-textarea");
+const $saveLinkWithNoteWrapper = $("#save-link-with-note-wrapper");
+const $textNote = $("#save-link-with-note-textarea");
$textNote.on('keypress', function (event) {
- if (event.which === 10 || event.which === 13 && event.ctrlKey) {
- saveNote();
+ if ((event.which === 10 || event.which === 13) && event.ctrlKey) {
+ saveLinkWithNote();
return false;
}
return true;
});
-$("#create-text-note-button").on("click", () => {
- $createTextNoteWrapper.show();
+$("#save-link-with-note-button").on("click", () => {
+ $saveLinkWithNoteWrapper.show();
$textNote[0].focus();
});
$("#cancel-button").on("click", () => {
- $createTextNoteWrapper.hide();
+ $saveLinkWithNoteWrapper.hide();
$textNote.val("");
window.close();
});
-async function saveNote() {
+async function saveLinkWithNote() {
const textNoteVal = $textNote.val().trim();
-
- if (textNoteVal.length === 0) {
- alert("Note is empty. Please enter some text");
- return;
- }
-
- const match = /^(.*?)([.?!]\s|\n)/.exec(textNoteVal);
let title, content;
- if (match) {
- title = match[0].trim();
- content = textNoteVal.substr(title.length).trim();
+ if (!textNoteVal) {
+ title = '';
+ content = '';
}
else {
- title = textNoteVal;
- content = '';
+ const match = /^(.*?)([.?!]\s|\n)/.exec(textNoteVal);
+
+ if (match) {
+ title = match[0].trim();
+ content = textNoteVal.substr(title.length).trim();
+ }
+ else {
+ title = textNoteVal;
+ content = '';
+ }
}
content = escapeHtml(content);
- const result = await sendMessage({name: 'save-note', title, content});
+ const result = await sendMessage({name: 'save-link-with-note', title, content});
if (result) {
$textNote.val('');
@@ -75,7 +76,7 @@ async function saveNote() {
}
}
-$("#save-button").on("click", saveNote);
+$("#save-button").on("click", saveLinkWithNote);
$("#show-help-button").on("click", () => {
window.open("https://github.com/zadam/trilium/wiki/Web-clipper", '_blank');
@@ -141,4 +142,4 @@ $checkConnectionButton.on("click", () => {
})
});
-$(() => browser.runtime.sendMessage({name: "send-trilium-search-status"}));
\ No newline at end of file
+$(() => browser.runtime.sendMessage({name: "send-trilium-search-status"}));
diff --git a/utils.js b/utils.js
index 40b0ca809a..9ec82b2c23 100644
--- a/utils.js
+++ b/utils.js
@@ -7,4 +7,22 @@ function randomString(len) {
}
return text;
-}
\ No newline at end of file
+}
+
+function getBaseUrl() {
+ let output = getPageLocationOrigin() + location.pathname;
+
+ if (output[output.length - 1] !== '/') {
+ output = output.split('/');
+ output.pop();
+ output = output.join('/');
+ }
+
+ return output;
+}
+
+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;
+}