mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-17 21:16:35 +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
|
### 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
|
### 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/*/title"] = withTab(tab => tab.title + "\n");
|
||||||
router["/tabs/by-id/*/text"] = fromScript(`document.body.innerText`);
|
router["/tabs/by-id/*/text"] = fromScript(`document.body.innerText`);
|
||||||
router["/tabs/by-id/*/control"] = {
|
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) {
|
async write(path, buf) {
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
if (buf.trim() === 'close') {
|
const command = buf.trim();
|
||||||
await new Promise(resolve => chrome.tabs.remove(tabId, resolve));
|
// can use `discard`, `remove`, `reload`, `goForward`, `goBack`...
|
||||||
} else {
|
// see https://developer.chrome.com/extensions/tabs
|
||||||
throw new UnixError(unix.EIO);
|
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');
|
const assert = require('assert');
|
||||||
(async () => {
|
(async () => {
|
||||||
assert.deepEqual(await router['/tabs/by-id/*'].entries(), ['url', 'title', 'text', 'control']);
|
assert.deepEqual(await router['/tabs/by-id/*'].entries(), ['url', 'title', 'text', 'control']);
|
||||||
|
|
Loading…
Reference in a new issue