From 46476cf0f5276e84e9bcafe8da9f0679349f72b2 Mon Sep 17 00:00:00 2001 From: Jaclenga Date: Fri, 28 Mar 2025 19:20:49 -0400 Subject: [PATCH 1/2] Url now appears in title - buggy code. Unfinished (I just wanted to save the concept) --- background.js | 9 ++++++++- js/notes.js | 4 ++-- js/sidepanel.js | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/background.js b/background.js index 8db9c92..2d2769b 100644 --- a/background.js +++ b/background.js @@ -11,11 +11,18 @@ chrome.runtime.onInstalled.addListener(() => { setupContextMenu() }) // handle context menu click chrome.contextMenus.onClicked.addListener((info, tab) => { console.log(info, tab); + + let extractedUrl = info.linkUrl || info.pageUrl; + if (info.menuItemId === "addnote") { console.log(`Adding the note "${info.selectionText}"`); // we don't need a response, don't bother waiting for one - chrome.runtime.sendMessage({content: info.selectionText}); + chrome.runtime.sendMessage({ + content: info.selectionText, + url: extractedUrl + }); + } }) diff --git a/js/notes.js b/js/notes.js index d903752..b6eaad0 100644 --- a/js/notes.js +++ b/js/notes.js @@ -43,8 +43,8 @@ function deleteAllNotes() { * @param {object} insertAfter - the note that precedes the new note you're trying to add */ -function addNote(text, insertAfter) { - const title = titleInput.value || ""; +function addNote(text, titleText, insertAfter) { + const title = titleText || ""; const content = text === "" ? infoInput.value : text; infoInput.value = ""; // empty out the textbox titleInput.value = ""; diff --git a/js/sidepanel.js b/js/sidepanel.js index 8183f4b..6e43870 100644 --- a/js/sidepanel.js +++ b/js/sidepanel.js @@ -10,7 +10,10 @@ document.addEventListener("visibilitychange", _ => { saveNotesOrder(); saveFolde // context menu --> add new note chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { const content = request.content; + const title = request.url || "Untitled"; // make that new message if it's non-empty - if (content) addNote(content); + if (content) addNote(content, title); + + sendResponse({ status: "Received" }); }); From 2e3b07f506c02a76cbfbc58133542c08d4d27735 Mon Sep 17 00:00:00 2001 From: Jaclenga Date: Sat, 29 Mar 2025 00:56:20 -0400 Subject: [PATCH 2/2] Add to harbor now works when sidepanel is unopened - Previously, pressing the "add to harbor" button wouldn't do anything when the sidepanel wasn't open - Sidepanel now opens upon "add to harbor" activation --- background.js | 17 ++++++++++------- js/sidepanel.js | 2 -- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/background.js b/background.js index 2d2769b..71d8aa2 100644 --- a/background.js +++ b/background.js @@ -17,16 +17,19 @@ chrome.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId === "addnote") { console.log(`Adding the note "${info.selectionText}"`); - // we don't need a response, don't bother waiting for one - chrome.runtime.sendMessage({ - content: info.selectionText, - url: extractedUrl - }); - + // Open sidepanel to ensure connection is met for event listener + chrome.sidePanel.open({ tabId: tab.id }) + + // Ensure content scripts have time to activate + setTimeout(() => { + chrome.runtime.sendMessage({ + content: info.selectionText, + url: extractedUrl + }); + }, 200); } }) - // open panel onclick chrome.sidePanel .setPanelBehavior({ openPanelOnActionClick: true }) diff --git a/js/sidepanel.js b/js/sidepanel.js index 6e43870..0d46558 100644 --- a/js/sidepanel.js +++ b/js/sidepanel.js @@ -14,6 +14,4 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { // make that new message if it's non-empty if (content) addNote(content, title); - - sendResponse({ status: "Received" }); });