aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2020-12-15 12:11:41 -0800
committerOmar Rizwan <omar@omar.website>2020-12-15 12:11:41 -0800
commitd21c9eace16593446cdedbd85ba780b7f4368b70 (patch)
tree752e8f8a08e7deb33b4a98c900392e4cf34d7b93 /extension
parent9feca9b0b90a107ece6be1b4d197e08020a40690 (diff)
make URL writable (kinda). allow delete in by-title/. README update
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js25
1 files changed, 17 insertions, 8 deletions
diff --git a/extension/background.js b/extension/background.js
index a233f27..e92069e 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -148,7 +148,7 @@ const defineFile = (getData, setData) => ({
},
async write({path, buf}) {
// FIXME: patch
- setData(path, buf); return {size: utf8(buf).length};
+ setData(path, buf); return { size: utf8(buf).length };
},
async release({fh}) { Cache.removeObjectForHandle(fh); return {}; }
});
@@ -177,17 +177,21 @@ router["/tabs/by-id"] = {
// TODO: scripts/
(function() {
- const withTab = handler => defineFile(async path => {
+ const withTab = (readHandler, writeHandler) => defineFile(async path => {
const tabId = parseInt(pathComponent(path, -2));
const tab = await browser.tabs.get(tabId);
- return handler(tab);
- });
+ return readHandler(tab);
+
+ }, writeHandler ? async (path, buf) => {
+ const tabId = parseInt(pathComponent(path, -2));
+ await browser.tabs.update(tabId, writeHandler(buf));
+ } : undefined);
const fromScript = code => defineFile(async path => {
const tabId = parseInt(pathComponent(path, -2));
return (await browser.tabs.executeScript(tabId, {code}))[0];
});
- router["/tabs/by-id/*/url"] = withTab(tab => tab.url + "\n");
+ router["/tabs/by-id/*/url"] = withTab(tab => tab.url + "\n", buf => ({ url: buf }));
router["/tabs/by-id/*/title"] = withTab(tab => tab.title + "\n");
router["/tabs/by-id/*/text"] = fromScript(`document.body.innerText`);
})();
@@ -259,7 +263,7 @@ router["/tabs/by-id/*/control"] = {
const command = buf.trim();
// can use `discard`, `remove`, `reload`, `goForward`, `goBack`...
// see https://developer.chrome.com/extensions/tabs
- await new Promise(resolve => chrome.tabs[command](tabId, resolve));
+ await browser.tabs[command](tabId);
return {size: utf8(buf).length};
}
};
@@ -280,8 +284,13 @@ router["/tabs/by-title"] = {
router["/tabs/by-title/*"] = {
// a symbolic link to /tabs/by-id/[id for this tab]
async readlink({path}) {
- const parts = path.split("_"); const id = parts[parts.length - 1];
- return { buf: "../by-id/" + id };
+ const parts = path.split("_"); const tabId = parts[parts.length - 1];
+ return { buf: "../by-id/" + tabId };
+ },
+ async unlink({path}) {
+ const parts = path.split("_"); const tabId = parseInt(parts[parts.length - 1]);
+ await browser.tabs.remove(tabId);
+ return {};
}
};