From c36dc9c1646f7d42a628c5b00d3a584c43ae1f53 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 7 Feb 2021 19:45:32 +0000 Subject: [PATCH] Finalize the version 0.1.1 --- .gitignore | 3 ++- Makefile | 3 +++ background.js | 25 +++++++++++++++++++++++++ daru.js | 11 +++++++++++ manifest.json | 23 +++++++++++++++++++++-- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 Makefile create mode 100644 background.js create mode 100644 daru.js diff --git a/.gitignore b/.gitignore index 900f99b..2d4d273 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ -node_modules/ \ No newline at end of file +node_modules/ +web-ext-artifacts/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bdce0e9 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +pack: + rm ./*~ -rf + zip -r -FS ../Daru.zip * --exclude '*.git*' --exclude 'Makefile' --exclude 'daru.zip' diff --git a/background.js b/background.js new file mode 100644 index 0000000..7e27cde --- /dev/null +++ b/background.js @@ -0,0 +1,25 @@ +"use strict"; + +function onError(error) { + console.error(`Error: ${error}`); +} + +function sendMessageToTabs(tabs) { + for (let tab of tabs) { + browser.tabs.sendMessage( + tab.id, + {command: "bookmark"} + ).catch(onError); + } +} + + + +browser.commands.onCommand.addListener(function (command) { + if (command === "bookmark") { + browser.tabs.query({ + currentWindow: true, + active: true + }).then(sendMessageToTabs).catch(onError); + } +}); diff --git a/daru.js b/daru.js new file mode 100644 index 0000000..7d0b4e8 --- /dev/null +++ b/daru.js @@ -0,0 +1,11 @@ +"use strict"; + +browser.runtime.onMessage.addListener(request => { + if (request.command == "bookmark") { + //const url = 'org-protocol://msg/?URL='+ encodeURIComponent(location.href)+'&TITLE='+ encodeURIComponent(document.title)+'&SELECTED='+ encodeURIComponent(window.getSelection()); + const url = `org-protocol://capture/?template=l&url=${encodeURIComponent(location.href)}&title=${encodeURIComponent(document.title)}&body=${encodeURIComponent(window.getSelection())}`; + console.log("Sending to FG42. URL:", url); + location.href = url; + } + return Promise.resolve({response: "done"}); +}); diff --git a/manifest.json b/manifest.json index 5eeba3b..045fc9a 100644 --- a/manifest.json +++ b/manifest.json @@ -2,15 +2,34 @@ "manifest_version": 2, "name": "Daru", - "version": "0.1.0", - + "version": "0.1.1", "description": "An extension to integrate FG42 with Firefox (Possibly, it can be used with any org-mode setup).", + + "background": { + "scripts": ["background.js"] + }, + "icons": { "48": "icons/48.png", "96": "icons/96.png" }, + "permissions": ["tabs"], + "commands": { + "bookmark": { + "suggested_key": { + "default": "Ctrl+Shift+0", + "linux": "Ctrl+Shift+0" + }, + "description": "Bookmark the page in org mode" + } + }, + "browser_specific_settings": { + "gecko": { + "id": "{fbc15118-c371-4ffd-b686-209a13ff6a5e}" + } + }, "content_scripts": [ { "matches": [""],