Created
April 14, 2019 17:31
-
-
Save hot-2130/e91890cbe6dcdb355f50009d8a285faa to your computer and use it in GitHub Desktop.
ブラウザ三国志 ランキング出力ツール
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
| // ==UserScript== | |
| // @name bro3_getrank_tool | |
| // @namespace bro3_getrank_tool | |
| // @description ブラウザ三国志 ランキング出力ツール byほっと | |
| // @include https://*.3gokushi.jp/user/ranking.php* | |
| // @include http://*.3gokushi.jp/user/ranking.php* | |
| // @version 1.1 | |
| // @require http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js | |
| // @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js | |
| // @resource jqueryui_css http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css | |
| // ==/UserScript== | |
| // version date author | |
| // 1.1 2019/04/14 作成開始 | |
| // load jQuery | |
| jQuery.noConflict(); | |
| j$ = jQuery; | |
| var PROTOCOL = location.protocol; | |
| var m_maxpage = 50; | |
| var m_urllist = []; | |
| var m_logkind = []; | |
| //----------------// | |
| // メインルーチン // | |
| //----------------// | |
| (function() { | |
| grt_getListTextReport(); | |
| })(); | |
| // ランキング収集 | |
| function grt_getListTextReport() { | |
| j$("#statMenu").after( | |
| "<div style='margin-left: 4px;'>" + | |
| "<input id='grt_tsv_report_button' type='button' value='現ページのランキングをTSV形式でテキスト出力する'></input>" + | |
| "<span style='font-size: 10px;'>ページ指定:</span>" + | |
| "<input id='grt_startpage' type='text' size='7' maxlength='4' style='font-size: 10px;'></input>" + | |
| "<span style='font-size: 10px;'>〜</span>" + | |
| "<input id='grt_endpage' type='text' size='7' maxlength='4' style='font-size: 10px;'></input>" + | |
| "<span style='font-size: 10px;'>(一度に指定できるのは" + m_maxpage + "ページ以内です)</span>" + | |
| "</div>" + | |
| "<div id='grt_result_box' style='position: absolute; z-index:9999;background-color: #a9a9a9; display: none; margin-top: 4px;'>" + | |
| "<div style='background-color: #d3d3d3; margin: 2px;'>" + | |
| "<div style='margin-left: 4px; font-weight: bold;'>" + | |
| "<input id='grt_close_result1' style='margin-right: 4px;' type='button' value='閉じる'></input>" + | |
| "<span id='grt_list_title'>報告書解析中</span>" + | |
| "</div>" + | |
| "<textarea id='grt_result_tsv' cols='98' rows='20' style='overflow: scroll; margin: 4px; '></textarea>" + | |
| "<br><input id='grt_close_result2' type='button' value='閉じる'></input>" + | |
| "</div>" + | |
| "</div>" | |
| ); | |
| // 閉じるボタン | |
| j$("[ id^='grt_close_result' ]").on('click', | |
| function() { | |
| j$("#grt_tsv_report_button").prop('disabled', false); | |
| j$("#grt_result_box").css('display', 'none'); | |
| } | |
| ); | |
| // TSV出力ボタン | |
| j$("#grt_tsv_report_button").on('click', function() { | |
| // ページ数チェック | |
| var l_flg = true; | |
| var l_startpage=j$("#grt_startpage").val(); | |
| var l_endpage=j$("#grt_endpage").val(); | |
| if ((l_startpage=="") && (l_endpage!="")){ | |
| l_startpage=l_endpage; | |
| } | |
| if ((l_startpage!="") && (l_endpage=="")){ | |
| l_endpage=l_startpage; | |
| } | |
| if ((l_startpage!="") && (l_endpage!="")){ | |
| if (grt_pagecheck(l_startpage,l_endpage)){ | |
| if(!confirm('複数ページを取得する場合、タイミングによって同じ報告書が取得される可能性があります')){ | |
| /* キャンセルの時の処理 */ | |
| l_flg = false; | |
| } | |
| } else { | |
| l_flg = false; | |
| } | |
| } | |
| // 取得 | |
| if (l_flg){ | |
| j$("#grt_tsv_report_button").prop('disabled', true); | |
| j$("#grt_result_box").css('display', 'block'); | |
| grt_getpage(l_startpage,l_endpage); // ページ取得 | |
| } | |
| }); | |
| } | |
| // ページ数チェック | |
| function grt_pagecheck(i_startpage,i_endpage) { | |
| //指定ページ数が50ページ以内 | |
| if (i_startpage.match(/[^0-9]+/)) { | |
| alert("指定ページは半角数字で入力して下さい。"); | |
| return false; | |
| } | |
| if (i_endpage.match(/[^0-9]+/)) { | |
| alert("指定ページは半角数字で入力して下さい。"); | |
| return false; | |
| } | |
| var l_startpage = parseInt(i_startpage, 10); | |
| var l_endpage = parseInt(i_endpage, 10); | |
| if (((l_endpage-l_startpage)>m_maxpage-1) || ((l_endpage-l_startpage)<0)){ | |
| alert("指定ページは" + m_maxpage + "ページ以内で指定してください"); | |
| return false; | |
| } | |
| var l_max=1; | |
| //対象ページが存在するか | |
| if (j$("ul[class=pager]").length > 0) { | |
| var l_pages = j$("ul[class=pager] li"); | |
| for (var i = 0; i < l_pages.length; i++) { | |
| var l_page = parseInt(j$(l_pages[i]).text(),10); | |
| if (!isNaN(l_page) && l_max < l_page) { | |
| l_max = l_page; | |
| } | |
| } | |
| } | |
| if (l_endpage>l_max){ | |
| alert("指定ページがページ数を超えています"); | |
| return false; | |
| } | |
| return true; | |
| } | |
| function grt_getpage(i_startpage,i_endpage){ | |
| //ランキング種類によってヘッダーとカラム数変更 | |
| var l_col=0; | |
| var l_header=0; | |
| if ((location.href.indexOf("m=attack_score") > 0) || (location.href.indexOf("m=defense_score") > 0) || | |
| (location.href.indexOf("m=destroy_score") > 0)){ | |
| // 撃破スコア // 防衛スコア //破砕スコア | |
| l_col=6; | |
| l_header="ランク\tuser_id\t君主名\t同盟略称\t撃破スコア\t防衛スコア\t破砕スコア"; | |
| } else if ((location.href.indexOf("m=population") > 0) || (location.href.indexOf("m=attack") > 0) || | |
| (location.href.indexOf("m=defense") > 0) || (location.href.indexOf("m=destroy") > 0)){ | |
| // 人口 // 攻撃 //防御 //破壊 | |
| l_col=7; | |
| l_header="ランク\tuser_id\t君主名\t人口\t攻撃\t防御\t破壊\t遠征"; | |
| } else if (location.href.indexOf("m=expedition") > 0) { | |
| // 遠征 | |
| l_col=6; | |
| l_header="ランク\tuser_id\t君主名\t同盟略称\t遠征ポイント\t進軍ポイント\t隣接ポイント"; | |
| } else if (location.href.indexOf("m=contribution") > 0) { | |
| // 寄付 | |
| l_col=4; | |
| l_header="ランク\tuser_id\t君主名\t同盟略称\t寄付ポイント"; | |
| } else if (location.href.indexOf("m=duel") > 0) { | |
| // デュエル | |
| l_col=6; | |
| l_header="ランク\tuser_id\t君主名\t同盟略称\tDP\t勝利数\t階級"; | |
| } else if (location.href.indexOf("m=npc_assault") > 0) { | |
| // 南蛮襲来 | |
| l_col=5; | |
| l_header="ランク\tuser_id\t君主名\t同盟略称\t南蛮撃退ポイント\t到達数"; | |
| } else { | |
| // 総合 | |
| l_col=4; | |
| l_header="ランク\tuser_id\t君主名\t同盟略称\t総合"; | |
| } | |
| if (i_startpage==""){ | |
| // 表示されているページのランキングを取得 | |
| var trlist = j$("#grayWrapper table[summary='ランキング'] tbody tr"); | |
| var summary = []; | |
| summary.push(l_header); | |
| for (var i = 2; i < trlist.length; i++) { | |
| var td = trlist.eq(i).children('td'); | |
| var alog = []; | |
| var ids = td[1].innerHTML.match(/\/user\/\?user_id\=(\d+).*\">(.+)<\/a>/); | |
| var uid = parseInt(ids[1], 10); | |
| for (var j = 0; j < l_col; j++) { | |
| var num = td.eq(j).text().replace(/[ \t\r\n\s]/g, ""); | |
| alog.push(num); | |
| } | |
| alog.splice(1, 0, uid); | |
| var alog_line=""; | |
| for (var m = 0; m < alog.length; m++) { | |
| alog_line += alog[m]; | |
| alog_line += "\t" | |
| } | |
| summary.push(alog_line); | |
| } | |
| var result_line = ""; | |
| for (var k = 0; k < summary.length; k++, result_line += "\r\n") { | |
| result_line += summary[k]; | |
| } | |
| j$("#grt_result_tsv").val(result_line); | |
| } else { | |
| var l_kind=""; | |
| if (location.href.indexOf("m=") > 0 ){ | |
| if (location.href.indexOf("m=attack_score") > 0){l_kind="&m=attack_score";} | |
| else if (location.href.indexOf("m=defense_score") > 0){l_kind="&m=defense_score";} | |
| else if (location.href.indexOf("m=destroy_score") > 0){l_kind="&m=destroy_score";} | |
| else if (location.href.indexOf("m=population") > 0){l_kind="&m=population";} | |
| else if (location.href.indexOf("m=attack") > 0){l_kind="&m=attack";} | |
| else if (location.href.indexOf("m=defense") > 0){l_kind="&m=defense";} | |
| else if (location.href.indexOf("m=destroy") > 0){l_kind="&m=destroy";} | |
| else if (location.href.indexOf("m=expedition") > 0){l_kind="&m=expedition";} | |
| else if (location.href.indexOf("m=contribution") > 0) {l_kind="&m=contribution";} | |
| else if (location.href.indexOf("m=duel") > 0) {l_kind="&m=duel";} | |
| else if (location.href.indexOf("m=npc_assault") > 0) {l_kind="&m=npc_assault";} | |
| } | |
| var wait = false; | |
| var result=l_header+"\r\n"; | |
| var count = 1; | |
| var max = m_urllist.length; | |
| var l_page = 1; | |
| max = parseInt(i_endpage) - parseInt(i_startpage) + 1; | |
| var timer2 = setInterval(function() { | |
| if (j$("#grt_result_box").css('display') == 'none') { | |
| clearInterval(timer2); | |
| return; | |
| } | |
| if (wait) { | |
| return; | |
| } | |
| wait = true; | |
| l_page = parseInt(i_startpage) + count - 1; | |
| j$("#grt_list_title").text("ページ読み込み中・・・(" + count + "/" + max + ")"); | |
| var l_url = PROTOCOL + "//" + location.hostname + "/user/ranking.php?p=" + String(l_page) + l_kind ; | |
| var summary = []; | |
| console.log(l_url); | |
| j$.ajax({ | |
| url: l_url, | |
| type: 'GET', | |
| datatype: 'html', | |
| cache: false | |
| }).done(function(res){ | |
| // 取得ページのランキングを取得 | |
| var trlist = j$(res).find("#grayWrapper table[summary='ランキング'] tbody tr"); | |
| var summary = []; | |
| for (var i = 2; i < trlist.length; i++) { | |
| var td = trlist.eq(i).children('td'); | |
| var alog = []; | |
| var ids = td[1].innerHTML.match(/\/user\/\?user_id\=(\d+).*\">(.+)<\/a>/); | |
| var uid = parseInt(ids[1], 10); | |
| for (var j = 0; j < l_col; j++) { | |
| var num = td.eq(j).text().replace(/[ \t\r\n\s]/g, ""); | |
| alog.push(num); | |
| } | |
| alog.splice(1, 0, uid); | |
| var alog_line=""; | |
| for (var m = 0; m < alog.length; m++) { | |
| alog_line += alog[m]; | |
| alog_line += "\t" | |
| } | |
| summary.push(alog_line); | |
| } | |
| var result_line = ""; | |
| for (var k = 0; k < summary.length; k++, result_line += "\r\n") { | |
| result_line += summary[k]; | |
| } | |
| result += result_line; | |
| j$("#grt_result_tsv").val(result); | |
| count++; | |
| if (count > max) { | |
| clearInterval(timer2); | |
| } | |
| wait = false; | |
| }); | |
| }, 200);} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment