Skip to content

Instantly share code, notes, and snippets.

@rirufa
Last active August 29, 2015 14:20
Show Gist options
  • Save rirufa/72af1d0f990c184bbeb9 to your computer and use it in GitHub Desktop.
Save rirufa/72af1d0f990c184bbeb9 to your computer and use it in GitHub Desktop.
FEZ SNSの戦争データを集める
var FezWarData = (function(){
function FezWarData(){
}
FezWarData.prototype.result = "";
FezWarData.prototype.fetchRecords = function(record_list_url){
console.log(record_list_url);
var d = new $.Deferred();
var requests = [];
$.ajax({
type: "GET",
url: record_list_url,
cache: false,
scriptCharset:"UTF-8"
}).done(function(res) {
var parsed_data = $($.parseHTML(res));
var record_list = parsed_data.find('.warRecordList > .parts > table > tbody > tr > td > a');
var loop_d = (new $.Deferred()).resolve();
record_list.each(function(i,e){
loop_d = loop_d.then(function(){ return FezWarData.prototype.fetchOnePage($(e).attr("href")); })
});
if(parsed_data.find('p.prev:eq(1) > a').text() == "次を表示")
{
var next_url = parsed_data.find('p.prev:eq(1) > a').attr('href');
//メモリーリークの原因になるので解放する
parsed_data.empty();
parsed_data = null;
loop_d = loop_d.then(function(){ return FezWarData.prototype.fetchRecords(next_url); })
}
loop_d.then(function(){
d.resolve();
});
});
return d.promise();
}
FezWarData.prototype.fetchOnePage = function(url){
var d = new $.Deferred();
$.ajax({
type: "GET",
url: url,
cache: false,
scriptCharset:"UTF-8"
}).done(function(res) {
var parsed_data = $($.parseHTML(res));
var title = parsed_data.find(".WarTitle").text().match(/(\d+年\d+月\d+日 \d+:\d+) (.+) (.+【.+】)/);
var header = title[1] + "," + title[2] + "," + title[3];
var of_content = "";
var df_content = "";
var result = parsed_data.find(".gauge").text().match(/防衛軍 (\d+) %攻撃軍 (\d+) %/);
if (parseInt(result[1]) > parseInt(result[2])){
of_content = "攻撃側,Lose,";
df_content = "防衛側,Win,";
}else if(parseInt(result[2]) > parseInt(result[1])){
of_content = "攻撃側,Win,";
df_content = "防衛側,Lose,";
}else{
of_content = "攻撃側,,";
df_content = "防衛側,,";
}
of_content += result[2] + ",";
df_content += result[1] + ",";
parsed_data.find(".WarMember.Heading.partsHeading").each(function(i,e){
var unit_match = $(e).html().match(/[A-Za-z]\s\((\d+)\)/);
var unit_number = null;
if(unit_match == null)
unit_number = $(e).html();
else
unit_number = unit_match[1];
if(i % 2 == 0)
df_content += unit_number + ",";
else
of_content += unit_number + ",";
});
parsed_data.find(".WarMember.Heading.partsHeading").each(function(i,e){
if($(e).parent().find("td[style]").size() > 0)
{
if(i % 2 == 0)
df_content += ",*";
else
of_content += ",*";
}
});
//余計な改行がつくので取り除く
FezWarData.prototype.result += header + "," + df_content.replace(/[\n\r]/g,"") + "<br>" + header + "," + of_content.replace(/[\n\r]/g,"") + "</br>";
parsed_data.empty();
parsed_data = null;
d.resolve();
});
return d.promise();
};
return FezWarData;
})();
var s = document.createElement('script');
s.src = '//ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js';
s.onload = function () {
var months = window.prompt("取得する月数を入力してください","all")
var month_list = $('#Left > .parts > .item > .list > li > a').
map(function(i, e){
if(i != "all" && i >= parseInt(months))
return null;
return $(e).attr("href");
});
var d = (new $.Deferred()).resolve();
var requests = [];
var war_data = new FezWarData();
$.each(month_list,function(i, record_list_url){
if(record_list_url != null)
d = d.then(function(){ return war_data.fetchRecords(record_list_url); });
});
d.then(function() {
var generator=window.open('','name','height=250,width=700');
generator.document.write('<html><head><title>Amazon to TSV</title>');
generator.document.write('</head><body>');
generator.document.write('<pre>');
generator.document.write('timestamp,area,map,type,result,gauge,参加者リスト,Warrior,Scout,Sorcerer,Fencer,Cestus,you_join<br/>');
generator.document.write(war_data.result);
generator.document.write('</pre>');
generator.document.write('</body></html>');
generator.document.close();
});
};
document.documentElement.appendChild(s);
@rirufa
Copy link
Author

rirufa commented May 8, 2015

使い方
1.fez snsの最近参加した戦争の「もっと見る」をクリックする
2.要素を検査するをクリック
3.コンソールに移動してfez_war_data.jsを貼り付ける

※ポップアップブロックが有効な場合、Windowが開かないことがあります

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment