Skip to content

Instantly share code, notes, and snippets.

@Plazmaz
Last active February 23, 2017 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Plazmaz/e733eada0c9798dfffa3b6c772933f8b to your computer and use it in GitHub Desktop.
Save Plazmaz/e733eada0c9798dfffa3b6c772933f8b to your computer and use it in GitHub Desktop.
Extract data from Google Books Ngram Viewer(https://books.google.com/ngrams/graph)
//This can be pasted into the chrome dev console to generate a comma seperated list
//of coordinates. This is copied to your clipboard and can be pasted into a CSV.
var children = document.getElementsByClassName("y axis main")[0].children;
var scaleStr = children[children.length - 2].children[1].innerHTML;
scaleStr = scaleStr.substring(0, scaleStr.length - 1);
var scale = 413 / parseFloat(scaleStr);
var data = document.getElementsByClassName("line visible clickable main")[0].getAttribute("d");
var coords = data.substr(1).split("L")
var msg = ""
for(var i = 0; i < coords.length; i++) {
var x = parseInt(coords[i].split(",")[0]) / scale;
var y = -(parseInt(coords[i].split(",")[1]) - 413) / scale;
msg += "\n" + x + "," + y
}
copy(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment