mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-17 13:06:35 +02:00
fence withTab and fromScript into scope
This commit is contained in:
parent
d3b376582f
commit
1dd02874a3
|
@ -133,40 +133,6 @@ const BrowserState = { lastFocusedWindowId: null };
|
||||||
view of what the whole filesystem looks like at a glance. */
|
view of what the whole filesystem looks like at a glance. */
|
||||||
const router = {};
|
const router = {};
|
||||||
|
|
||||||
function withTab(handler) {
|
|
||||||
return {
|
|
||||||
async getattr({path}) {
|
|
||||||
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
|
||||||
return {
|
|
||||||
st_mode: unix.S_IFREG | 0444,
|
|
||||||
st_nlink: 1,
|
|
||||||
st_size: stringSize(handler(tab))
|
|
||||||
};
|
|
||||||
},
|
|
||||||
async open({path}) { return { fh: 0 }; },
|
|
||||||
async read({path, fh, size, offset}) {
|
|
||||||
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
|
||||||
return { buf: utf8(handler(tab), offset, size) };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
function fromScript(code) {
|
|
||||||
return {
|
|
||||||
async getattr({path}) {
|
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
|
||||||
return {
|
|
||||||
st_mode: unix.S_IFREG | 0444,
|
|
||||||
st_nlink: 1,
|
|
||||||
st_size: stringSize((await browser.tabs.executeScript(tabId, {code}))[0])
|
|
||||||
};
|
|
||||||
},
|
|
||||||
async open({path}) { return { fh: 0 }; },
|
|
||||||
async read({path, fh, size, offset}) {
|
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
|
||||||
return { buf: utf8((await browser.tabs.executeScript(tabId, {code}))[0], offset, size) }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const Cache = {
|
const Cache = {
|
||||||
// used when you open a file to cache the content we got from the browser
|
// used when you open a file to cache the content we got from the browser
|
||||||
// until you close that file.
|
// until you close that file.
|
||||||
|
@ -186,14 +152,45 @@ router["/tabs/by-id"] = {
|
||||||
return { entries: tabs.map(tab => String(tab.id)) };
|
return { entries: tabs.map(tab => String(tab.id)) };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
router["/tabs/by-id/*/url"] = withTab(tab => tab.url + "\n");
|
(function() {
|
||||||
router["/tabs/by-id/*/title"] = withTab(tab => tab.title + "\n");
|
const withTab = handler => ({
|
||||||
router["/tabs/by-id/*/text"] = fromScript(`document.body.innerText`);
|
async getattr({path}) {
|
||||||
|
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
||||||
|
return {
|
||||||
|
st_mode: unix.S_IFREG | 0444,
|
||||||
|
st_nlink: 1,
|
||||||
|
st_size: stringSize(handler(tab))
|
||||||
|
};
|
||||||
|
},
|
||||||
|
async open({path}) { return { fh: 0 }; },
|
||||||
|
async read({path, fh, size, offset}) {
|
||||||
|
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
||||||
|
return { buf: utf8(handler(tab), offset, size) };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const fromScript = code => ({
|
||||||
|
async getattr({path}) {
|
||||||
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
|
return {
|
||||||
|
st_mode: unix.S_IFREG | 0444,
|
||||||
|
st_nlink: 1,
|
||||||
|
st_size: stringSize((await browser.tabs.executeScript(tabId, {code}))[0])
|
||||||
|
};
|
||||||
|
},
|
||||||
|
async open({path}) { return { fh: 0 }; },
|
||||||
|
async read({path, fh, size, offset}) {
|
||||||
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
|
return { buf: utf8((await browser.tabs.executeScript(tabId, {code}))[0], offset, size) }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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/*/screenshot.png"] = {
|
router["/tabs/by-id/*/screenshot.png"] = {
|
||||||
async open({path}) {
|
async open({path}) {
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
await TabManager.debugTab(tabId); await TabManager.enableDomainForTab(tabId, "Page");
|
await TabManager.debugTab(tabId); await TabManager.enableDomainForTab(tabId, "Page");
|
||||||
// FIXME: cache.
|
|
||||||
|
|
||||||
const {data} = await sendDebuggerCommand(tabId, "Page.captureScreenshot");
|
const {data} = await sendDebuggerCommand(tabId, "Page.captureScreenshot");
|
||||||
return { fh: Cache.storeObject(Uint8Array.from(atob(data), c => c.charCodeAt(0))) };
|
return { fh: Cache.storeObject(Uint8Array.from(atob(data), c => c.charCodeAt(0))) };
|
||||||
|
|
Loading…
Reference in a new issue