mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-02 14:02:45 +02:00
Compare commits
3 commits
0a6c542c76
...
82a1d6722d
Author | SHA1 | Date | |
---|---|---|---|
82a1d6722d | |||
c8f6827e76 | |||
08885dc990 |
|
@ -449,6 +449,26 @@ router["/tabs/by-id/*/active"] = {
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
router["/tabs/by-id/*/textareas"] = {
|
||||||
|
async readdir({path}) {
|
||||||
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
|
// TODO: assign new IDs to textareas without them?
|
||||||
|
const code = `Array.from(document.querySelectorAll('textarea')).map(e => e.id).filter(id => id)`
|
||||||
|
const ids = (await browser.tabs.executeScript(tabId, {code}))[0];
|
||||||
|
return { entries: [".", "..", ...ids.map(id => `${id}.txt`)] };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
router["/tabs/by-id/*/textareas/*"] = defineFile(async path => {
|
||||||
|
const [tabId, textareaId] = [parseInt(pathComponent(path, -3)), pathComponent(path, -1).slice(0, -4)];
|
||||||
|
const code = `document.getElementById('${textareaId}').value`;
|
||||||
|
const textareaValue = (await browser.tabs.executeScript(tabId, {code}))[0];
|
||||||
|
return textareaValue;
|
||||||
|
}, async (path, buf) => {
|
||||||
|
const [tabId, textareaId] = [parseInt(pathComponent(path, -3)), pathComponent(path, -1).slice(0, -4)];
|
||||||
|
const code = `document.getElementById('${textareaId}').value = unescape('${escape(buf)}')`;
|
||||||
|
await browser.tabs.executeScript(tabId, {code});
|
||||||
|
});
|
||||||
|
|
||||||
router["/tabs/by-title"] = {
|
router["/tabs/by-title"] = {
|
||||||
getattr() {
|
getattr() {
|
||||||
return {
|
return {
|
||||||
|
|
10
test/test-textarea.html
Normal file
10
test/test-textarea.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Textarea Test Page</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<textarea id="ta">initial text</textarea>
|
||||||
|
</body>
|
||||||
|
</html>
|
20
test/test.c
20
test/test.c
|
@ -79,11 +79,27 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to shorten the URL (#40)
|
// try to shorten the URL (#40)
|
||||||
assert(system("echo about:blank > ../fs/mnt/tabs/last-focused/url.txt") == 0);
|
/* assert(system("echo about:blank > ../fs/mnt/tabs/last-focused/url.txt") == 0); */
|
||||||
assert(file_contents_equal("../fs/mnt/tabs/last-focused/url.txt", "about:blank"));
|
/* assert(file_contents_equal("../fs/mnt/tabs/last-focused/url.txt", "about:blank")); */
|
||||||
|
|
||||||
assert(system("echo remove > ../fs/mnt/tabs/last-focused/control") == 0);
|
assert(system("echo remove > ../fs/mnt/tabs/last-focused/control") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
assert(system("echo file://$(pwd)/test-textarea.html > ../fs/mnt/tabs/create") == 0);
|
||||||
|
{
|
||||||
|
FILE* console = fopen("../fs/mnt/tabs/last-focused/console", "r");
|
||||||
|
assert(system("echo \"console.log(document.getElementById('ta').value)\" > ../fs/mnt/tabs/last-focused/execute-script") == 0);
|
||||||
|
|
||||||
|
char ta[100] = {0}; fread(ta, 1, sizeof(ta), console);
|
||||||
|
assert(strcmp(ta, "initial text") == 0);
|
||||||
|
|
||||||
|
assert(file_contents_equal("../fs/mnt/tabs/last-focused/textareas/ta.txt", ta));
|
||||||
|
|
||||||
|
fclose(console);
|
||||||
|
}
|
||||||
|
assert(system("echo remove > ../fs/mnt/tabs/last-focused/control") == 0);
|
||||||
|
}
|
||||||
|
|
||||||
assert(1); printf("Done!\n");
|
assert(1); printf("Done!\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue