Last active
February 13, 2016 07:46
-
-
Save suitougreentea/f64cac690ca718917be7 to your computer and use it in GitHub Desktop.
download() function: http://qiita.com/ukyo/items/d623209655a003b13add
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 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