Skip to content

Commit 396bd16

Browse files
committed
encode/decode note url in local storage when opening from browser extension
1 parent 3af7a70 commit 396bd16

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

browser-extension/manifest.chrome.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"matches": ["https://notes.toolworks.dev/*"]
2323
}],
2424
"host_permissions": [
25-
"https://notes.toolworks.dev/*",
26-
"https://notes-sync.toolworks.dev/*"
25+
"https://notes.toolworks.dev/*"
2726
],
2827
"action": {
2928
"default_icon": "icons/icon-96.png",

browser-extension/manifest.firefox.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"matches": ["https://notes.toolworks.dev/*"]
2323
}],
2424
"host_permissions": [
25-
"https://notes.toolworks.dev/*",
26-
"https://notes-sync.toolworks.dev/*"
25+
"https://notes.toolworks.dev/*"
2726
],
2827
"action": {
2928
"default_icon": "icons/icon-96.png",

browser-extension/popup/popup.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,18 @@ function renderNotes(notesToRender) {
153153
`;
154154

155155
noteElement.addEventListener('click', async () => {
156-
const url = new URL('https://notes.toolworks.dev');
157-
url.searchParams.set('loadNote', JSON.stringify({
156+
const noteData = {
158157
id: note.id,
159158
title: note.title,
160159
content: note.content,
161160
created_at: note.created_at,
162161
updated_at: note.updated_at
163-
}));
162+
};
163+
164+
const url = new URL('https://notes.toolworks.dev');
165+
166+
const encodedNoteData = encodeURIComponent(JSON.stringify(noteData));
167+
url.searchParams.set('loadNote', encodedNoteData);
164168
url.searchParams.set('autoload', 'true');
165169

166170
chrome.tabs.create({ url: url.toString() });

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ function App() {
105105

106106
if (loadNoteParam && autoload === 'true') {
107107
try {
108-
const noteToLoad = JSON.parse(loadNoteParam);
108+
const decodedNote = decodeURIComponent(loadNoteParam);
109+
const noteToLoad = JSON.parse(decodedNote);
109110
setSelectedNote(noteToLoad);
110111
setTitle(noteToLoad.title);
111112
setContent(noteToLoad.content);

0 commit comments

Comments
 (0)