Improved webextension and wrapper script.
continuous-integration/drone/push Build is passing Details

Got rid of the form, it was causing errors. Sending back a test
message worked.
This commit is contained in:
tastytea 2019-05-21 09:42:58 +02:00
parent 0ef7dbe253
commit 65c0bfc7ea
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
6 changed files with 72 additions and 24 deletions

View File

@ -6,6 +6,7 @@ project(remwharead
set(WITH_MAN "YES" CACHE STRING "WITH_MAN defaults to \"YES\"")
set(WITH_TESTS "NO" CACHE STRING "WITH_TESTS defaults to \"NO\"")
set(WITH_MOZILLA "NO" CACHE STRING "WITH_MOZILLA defaults to \"NO\"")
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
@ -63,6 +64,13 @@ if (WITH_MAN)
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
endif()
if (WITH_MOZILLA)
install(FILES
browser-plugins/webextension/native-wrapper/remwharead.json
browser-plugins/webextension/native-wrapper/remwharead_wrapper.sh
DESTINATION "${CMAKE_INSTALL_LIBDIR}/mozilla/native-messaging-hosts")
endif()
if(WITH_TESTS)
add_library(${PROJECT_NAME}_testlib SHARED ${sources})
target_link_libraries(${PROJECT_NAME}_testlib ${COMMON_LIBRARIES})

View File

@ -96,6 +96,7 @@ cmake --build .
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build.
* `-DWITH_MAN=NO` to not compile the manpage.
* `WITH_TESTS=YES` to compile the tests.
* `WITH_MOZILLA=YES` to install the helper script for the Mozilla extension.
* One of:
** `-DWITH_DEB=YES` if you want to be able to generate a deb-package.
** `-DWITH_RPM=YES` if you want to be able to generate an rpm-package.

View File

@ -4,11 +4,9 @@
<meta charset="utf-8">
</head>
<body>
<form id="add_uri">
<label for="tags">Tags, comma separated:</label>
<input type="text" id="tags" autofocus>
<input type="submit" value="Add URI">
</form>
<label for="tags">Tags, comma separated:</label>
<input type="text" id="tags" autofocus>
<input type="button" id="button" value="Add URI">
<script src="launch.js"></script>
</body>

View File

@ -1,27 +1,53 @@
var taburl;
var port;
function onResponse(response)
{
console.log(`Received ${response}`);
}
function onError(error)
{
console.log(`Error: ${error}`);
}
function set_taburl(tabs)
function set_taburl(tabs) // Set taburl to URL of current tab.
{
let tab = tabs[0];
taburl = tab.url;
}
function launch()
function get_tags() // get tags from text input.
{
let tags = document.getElementById("tags").value;
var sending = browser.runtime.sendNativeMessage("remwharead", "-t " + tags + " " + taburl);
sending.then(onResponse, onError);
if (tags != "")
{
return "-t " + tags + " ";
}
return "";
}
function onResponse(response) {
console.log("Received " + response);
}
function onError(error) {
console.log(`Error: ${error}`);
}
function launch() // Launch wrapper and send tags + URL to stdin.
{
var arguments = get_tags() + taburl;
console.log("Sending: " + arguments + " to remwharead");
var sending = browser.runtime.sendNativeMessage("remwharead", arguments);
sending.then(onResponse, onError);
window.close();
}
// Call set_taburl() with current tab.
browser.tabs.query({currentWindow: true, active: true}).then(set_taburl);
add_uri.addEventListener("submit", launch);
button.addEventListener("click", launch); // Call send() if submit is clicked.
// Click button if enter is hit in text input.
document.querySelector("#tags").addEventListener(
"keyup", event =>
{
if(event.key !== "Enter")
{
return;
}
document.querySelector("#button").click();
event.preventDefault();
});

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "remwharead",
"version": "0.1.0",
"version": "0.1.1",
"description": "Integrates remwharead into your Browser.",
"homepage_url": "https://schlomp.space/tastytea/remwharead",

View File

@ -1,5 +1,20 @@
#!/bin/sh
#!/bin/bash
args=""
start=0
# Read everything betweeen " and the next " into args.
while IFS= read -r -n1 c; do
if [[ ${start} -eq 0 ]]; then
[[ "${c}" == '"' ]] && start=1
continue
fi
if [[ "$c" != '"' ]] ; then
args="${args}$c"
continue
fi
break;
done
read args
args="$(echo ${args} | sed -E 's/^.+\"(.+)\"$/\1/')" # Remove length and quotes.
remwharead ${args}
echo -en '\x06\x00\x00\x00''"test"'