Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ 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});
// 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 })
Expand Down
4 changes: 2 additions & 2 deletions js/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
3 changes: 2 additions & 1 deletion js/sidepanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ 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);
});