Skip to content

Instantly share code, notes, and snippets.

@suitougreentea
Last active February 13, 2016 07:46
Show Gist options
  • Save suitougreentea/f64cac690ca718917be7 to your computer and use it in GitHub Desktop.
Save suitougreentea/f64cac690ca718917be7 to your computer and use it in GitHub Desktop.
function download(blob, filename) {
var objectURL = (window.URL || window.webkitURL).createObjectURL(blob),
a = document.createElement('a');
e = document.createEvent('MouseEvent');
//a要素のdownload属性にファイル名を設定
a.download = filename;
a.href = objectURL;
//clickイベントを着火
e.initEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
}
var table = []
$(".tngMainT tr:not(:first)").each(function() {
var e = $(this)
var word = e.find(".tngMainTTG").text().trim()
var meaning = e.find(".tngMainTIML").text().trim()
var exampleE = e.find(".tngMainTSRH").text().trim()
var exampleJ = e.find(".tngMainTSRFL").text().trim()
var learned = e.find(".tngMainTMK").find("b:not(.tngMainTLL)"+"[title=learned]").length == 1
table.push({word: word, meaning: meaning, exampleE: exampleE, exampleJ: exampleJ, learned: learned})
})
console.log(table)
var text = table
.filter(function(e) { return !e.learned })
.map(function(e) {
return (e.learned ? "●" : "○") + " " + e.word + "\n"
+ " " + e.meaning + "\n"
+ " " + e.exampleE + "\n"
+ " " + e.exampleJ + "\n"
}).join("\n")
console.log(text)
download(new Blob([text]), 'word-list.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment