Skip to content

Instantly share code, notes, and snippets.

@jmanuel1
Created July 9, 2020 00:42
Show Gist options
  • Select an option

  • Save jmanuel1/ffe77a5a49997512559b9a4cf1839bb4 to your computer and use it in GitHub Desktop.

Select an option

Save jmanuel1/ffe77a5a49997512559b9a4cf1839bb4 to your computer and use it in GitHub Desktop.
Convert your schema.rocks notes to org files!
{
function documentToOrg(document) {
const title = document.querySelector("#document_title").value;
let orgFile = `#+TITLE: ${title}\n\n`;
const bullets = document.querySelector("#root_node_children");
function bulletsToOrg(bullets, level = 1) {
let orgBullets = "";
for (let bullet of bullets.children) {
const tag = bullet.tagName.toLowerCase();
if (tag === "li") {
orgBullets += bulletsToOrg(bullet, level);
} else if (tag === "div") {
const dashes = "-".repeat(level) + " ";
let file = "";
if (bullet.querySelector(".node_file")) {
file = "[[UNKNOWN???][Replace with link to file]] ";
}
let text = "";
for (let node of bullet.querySelector(".transparent_textarea.schema-editable-input").childNodes) {
if (node.tagName && node.tagName.toLowerCase() === "b") {
text += `*${node.textContent}*`;
} else if (node.tagName && node.tagName.toLowerCase() === "i") {
text += `/${node.textContent}/`;
} else {
text += node.textContent;
}
}
orgBullets += dashes + file + text + "\n";
} else if (tag === "ul") {
orgBullets += bulletsToOrg(bullet, level + 1);
}
}
return orgBullets;
}
orgFile += bulletsToOrg(bullets);
return orgFile;
}
const documents = document.querySelectorAll(".document_list_item");
for (let doc of documents) {
const id = doc.id;
const documentId = /document_list_item_(.*)/.exec(id)[1];
const w = window.open("http://www.schema.rocks/" + documentId);
w.onload = () => {
console.log(documentToOrg(w.document));
w.close();
};
}
}
@jmanuel1
Copy link
Author

jmanuel1 commented Jul 9, 2020

How do you use this?

  1. Navigate to http://www.schema.rocks and sign in.
  2. On the workspace page, open your browser's developer tools.
  3. Paste this code (convert.js) into the JavaScript console and press enter.

The result: The code will open as many tabs as there are Schema documents on the page (sorry). The org mode version of these documents will be logged to the console. During the process, the new tabs will close themselves.

Why?

Converting each of my documents manually was tedious and repetitive. So I wrote the documentToOrg function, which took me about 30 minutes.

The rest of the script took me like an hour and a half :(. I couldn't get authentication working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment