mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-18 16:32:33 +08:00
reformat code
This commit is contained in:
parent
6952c467cd
commit
9abee14beb
@ -251,6 +251,22 @@ async function saveWholePage() {
|
|||||||
toast("Page has been saved to Trilium.", resp.noteId);
|
toast("Page has been saved to Trilium.", resp.noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function saveNote(title, content) {
|
||||||
|
const resp = await triliumServerFacade.callService('POST', 'notes', {
|
||||||
|
title: title,
|
||||||
|
content: content,
|
||||||
|
clipType: 'note'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!resp) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast("Note has been saved to Trilium.", resp.noteId);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
async function getTabsPayload(tabs) {
|
async function getTabsPayload(tabs) {
|
||||||
let content = '<ul>';
|
let content = '<ul>';
|
||||||
tabs.forEach(tab => {
|
tabs.forEach(tab => {
|
||||||
@ -258,8 +274,6 @@ async function getTabsPayload(tabs) {
|
|||||||
});
|
});
|
||||||
content += '</ul>';
|
content += '</ul>';
|
||||||
|
|
||||||
// topDomains string with 1-3 most used domains will be used as the note title
|
|
||||||
// to help the user differentiate between multiple notes of this type
|
|
||||||
const domainsCount = tabs.map(tab => tab.url)
|
const domainsCount = tabs.map(tab => tab.url)
|
||||||
.reduce((acc, url) => {
|
.reduce((acc, url) => {
|
||||||
const hostname = new URL(url).hostname
|
const hostname = new URL(url).hostname
|
||||||
@ -272,7 +286,7 @@ async function getTabsPayload(tabs) {
|
|||||||
.map(domain=>domain[0])
|
.map(domain=>domain[0])
|
||||||
.join(', ')
|
.join(', ')
|
||||||
|
|
||||||
if (tabs.length > 3) { topDomains += '...' };
|
if (tabs.length > 3) { topDomains += '...' }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: `${tabs.length} browser tabs: ${topDomains}`,
|
title: `${tabs.length} browser tabs: ${topDomains}`,
|
||||||
@ -295,22 +309,6 @@ async function saveTabs() {
|
|||||||
await closeWindowTabs(tabs);
|
await closeWindowTabs(tabs);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveNote(title, content) {
|
|
||||||
const resp = await triliumServerFacade.callService('POST', 'notes', {
|
|
||||||
title: title,
|
|
||||||
content: content,
|
|
||||||
clipType: 'note'
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!resp) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
toast("Note has been saved to Trilium.", resp.noteId);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
browser.contextMenus.onClicked.addListener(async function(info, tab) {
|
browser.contextMenus.onClicked.addListener(async function(info, tab) {
|
||||||
if (info.menuItemId === 'trilium-save-selection') {
|
if (info.menuItemId === 'trilium-save-selection') {
|
||||||
await saveSelection();
|
await saveSelection();
|
||||||
@ -388,12 +386,12 @@ browser.runtime.onMessage.addListener(async request => {
|
|||||||
else if (request.name === 'save-whole-page') {
|
else if (request.name === 'save-whole-page') {
|
||||||
return await saveWholePage();
|
return await saveWholePage();
|
||||||
}
|
}
|
||||||
else if (request.name === 'save-tabs') {
|
|
||||||
return await saveTabs();
|
|
||||||
}
|
|
||||||
else if (request.name === 'save-note') {
|
else if (request.name === 'save-note') {
|
||||||
return await saveNote(request.title, request.content);
|
return await saveNote(request.title, request.content);
|
||||||
}
|
}
|
||||||
|
else if (request.name === 'save-tabs') {
|
||||||
|
return await saveTabs();
|
||||||
|
}
|
||||||
else if (request.name === 'trigger-trilium-search') {
|
else if (request.name === 'trigger-trilium-search') {
|
||||||
triliumServerFacade.triggerSearchForTrilium();
|
triliumServerFacade.triggerSearchForTrilium();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user