Created
July 9, 2020 00:42
-
-
Save jmanuel1/ffe77a5a49997512559b9a4cf1839bb4 to your computer and use it in GitHub Desktop.
Convert your schema.rocks notes to org files!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| 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(); | |
| }; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you use this?
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
documentToOrgfunction, 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!