aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2021-01-13 00:12:12 -0800
committerGitHub <noreply@github.com>2021-01-13 00:12:12 -0800
commitc8f6827e76768e5da20531c62da008e01865565c (patch)
tree2fe22d5e12c06e4015fbd1598233daa85507e367
parent0a6c542c767f7cb13b577e4fb65af681a55c0aa8 (diff)
parent08885dc9904e2c68c794a1c88df4fedd8cdfff5e (diff)
Merge pull request #51 from joshuahhh/master
read/write textareas
-rw-r--r--extension/background.js20
1 files changed, 20 insertions, 0 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 {