From 0ef7dbe253b3535c066f6b58573c2426d63ede5f Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 20 May 2019 19:23:16 +0200 Subject: [PATCH] Minimal working Firefox extension. --- browser-plugins/webextension/add_uri.html | 15 +++++++ browser-plugins/webextension/launch.js | 27 ++++++++++++ browser-plugins/webextension/manifest.json | 42 +++++++++++++++++++ .../native-wrapper/remwharead.json | 7 ++++ .../native-wrapper/remwharead_wrapper.sh | 5 +++ 5 files changed, 96 insertions(+) create mode 100644 browser-plugins/webextension/add_uri.html create mode 100644 browser-plugins/webextension/launch.js create mode 100644 browser-plugins/webextension/manifest.json create mode 100644 browser-plugins/webextension/native-wrapper/remwharead.json create mode 100755 browser-plugins/webextension/native-wrapper/remwharead_wrapper.sh diff --git a/browser-plugins/webextension/add_uri.html b/browser-plugins/webextension/add_uri.html new file mode 100644 index 0000000..59e39af --- /dev/null +++ b/browser-plugins/webextension/add_uri.html @@ -0,0 +1,15 @@ + + + + + + +
+ + + +
+ + + + diff --git a/browser-plugins/webextension/launch.js b/browser-plugins/webextension/launch.js new file mode 100644 index 0000000..0cee334 --- /dev/null +++ b/browser-plugins/webextension/launch.js @@ -0,0 +1,27 @@ +var taburl; + +function onResponse(response) +{ + console.log(`Received ${response}`); +} + +function onError(error) +{ + console.log(`Error: ${error}`); +} + +function set_taburl(tabs) +{ + let tab = tabs[0]; + taburl = tab.url; +} + +function launch() +{ + let tags = document.getElementById("tags").value; + var sending = browser.runtime.sendNativeMessage("remwharead", "-t " + tags + " " + taburl); + sending.then(onResponse, onError); +} + +browser.tabs.query({currentWindow: true, active: true}).then(set_taburl); +add_uri.addEventListener("submit", launch); diff --git a/browser-plugins/webextension/manifest.json b/browser-plugins/webextension/manifest.json new file mode 100644 index 0000000..ab3369d --- /dev/null +++ b/browser-plugins/webextension/manifest.json @@ -0,0 +1,42 @@ +{ + "manifest_version": 2, + "name": "remwharead", + "version": "0.1.0", + + "description": "Integrates remwharead into your Browser.", + "homepage_url": "https://schlomp.space/tastytea/remwharead", + + "applications": + { + "gecko": + { + "id": "remwharead@tastytea.de", + "strict_min_version": "50.0" + } + }, + + "permissions": + [ + "activeTab", + "nativeMessaging" + ], + + "browser_action": + { + "default_title": "remwharead", + "default_popup": "add_uri.html", + "browser_style": true + }, + + "commands": + { + "open_popup": + { + "suggested_key": + { + "default": "Ctrl+Shift+S" + }, + "description": "Add URI to remwharead." + } + } +} diff --git a/browser-plugins/webextension/native-wrapper/remwharead.json b/browser-plugins/webextension/native-wrapper/remwharead.json new file mode 100644 index 0000000..ba77bf8 --- /dev/null +++ b/browser-plugins/webextension/native-wrapper/remwharead.json @@ -0,0 +1,7 @@ +{ + "name": "remwharead", + "description": "Saves URIs of things you want to remember in a database.", + "path": "/usr/lib/mozilla/native-messaging-hosts/remwharead_wrapper.sh", + "type": "stdio", + "allowed_extensions": [ "remwharead@tastytea.de" ] +} diff --git a/browser-plugins/webextension/native-wrapper/remwharead_wrapper.sh b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.sh new file mode 100755 index 0000000..c887aba --- /dev/null +++ b/browser-plugins/webextension/native-wrapper/remwharead_wrapper.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +read args +args="$(echo ${args} | sed -E 's/^.+\"(.+)\"$/\1/')" # Remove length and quotes. +remwharead ${args}