aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2020-10-29 23:16:06 -0700
committerOmar Rizwan <omar.rizwan@gmail.com>2020-10-29 23:16:06 -0700
commitf576b4c324d3c9a9a4fe2fc9ef60dc34427df1bc (patch)
treef67edc96392df7d340e06b0cfe2d0cf0849b53da /extension
parent76efd118e00ef7bad767563c3e60cb39c6ff932f (diff)
Manually set getattr op. Fixes text file.
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/extension/background.js b/extension/background.js
index e3dda87..8d6eb8a 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -44,6 +44,17 @@ function pathComponent(path, i) {
function sanitize(s) {
return s.replace(/[^A-Za-z0-9_\-\.]/gm, '_');
}
+function stringSize(str) {
+ // returns the byte length of an utf8 string
+ var s = str.length;
+ for (var i=str.length-1; i>=0; i--) {
+ var code = str.charCodeAt(i);
+ if (code > 0x7f && code <= 0x7ff) s++;
+ else if (code > 0x7ff && code <= 0xffff) s+=2;
+ if (code >= 0xDC00 && code <= 0xDFFF) i--; //trail surrogate
+ }
+ return s + 1;
+}
/* if I could specify a custom editor interface for all the routing
below ... I would highlight the route names in blocks of some color
@@ -53,6 +64,14 @@ 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 read(path, fh, size, offset) {
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
return handler(tab).substr(offset, size);
@@ -61,9 +80,18 @@ function withTab(handler) {
}
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 read(path, fh, size, offset) {
const tabId = parseInt(pathComponent(path, -2));
- return browser.tabs.executeScript(tabId, {code}).substr(offset, size);
+ return (await browser.tabs.executeScript(tabId, {code}))[0]
+ .substr(offset, size);
}
};
}