Text-based Jupyter #156
penn5
started this conversation in
Show and tell
Replies: 1 comment
-
|
For those who don't want to open external links, the gist of it is executing notebooks with Code for downloading from JupyterLab(() => {
$x('//*[@class="jp-LauncherCard"][@title="Python (Pyodide)"][@data-category="Console"]')[0].click();
console.log("created console");
const d = new DataTransfer();
const f = "Jupyter "+new Date().toISOString()+".zip";
const t = 'import zipfile, os\n' +
'zf = zipfile.ZipFile("'+f+'", "w")\n' +
'for dp, _, fns in os.walk("."):\n' +
' for fn in fns:\n' +
' if fn == "'+f+'":\n' +
' continue\n' +
' zf.write(os.path.join(dp, fn))\n' +
'zf.close()' ;
d.setData("text/plain", t);
const i = setInterval((() => {
if (!document.activeElement.classList.contains("cm-content")) {
return;
}
document.activeElement.dispatchEvent(new ClipboardEvent("paste", { clipboardData: d, dataType: "text/plain", data: t }));
console.log("pasted script");
document.getElementsByClassName("jp-CodeConsole-promptCell")[0].getElementsByClassName("cm-content")[0].dispatchEvent(new FocusEvent("focus"));
clearInterval(i);
console.log("focused input");
const j = setInterval((() => {
const e = $x('//*[@data-command="console:run-forced"]');
if (!e.length) {
return;
}
if ("disabled" in e[0].attributes) {
return;
}
console.log(document.getElementsByClassName("jp-CodeConsole-promptCell")[0].getElementsByClassName("cm-content")[0].innerText);
if (!document.getElementsByClassName("jp-CodeConsole-promptCell")[0].getElementsByClassName("cm-content")[0].innerText) {
return;
}
e[0].dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true, view: window }));
e[0].dispatchEvent(new MouseEvent("mouseup", { bubbles: true, cancelable: true, view: window }));
clearInterval(j);
console.log("clicked run");
const k = setInterval((() => {
const s = $x('//*[contains(concat(" ",normalize-space(@class)," ")," jp-InputPrompt ")][text()="[*]:"]');
if (s.length) {
console.log("waiting for execution");
return;
}
const e = $x('//*[@class="jp-DirListing-itemText"]//*[text()="'+f+'"]');
if (!e.length) {
return;
}
const e2 = e[0].closest(".jp-DirListing-item");
e2.dispatchEvent(new PointerEvent("mousedown", { bubbles: true, cancelable: true }));
e2.dispatchEvent(new PointerEvent("mouseup", { bubbles: true, cancelable: true }));
e[0].dispatchEvent(new PointerEvent("contextmenu", { bubbles: true, cancelable: true }));
clearInterval(k);
console.log("right-clicked file");
const l = setInterval((() => {
const e = $x('//*[@data-command="filebrowser:download"]');
if (!e.length) {
return;
}
e[0].dispatchEvent(new FocusEvent("focus"));
console.log("focused download button");
e[0].dispatchEvent(new PointerEvent("mousedown", { bubbles: true, cancelable: true }));
e[0].dispatchEvent(new PointerEvent("mouseup", { bubbles: true, cancelable: true }));
console.log("clicked download button");
clearInterval(l);
}), 200);
}), 200);
}), 200);
}), 200);
})(); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone!
I've written a short guide on converting a JupyterLab to plain text in a lossless way, so that it can be edited more easily with a screen reader or braille display. Should work for other types of notebook distribution too, but I particularly needed to get data out of JupyterLab. It's not perfect but it is a pretty good stopgap for users until Jupyter gets proper accessibility support. Might be nice to add this to the documentation if people think this is useful. Thoughts?
-penn5
Beta Was this translation helpful? Give feedback.
All reactions