mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-14 03:26:36 +02:00
extension: more routes.html descriptions and improvements.
This commit is contained in:
parent
c5228d4ac0
commit
ff53ae7d01
|
@ -212,7 +212,7 @@ Routes["/tabs/by-title"] = {
|
||||||
};
|
};
|
||||||
Routes["/tabs/by-title/:TAB_TITLE.#TAB_ID"] = {
|
Routes["/tabs/by-title/:TAB_TITLE.#TAB_ID"] = {
|
||||||
description: `Represents one open tab.
|
description: `Represents one open tab.
|
||||||
It's a symbolic link to /tabs/by-id/#TAB_ID.`,
|
It's a symbolic link to the folder /tabs/by-id/#TAB_ID.`,
|
||||||
// TODO: date
|
// TODO: date
|
||||||
usage: ['rm $0'],
|
usage: ['rm $0'],
|
||||||
async readlink({tabId}) {
|
async readlink({tabId}) {
|
||||||
|
@ -225,7 +225,7 @@ It's a symbolic link to /tabs/by-id/#TAB_ID.`,
|
||||||
};
|
};
|
||||||
Routes["/tabs/last-focused"] = {
|
Routes["/tabs/last-focused"] = {
|
||||||
description: `Represents the most recently focused tab.
|
description: `Represents the most recently focused tab.
|
||||||
It's a symbolic link to /tabs/by-id/[ID of most recently focused tab].`,
|
It's a symbolic link to the folder /tabs/by-id/[ID of most recently focused tab].`,
|
||||||
async readlink() {
|
async readlink() {
|
||||||
const id = (await browser.tabs.query({ active: true, lastFocusedWindow: true }))[0].id;
|
const id = (await browser.tabs.query({ active: true, lastFocusedWindow: true }))[0].id;
|
||||||
return { buf: "by-id/" + id };
|
return { buf: "by-id/" + id };
|
||||||
|
@ -297,7 +297,7 @@ Routes["/tabs/by-id"] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
Routes["/tabs/by-id/#TAB_ID/active"] = {
|
Routes["/tabs/by-id/#TAB_ID/active"] = {
|
||||||
description: 'Text file with `true` or `false` depending on whether this tab is active in its window.',
|
description: 'Text file containing `true` or `false` depending on whether this tab is active in its window.',
|
||||||
usage: ['cat $0',
|
usage: ['cat $0',
|
||||||
'echo true > $0'],
|
'echo true > $0'],
|
||||||
...routeForTab(
|
...routeForTab(
|
||||||
|
@ -318,7 +318,6 @@ function createWritableDirectory() {
|
||||||
return {
|
return {
|
||||||
directory: dir,
|
directory: dir,
|
||||||
routeForRoot: {
|
routeForRoot: {
|
||||||
usage: 'ls $0',
|
|
||||||
async readdir({path}) {
|
async readdir({path}) {
|
||||||
// get just last component of keys (filename)
|
// get just last component of keys (filename)
|
||||||
return { entries: [".", "..",
|
return { entries: [".", "..",
|
||||||
|
@ -335,9 +334,6 @@ function createWritableDirectory() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
routeForFilename: {
|
routeForFilename: {
|
||||||
usage: ['echo "2 + 2" > $0',
|
|
||||||
'cat $0.result'],
|
|
||||||
|
|
||||||
async mknod({path, mode}) {
|
async mknod({path, mode}) {
|
||||||
dir[path] = '';
|
dir[path] = '';
|
||||||
return {};
|
return {};
|
||||||
|
@ -358,9 +354,16 @@ function createWritableDirectory() {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
const evals = createWritableDirectory();
|
const evals = createWritableDirectory();
|
||||||
Routes["/tabs/by-id/#TAB_ID/evals"] = evals.routeForRoot;
|
Routes["/tabs/by-id/#TAB_ID/evals"] = {
|
||||||
|
...evals.routeForRoot,
|
||||||
|
description: `Add JavaScript files to this folder to evaluate them in the tab.`,
|
||||||
|
usage: 'ls $0'
|
||||||
|
};
|
||||||
Routes["/tabs/by-id/#TAB_ID/evals/:FILENAME"] = {
|
Routes["/tabs/by-id/#TAB_ID/evals/:FILENAME"] = {
|
||||||
...evals.routeForFilename,
|
...evals.routeForFilename,
|
||||||
|
// FIXME: use $0 here
|
||||||
|
usage: ['echo "2 + 2" > tabs/by-id/#TAB_ID/evals/twoplustwo.js',
|
||||||
|
'cat tabs/by-id/#TAB_ID/evals/twoplustwo.js.result'],
|
||||||
async write(req) {
|
async write(req) {
|
||||||
const ret = await evals.routeForFilename.write(req);
|
const ret = await evals.routeForFilename.write(req);
|
||||||
const code = evals.directory[req.path];
|
const code = evals.directory[req.path];
|
||||||
|
@ -372,6 +375,9 @@ function createWritableDirectory() {
|
||||||
(function() {
|
(function() {
|
||||||
const watches = {};
|
const watches = {};
|
||||||
Routes["/tabs/by-id/#TAB_ID/watches"] = {
|
Routes["/tabs/by-id/#TAB_ID/watches"] = {
|
||||||
|
description: `Put a file in this folder with a JS expression as its filename.
|
||||||
|
Read that file to evaluate and return the current value of that JS expression.`,
|
||||||
|
usage: 'ls $0',
|
||||||
async readdir({tabId}) {
|
async readdir({tabId}) {
|
||||||
return { entries: [".", "..", ...Object.keys(watches[tabId] || [])] };
|
return { entries: [".", "..", ...Object.keys(watches[tabId] || [])] };
|
||||||
},
|
},
|
||||||
|
@ -384,6 +390,8 @@ function createWritableDirectory() {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Routes["/tabs/by-id/#TAB_ID/watches/:EXPR"] = {
|
Routes["/tabs/by-id/#TAB_ID/watches/:EXPR"] = {
|
||||||
|
description: `A file with a JS expression :EXPR as its filename.`,
|
||||||
|
usage: `touch '/tabs/by-id/#TAB_ID/watches/2+2' && cat '/tabs/by-id/#TAB_ID/watches/2+2'`,
|
||||||
// NOTE: eval runs in extension's content script, not in original page JS context
|
// NOTE: eval runs in extension's content script, not in original page JS context
|
||||||
async mknod({tabId, expr, mode}) {
|
async mknod({tabId, expr, mode}) {
|
||||||
watches[tabId] = watches[tabId] || {};
|
watches[tabId] = watches[tabId] || {};
|
||||||
|
@ -410,14 +418,16 @@ function createWritableDirectory() {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
Routes["/tabs/by-id/#TAB_ID/window"] = {
|
Routes["/tabs/by-id/#TAB_ID/window"] = {
|
||||||
// a symbolic link to /windows/[id for this window]
|
description: `The window that this tab lives in;
|
||||||
|
a symbolic link to the folder /windows/[id for this window].`,
|
||||||
async readlink({tabId}) {
|
async readlink({tabId}) {
|
||||||
const tab = await browser.tabs.get(tabId);
|
const tab = await browser.tabs.get(tabId);
|
||||||
return { buf: "../../../windows/" + tab.windowId };
|
return { buf: "../../../windows/" + tab.windowId };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Routes["/tabs/by-id/#TAB_ID/control"] = {
|
Routes["/tabs/by-id/#TAB_ID/control"] = {
|
||||||
// see https://developer.chrome.com/extensions/tabs
|
description: `Write control commands to this file to control this tab;
|
||||||
|
see https://developer.chrome.com/extensions/tabs.`,
|
||||||
usage: ['echo remove > $0',
|
usage: ['echo remove > $0',
|
||||||
'echo reload > $0',
|
'echo reload > $0',
|
||||||
'echo goForward > $0',
|
'echo goForward > $0',
|
||||||
|
@ -555,6 +565,7 @@ Routes["/tabs/by-id/#TAB_ID/control"] = {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
Routes["/tabs/by-id/#TAB_ID/inputs"] = {
|
Routes["/tabs/by-id/#TAB_ID/inputs"] = {
|
||||||
|
description: `Contains a file for each text input and textarea on this page (as long as it has an ID, currently).`,
|
||||||
async readdir({tabId}) {
|
async readdir({tabId}) {
|
||||||
// TODO: assign new IDs to inputs without them?
|
// TODO: assign new IDs to inputs without them?
|
||||||
const code = `Array.from(document.querySelectorAll('textarea, input[type=text]'))
|
const code = `Array.from(document.querySelectorAll('textarea, input[type=text]'))
|
||||||
|
@ -581,7 +592,7 @@ Routes["/windows"] = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Routes["/windows/last-focused"] = {
|
Routes["/windows/last-focused"] = {
|
||||||
// a symbolic link to /windows/[id for this window]
|
description: `A symbolic link to /windows/[id for the last focused window].`,
|
||||||
async readlink() {
|
async readlink() {
|
||||||
const windowId = (await browser.windows.getLastFocused()).id;
|
const windowId = (await browser.windows.getLastFocused()).id;
|
||||||
return { buf: windowId };
|
return { buf: windowId };
|
||||||
|
@ -681,11 +692,14 @@ Routes["/runtime/routes.html"] = makeRouteWithContents(async () => {
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<style>
|
<style>
|
||||||
dt:not(:first-of-type) { margin-top: 1em; }
|
dt:not(:first-of-type) { margin-top: 1em; }
|
||||||
|
.description { font-style: italic; }
|
||||||
|
summary { color: #555; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>This page is automatically generated from <a href="https://github.com/osnr/TabFS/blob/master/extension/background.js">extension/background.js in the TabFS source code</a>.</p>
|
<p>This page is automatically generated from <a href="https://github.com/osnr/TabFS/blob/master/extension/background.js">extension/background.js in the TabFS source code</a>.</p>
|
||||||
<p>It documents each of the folders and files that TabFS serves up from your browser.</p>
|
<p>It documents each of the folders and files that TabFS serves up from your browser.</p>
|
||||||
|
<p>Variables here, like :TAB_TITLE and #TAB_ID, are stand-ins for concrete values of what you actually have open in your browser.</p>
|
||||||
<p>(work in progress)</p>
|
<p>(work in progress)</p>
|
||||||
<dl>
|
<dl>
|
||||||
` + Object.entries(Routes).map(([path, {usage, description, __isInfill, readdir}]) => {
|
` + Object.entries(Routes).map(([path, {usage, description, __isInfill, readdir}]) => {
|
||||||
|
@ -695,13 +709,13 @@ Routes["/runtime/routes.html"] = makeRouteWithContents(async () => {
|
||||||
const lineRange = findRouteLineRange(path);
|
const lineRange = findRouteLineRange(path);
|
||||||
return `
|
return `
|
||||||
<dt>${readdir ? '📁' : '📄'} ${path.substring(1)}</dt>
|
<dt>${readdir ? '📁' : '📄'} ${path.substring(1)}</dt>
|
||||||
${description ? `<dd>Description: ${description}</dd>` :
|
${description ? `<dd class="description">${description}</dd>` :
|
||||||
'<dd style="background-color: #f99">No description found!</dd>'}
|
'<dd style="background-color: #f99">No description found!</dd>'}
|
||||||
${usages.length > 0 ? `<dd>Usage:
|
${usages.length > 0 ? `<dd><details><summary>Usage examples</summary>
|
||||||
<ul>
|
<ul>
|
||||||
${usages.map(u => `<li>${u}</li>`).join('\n')}
|
${usages.map(u => `<li>${u}</li>`).join('\n')}
|
||||||
</ul>
|
</ul>
|
||||||
</dd>` : '<dd style="background-color: #f99">No usage found!</dd>'}
|
</details></dd>` : '<dd style="background-color: #f99">No usage examples found!</dd>'}
|
||||||
${lineRange ?
|
${lineRange ?
|
||||||
`<dd><details>
|
`<dd><details>
|
||||||
<summary>Source code (<a href="https://github.com/osnr/TabFS/blob/master/extension/background.js#L${lineRange[0]+1}-L${lineRange[1]+1}">on GitHub</a>)</summary>
|
<summary>Source code (<a href="https://github.com/osnr/TabFS/blob/master/extension/background.js#L${lineRange[0]+1}-L${lineRange[1]+1}">on GitHub</a>)</summary>
|
||||||
|
|
Loading…
Reference in a new issue