Skip to content

Instantly share code, notes, and snippets.

@einichi
Last active May 1, 2022 18:02
Show Gist options
  • Save einichi/17ef170854438371b1265ce83d18a1b6 to your computer and use it in GitHub Desktop.
Save einichi/17ef170854438371b1265ce83d18a1b6 to your computer and use it in GitHub Desktop.
Exports Google Keep notes to CSV (text only), run in JS console when on keep.google.com
var elements = document.getElementsByTagName("*"); // Grab all elements, since the actual note content elements have no ID are seemingly randomly generated class IDs
var keepTitle = [];
var keepContent = [];
var x = 0;
for (var i=0; i < elements.length; i++) { // Loop through all elements
if (elements[i].hasAttribute("contenteditable") && elements[i].getAttribute("contenteditable") == "false") { // Elements with 'contenteditable' attr set to false in the Keep page are fortunately only note title and contents
if (x % 2 == 0) { // Simple means of separating title from contents
if (elements[i].innerHTML == "") { // Make it clear if the field was empty
keepTitle.push("(empty)");
}
else {
keepTitle.push(elements[i].innerHTML);
}
}
else {
if (elements[i].innerHTML == "") {
keepContent.push("(empty)");
}
else {
keepContent.push(elements[i].innerHTML);
}
}
x++; // Increase counter for actual title/content parsing iterations
}
}
var keepExport = [];
for (var i=0; i < keepTitle.length; i++) {
keepExport.push([keepTitle[i], keepContent[i]]); // Merge title/content arrays together
}
var csv = "data:text/csv;charset=utf-8," + keepExport.map(e => e.join(",")).join("\n"); // Convert to CSV format and add headers
var encodedUri = encodeURI(csv); // Encode
window.open(encodedUri); // Download
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment