mirror of
https://github.com/osnr/TabFS.git
synced 2024-06-17 05:05:00 +02:00
active: refactor / simplify to use withTab
This commit is contained in:
parent
2215ba8e41
commit
e24f0f8afa
|
@ -238,6 +238,11 @@ router["/tabs/by-id"] = {
|
||||||
router["/tabs/by-id/*/title.txt"] = withTab(tab => tab.title + "\n");
|
router["/tabs/by-id/*/title.txt"] = withTab(tab => tab.title + "\n");
|
||||||
router["/tabs/by-id/*/text.txt"] = fromScript(`document.body.innerText`);
|
router["/tabs/by-id/*/text.txt"] = fromScript(`document.body.innerText`);
|
||||||
router["/tabs/by-id/*/source.html"] = fromScript(`document.body.innerHTML`);
|
router["/tabs/by-id/*/source.html"] = fromScript(`document.body.innerHTML`);
|
||||||
|
|
||||||
|
// echo true > mnt/tabs/by-id/1644/active
|
||||||
|
// cat mnt/tabs/by-id/1644/active
|
||||||
|
router["/tabs/by-id/*/active"] = withTab(tab => JSON.stringify(tab.active) + '\n',
|
||||||
|
buf => ({ active: buf.trim() === "true" }));
|
||||||
})();
|
})();
|
||||||
(function() {
|
(function() {
|
||||||
let nextConsoleFh = 0; let consoleForFh = {};
|
let nextConsoleFh = 0; let consoleForFh = {};
|
||||||
|
@ -355,25 +360,6 @@ router["/tabs/by-id/*/control"] = {
|
||||||
},
|
},
|
||||||
async truncate({path, size}) { return {}; }
|
async truncate({path, size}) { return {}; }
|
||||||
};
|
};
|
||||||
router["/tabs/by-id/*/active"] = {
|
|
||||||
// echo true > mnt/tabs/by-id/1644/active
|
|
||||||
// cat mnt/tabs/by-id/1644/active
|
|
||||||
async read({path, fh, offset, size}) {
|
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
|
||||||
const tab = await browser.tabs.get(tabId);
|
|
||||||
const buf = (JSON.stringify(tab.active) + '\n').slice(offset, offset + size);
|
|
||||||
return { buf };
|
|
||||||
},
|
|
||||||
async write({path, buf}) {
|
|
||||||
if (buf.trim() === "true") {
|
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
|
||||||
await browser.tabs.update(tabId, { active: true });
|
|
||||||
}
|
|
||||||
return {size: stringToUtf8Array(buf).length};
|
|
||||||
},
|
|
||||||
async truncate({path, size}) { return {}; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// debugger/ : debugger-API-dependent (Chrome-only)
|
// debugger/ : debugger-API-dependent (Chrome-only)
|
||||||
(function() {
|
(function() {
|
||||||
if (!chrome.debugger) return;
|
if (!chrome.debugger) return;
|
||||||
|
|
Loading…
Reference in a new issue