diff options
author | Omar Rizwan <omar.rizwan@gmail.com> | 2020-11-05 19:09:44 -0800 |
---|---|---|
committer | Omar Rizwan <omar.rizwan@gmail.com> | 2020-11-05 19:09:44 -0800 |
commit | 2befcb8db655431865cd07afbdb4e3171f840b12 (patch) | |
tree | 0a862b0951f84f0f0a77eec0ad914473b7a81d9d /extension/background.js | |
parent | 746cf02bd5dc5f85e426efea7324b2110a57e4b4 (diff) |
`close` should be `remove`. Make control allow arbitrary commands.
Diffstat (limited to 'extension/background.js')
-rw-r--r-- | extension/background.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/extension/background.js b/extension/background.js index 8d6eb8a..6406eb4 100644 --- a/extension/background.js +++ b/extension/background.js @@ -106,14 +106,13 @@ router["/tabs/by-id/*/url"] = withTab(tab => tab.url + "\n"); router["/tabs/by-id/*/title"] = withTab(tab => tab.title + "\n"); router["/tabs/by-id/*/text"] = fromScript(`document.body.innerText`); router["/tabs/by-id/*/control"] = { - // echo close >> mnt/tabs/by-id/1644/control + // echo remove >> mnt/tabs/by-id/1644/control async write(path, buf) { const tabId = parseInt(pathComponent(path, -2)); - if (buf.trim() === 'close') { - await new Promise(resolve => chrome.tabs.remove(tabId, resolve)); - } else { - throw new UnixError(unix.EIO); - } + 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)); } }; @@ -176,7 +175,7 @@ for (let key in router) { } } } -if (TESTING) { +if (TESTING) { // I wish I could color this section with... a pink background, or something. const assert = require('assert'); (async () => { assert.deepEqual(await router['/tabs/by-id/*'].entries(), ['url', 'title', 'text', 'control']); |