Last active
February 23, 2017 18:54
-
-
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 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
//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