mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-03 22:33:11 +02:00
close
should be remove
. Make control allow arbitrary commands.
This commit is contained in:
parent
746cf02bd5
commit
2befcb8db6
|
@ -38,7 +38,7 @@ Home / Twitter
|
|||
### Close all Stack Overflow tabs
|
||||
|
||||
```
|
||||
$ echo close | tee -a mnt/tabs/by-title/*Stack_Overflow*/control
|
||||
$ echo remove | tee -a mnt/tabs/by-title/*Stack_Overflow*/control
|
||||
```
|
||||
|
||||
### Save text of all tabs to a file
|
||||
|
|
|
@ -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']);
|
||||
|
|
Loading…
Reference in a new issue