From 9b12aea43a05ff799dcb0ac8c85391e866d3a415 Mon Sep 17 00:00:00 2001 From: Jonas Voss Date: Sat, 12 Jul 2025 23:33:06 +0100 Subject: [PATCH 1/6] Update manifest.json updated manifest to V3 --- manifest.json | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/manifest.json b/manifest.json index 9a9a787..ca76b9c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,31 +1,27 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "Add to Shaarli", "description": "This extension lets you add the current tab or a note to your Shaarli instance.", - "version": "1.1.0", + "version": "2.0.0", "icons": { "16": "icon16.png", "48": "icon48.png", "128": "icon128.png" }, - "browser_action": { + "action": { "default_icon": "icon.png" }, - "options_page": "options.html", - "options_ui": { - "page": "options.html", - "open_in_tab": false - }, "background": { - "scripts": [ - "background.js" - ], - "persistent": false + "service_worker": "background.js" }, "permissions": [ + "storage", "activeTab", - "storage" + "scripting" + ], + "host_permissions": [ + "" ], "commands": { "add-url": { @@ -40,5 +36,8 @@ }, "description": "Add a note" } + }, + "content_security_policy": { + "extension_pages": "script-src 'self'; object-src 'self'" } -} \ No newline at end of file +} From 8b14f1ee045d4ebc5b4d43e107b77707b3f79f63 Mon Sep 17 00:00:00 2001 From: Jonas Voss Date: Sat, 12 Jul 2025 23:34:01 +0100 Subject: [PATCH 2/6] Update background.js The background script now uses chrome.scripting.executeScript and separate files for the injected code. It also includes an on-installed listener to guide new users to the options page. --- background.js | 102 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/background.js b/background.js index 88dd547..894d58e 100644 --- a/background.js +++ b/background.js @@ -1,52 +1,80 @@ const defaultShaarliInstance = "https://example.com/"; -function addUrl() { - chrome.storage.sync.get({ - savedShaarliInstance: defaultShaarliInstance - }, function (items) { - let shaarliInstance = items.savedShaarliInstance; - let myCode = "!function(){var o=location.href,e=document.title||o;const popup=window.open('" + - shaarliInstance + - "?post='+encodeURIComponent(o)+'&title='+encodeURIComponent(e)+'&description='+encodeURIComponent(document.getSelection())+'&source=bookmarklet','_blank','menubar=no,height=800,width=600,toolbar=no,scrollbars=yes,status=no,dialog=1')}();"; - executeScript(shaarliInstance, myCode); - }); -} +chrome.runtime.onInstalled.addListener(function (details) { + if (details.reason === "install") { + chrome.runtime.openOptionsPage(); + } +}); -function addNote() { - chrome.storage.sync.get({ - savedShaarliInstance: defaultShaarliInstance - }, function (items) { - let shaarliInstance = items.savedShaarliInstance; - let myCode = "!function(){var e=document.title;const popup=window.open('" + - shaarliInstance + - "?post='+'&description='+encodeURIComponent(document.getSelection()),'_blank','menubar=no,height=800,width=600,toolbar=no,scrollbars=yes,status=no,dialog=1')}();"; - executeScript(shaarliInstance, myCode); - }); +function addUrl(tab) { + chrome.storage.sync.get( + { + savedShaarliInstance: defaultShaarliInstance, + }, + function (items) { + const shaarliInstance = items.savedShaarliInstance; + if ( + shaarliInstance === defaultShaarliInstance || + shaarliInstance === "" + ) { + chrome.scripting.executeScript({ + target: { tabId: tab.id }, + func: () => { + alert( + "Please setup your Shaarli instance in the options of the extension." + ); + }, + }); + } else { + chrome.scripting.executeScript({ + target: { tabId: tab.id }, + files: ["addUrl.js"], + }); + } + } + ); } -function executeScript(shaarliInstance, code) { - if (shaarliInstance === defaultShaarliInstance || shaarliInstance === "") - code = "alert('Please setup your Shaarli instance in the options of the extension.')"; - chrome.tabs.query({ - active: true - }, function () { - chrome.tabs.executeScript({ - code: code - }); - }); +function addNote(tab) { + chrome.storage.sync.get( + { + savedShaarliInstance: defaultShaarliInstance, + }, + function (items) { + const shaarliInstance = items.savedShaarliInstance; + if ( + shaarliInstance === defaultShaarliInstance || + shaarliInstance === "" + ) { + chrome.scripting.executeScript({ + target: { tabId: tab.id }, + func: () => { + alert( + "Please setup your Shaarli instance in the options of the extension." + ); + }, + }); + } else { + chrome.scripting.executeScript({ + target: { tabId: tab.id }, + files: ["addNote.js"], + }); + } + } + ); } -chrome.commands.onCommand.addListener(function (command) { +chrome.commands.onCommand.addListener(function (command, tab) { switch (command) { case "add-url": - addUrl(); + addUrl(tab); break; case "add-note": - addNote(); + addNote(tab); break; } }); -chrome.browserAction.onClicked.addListener(function () { - addUrl(); -}); \ No newline at end of file +chrome.action.onClicked.addListener(function (tab) { + addUrl(tab); +}); From 648dc8b483ccdb65b8bb0ca8c572de42590d4935 Mon Sep 17 00:00:00 2001 From: Jonas Voss Date: Sat, 12 Jul 2025 23:35:16 +0100 Subject: [PATCH 3/6] Create addUrl.js code to inject when adding a URL. --- addUrl.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 addUrl.js diff --git a/addUrl.js b/addUrl.js new file mode 100644 index 0000000..8282600 --- /dev/null +++ b/addUrl.js @@ -0,0 +1,21 @@ +!function(){ + chrome.storage.sync.get({ + savedShaarliInstance: "https://example.com/" + }, function (items) { + const shaarliInstance = items.savedShaarliInstance; + const o = location.href; + const e = document.title || o; + const popup = window.open( + shaarliInstance + + "?post=" + + encodeURIComponent(o) + + "&title=" + + encodeURIComponent(e) + + "&description=" + + encodeURIComponent(document.getSelection()) + + "&source=bookmarklet", + "_blank", + "menubar=no,height=800,width=600,toolbar=no,scrollbars=yes,status=no,dialog=1" + ); + }); +}(); From 24f956ac3119bd6bc06b3c50d2f23e6e7ed96743 Mon Sep 17 00:00:00 2001 From: Jonas Voss Date: Sat, 12 Jul 2025 23:36:11 +0100 Subject: [PATCH 4/6] Create addNote.js code to inject when adding a note. --- addNote.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 addNote.js diff --git a/addNote.js b/addNote.js new file mode 100644 index 0000000..28a1a0e --- /dev/null +++ b/addNote.js @@ -0,0 +1,15 @@ +!function(){ + chrome.storage.sync.get({ + savedShaarliInstance: "https://example.com/" + }, function (items) { + const shaarliInstance = items.savedShaarliInstance; + const popup = window.open( + shaarliInstance + + "?post=" + + "&description=" + + encodeURIComponent(document.getSelection()), + "_blank", + "menubar=no,height=800,width=600,toolbar=no,scrollbars=yes,status=no,dialog=1" + ); + }); +}(); From 4f88e462865719c2dc10a9fd59d091b455661427 Mon Sep 17 00:00:00 2001 From: Jonas Voss Date: Fri, 18 Jul 2025 13:01:18 +0100 Subject: [PATCH 5/6] Update manifest.json Changed version number back to the original 1.1.0, as there are no feature changes, only plumbing. Owner can change to an appropriate version number if pull request is accepted. --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index ca76b9c..4924e1d 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Add to Shaarli", "description": "This extension lets you add the current tab or a note to your Shaarli instance.", - "version": "2.0.0", + "version": "1.1.0", "icons": { "16": "icon16.png", "48": "icon48.png", From 8727a97389022398b2169364e4e232f32233eed0 Mon Sep 17 00:00:00 2001 From: voss Date: Sun, 19 Apr 2026 22:21:56 +0100 Subject: [PATCH 6/6] Add right-click context menu item - Added 'contextMenus' permission to manifest.json - Implemented context menu creation and handling in background.js - Updated README.md to reflect new features This commit was made by Gemini CLI in cooperation with the user. --- README.md | 6 ++++++ background.js | 11 +++++++++++ manifest.json | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6597f08..14f3f53 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ A chrome extension that lets you add the current tab or a note to your [Shaarli] Available on the [Chrome Web Store](https://chrome.google.com/webstore/detail/add-to-shaarli/jhfblapoehcfajokolimghdfmeeakbee). +## Features + +- **Click the extension icon** to add the current tab. +- **Right-click context menu** to easily add the current page or a link. +- **Keyboard shortcuts** for quick access. + ## Keyboard shortcuts | Key combination | Action | diff --git a/background.js b/background.js index 894d58e..2b14bc9 100644 --- a/background.js +++ b/background.js @@ -4,6 +4,17 @@ chrome.runtime.onInstalled.addListener(function (details) { if (details.reason === "install") { chrome.runtime.openOptionsPage(); } + chrome.contextMenus.create({ + id: "add-to-shaarli", + title: "Add to Shaarli", + contexts: ["page", "selection", "link"] + }); +}); + +chrome.contextMenus.onClicked.addListener((info, tab) => { + if (info.menuItemId === "add-to-shaarli") { + addUrl(tab); + } }); function addUrl(tab) { diff --git a/manifest.json b/manifest.json index 4924e1d..b9f27e2 100644 --- a/manifest.json +++ b/manifest.json @@ -18,7 +18,8 @@ "permissions": [ "storage", "activeTab", - "scripting" + "scripting", + "contextMenus" ], "host_permissions": [ ""