-
-
Save jasonmhoule/0937d5af819d1914c7803f22ee8752d6 to your computer and use it in GitHub Desktop.
Export notes from Google Keep into tiddlers
This file contains 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() { | |
async function main() { | |
// Create an arrary of all active notes | |
notes = document.body.getElementsByClassName("RNfche"); | |
// Iterate over each note and add the output to output array | |
notes_out = new Array(); | |
for (let i = notes.length - 1; i >= 0; i--) { | |
if(notes[i].getElementsByClassName("JqEhuc")[0].ariaLabel == "Unarchive") { | |
continue; | |
} | |
notes[i].click(); | |
await sleep(1000); | |
notes_out.push(getPopup()); | |
await sleep(1000); | |
} | |
// Create the necessary HTML anchor to download the data | |
let anchor = document.createElement('a'); | |
anchor.download = "keep_notes.json"; | |
anchor.href = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(notes_out)); | |
anchor.click(); | |
} | |
function getPopup() { | |
popup = document.body.getElementsByClassName("oT9UPb")[0]; | |
var json_out = new Object(); | |
now = new Date(); | |
json_out.title = popup.getElementsByClassName("IZ65Hb-r4nke-haAclf")[0].innerText + ` ${now.getUTCFullYear()}${(now.getUTCMonth() + 1).toString().padStart(2, "0")}${now.getUTCDate().toString().padStart(2, "0")}${now.getUTCSeconds().toString().padStart(2, "0")}${now.getUTCMilliseconds().toString().padStart(3, "0")}`; | |
json_out.tags = "Inbox todo"; | |
json_out.type = "text/x-markdown"; | |
var newtags = popup.getElementsByClassName("IZ65Hb-jfdpUb")[0].getElementsByClassName("Q0hgme-XPtOyb XPtOyb-di8rgd-Bz112c notranslate"); | |
for (let i = 0; i < newtags.length; i++) { | |
newtag = newtags[i].innerText; | |
if(newtag != "export") { | |
json_out.tags = json_out.tags + " [[" + newtag + "]]"; | |
} | |
} | |
json_out.text = popup.getElementsByClassName("IZ65Hb-qJTHM-haAclf")[0].innerText; | |
json_out.created = `${now.getUTCFullYear()}${(now.getUTCMonth() + 1).toString().padStart(2, "0")}${now.getUTCDate().toString().padStart(2, "0")}${now.getUTCHours().toString().padStart(2, "0")}${now.getUTCMinutes().toString().padStart(2, "0")}${now.getUTCSeconds().toString().padStart(2, "0")}000`; | |
json_out.modified = json_out.created; | |
// archive note | |
tbut = popup.getElementsByClassName("JqEhuc")[0]; | |
down = new MouseEvent('mousedown'); | |
up = new MouseEvent('mouseup'); | |
tbut.dispatchEvent(down); | |
tbut.dispatchEvent(up); | |
return json_out; | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
// Entry point. | |
main(); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment