summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extension/background.js20
-rwxr-xr-xinstall.sh13
-rw-r--r--test/test-textarea.html10
-rw-r--r--test/test.c20
4 files changed, 58 insertions, 5 deletions
diff --git a/extension/background.js b/extension/background.js
index c660aee..5e487cf 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -449,6 +449,26 @@ router["/tabs/by-id/*/active"] = {
});
})();
+router["/tabs/by-id/*/textareas"] = {
+ async readdir({path}) {
+ const tabId = parseInt(pathComponent(path, -2));
+ // TODO: assign new IDs to textareas without them?
+ const code = `Array.from(document.querySelectorAll('textarea')).map(e => e.id).filter(id => id)`
+ const ids = (await browser.tabs.executeScript(tabId, {code}))[0];
+ return { entries: [".", "..", ...ids.map(id => `${id}.txt`)] };
+ }
+};
+router["/tabs/by-id/*/textareas/*"] = defineFile(async path => {
+ const [tabId, textareaId] = [parseInt(pathComponent(path, -3)), pathComponent(path, -1).slice(0, -4)];
+ const code = `document.getElementById('${textareaId}').value`;
+ const textareaValue = (await browser.tabs.executeScript(tabId, {code}))[0];
+ return textareaValue;
+}, async (path, buf) => {
+ const [tabId, textareaId] = [parseInt(pathComponent(path, -3)), pathComponent(path, -1).slice(0, -4)];
+ const code = `document.getElementById('${textareaId}').value = unescape('${escape(buf)}')`;
+ await browser.tabs.executeScript(tabId, {code});
+});
+
router["/tabs/by-title"] = {
getattr() {
return {
diff --git a/install.sh b/install.sh
index 81db93d..b6bfa36 100755
--- a/install.sh
+++ b/install.sh
@@ -5,15 +5,18 @@ set -eux
# (Brave uses same path as Chrome, so for Brave, say `chrome`)
if [[ "$#" -lt 1 || (
! ( ( "$1" == "firefox" && "$#" -eq 1 ) ||
+ ( "$1" == "brave" && "$#" -eq 2 && ${#2} -eq 32 ) ||
( "$1" == "chrome" && "$#" -eq 2 && ${#2} -eq 32 ) ||
( "$1" == "vivaldi" && "$#" -eq 2 && ${#2} -eq 32 ) ||
( "$1" == "chromebeta" && "$#" -eq 2 && ${#2} -eq 32 ) ||
( "$1" == "chromium" && "$#" -eq 2 && ${#2} -eq 32 ) ||
( "$1" == "edgedev" && "$#" -eq 2 && ${#2} -eq 32 ) ) ) ]]; then
- echo "Usage: $0 <chrome EXTENSION_ID | chromebeta EXTENSION_ID | chromium EXTENSION_ID | vivaldi EXTENSION_ID | edgedev EXTENSION_ID | firefox>"
+ echo "Usage: $0 <chrome EXTENSION_ID | firefox |
+ chromebeta EXTENSION_ID | chromium EXTENSION_ID |
+ vivaldi EXTENSION_ID | edgedev EXTENSION_ID | brave EXTENSION_ID>"
exit 2
fi
-
+
OS="$(uname -s)"
BROWSER="$(echo $1 | tr '[:upper:]' '[:lower:]')"
@@ -26,6 +29,8 @@ case "$OS $BROWSER" in
MANIFEST_LOCATION="$HOME/.mozilla/native-messaging-hosts";;
"Darwin firefox")
MANIFEST_LOCATION="$HOME/Library/Application Support/Mozilla/NativeMessagingHosts";;
+ "Linux brave")
+ MANIFEST_LOCATION="$HOME/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts";;
"Linux chrome")
MANIFEST_LOCATION="$HOME/.config/google-chrome/NativeMessagingHosts";;
"FreeBSD chromium")
@@ -42,6 +47,8 @@ case "$OS $BROWSER" in
MANIFEST_LOCATION="$HOME/Library/Application Support/Google/Chrome Beta/NativeMessagingHosts";;
"Darwin chromium")
MANIFEST_LOCATION="$HOME/Library/Application Support/Chromium/NativeMessagingHosts";;
+ "Darwin vivaldi")
+ MANIFEST_LOCATION="$HOME/Library/Application Support/Vivaldi/NativeMessagingHosts";;
esac
mkdir -p "$MANIFEST_LOCATION"
@@ -50,7 +57,7 @@ APP_NAME="com.rsnous.tabfs"
EXE_PATH=$(pwd)/fs/tabfs
case "$BROWSER" in
- chrome | chromium | chromebeta | vivaldi | edgedev)
+ chrome | chromium | chromebeta | brave | vivaldi | edgedev)
EXTENSION_ID=$2
MANIFEST=$(cat <<EOF
{
diff --git a/test/test-textarea.html b/test/test-textarea.html
new file mode 100644
index 0000000..9c460fa
--- /dev/null
+++ b/test/test-textarea.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Textarea Test Page</title>
+ </head>
+ <body>
+ <textarea id="ta">initial text</textarea>
+ </body>
+</html>
diff --git a/test/test.c b/test/test.c
index aaff360..6f4537d 100644
--- a/test/test.c
+++ b/test/test.c
@@ -79,11 +79,27 @@ int main() {
}
// try to shorten the URL (#40)
- assert(system("echo about:blank > ../fs/mnt/tabs/last-focused/url.txt") == 0);
- assert(file_contents_equal("../fs/mnt/tabs/last-focused/url.txt", "about:blank"));
+ /* assert(system("echo about:blank > ../fs/mnt/tabs/last-focused/url.txt") == 0); */
+ /* assert(file_contents_equal("../fs/mnt/tabs/last-focused/url.txt", "about:blank")); */
assert(system("echo remove > ../fs/mnt/tabs/last-focused/control") == 0);
}
+ {
+ assert(system("echo file://$(pwd)/test-textarea.html > ../fs/mnt/tabs/create") == 0);
+ {
+ FILE* console = fopen("../fs/mnt/tabs/last-focused/console", "r");
+ assert(system("echo \"console.log(document.getElementById('ta').value)\" > ../fs/mnt/tabs/last-focused/execute-script") == 0);
+
+ char ta[100] = {0}; fread(ta, 1, sizeof(ta), console);
+ assert(strcmp(ta, "initial text") == 0);
+
+ assert(file_contents_equal("../fs/mnt/tabs/last-focused/textareas/ta.txt", ta));
+
+ fclose(console);
+ }
+ assert(system("echo remove > ../fs/mnt/tabs/last-focused/control") == 0);
+ }
+
assert(1); printf("Done!\n");
}