Created
June 14, 2014 13:51
-
-
Save mikecat/5dca84d2c06d6d6fe8d5 to your computer and use it in GitHub Desktop.
【Greasemonkey】CodeIQ デスマコロシアムの集計リストを最短のペナルティの昇順でソートするユーザースクリプト
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
// ==UserScript== | |
// @name デスマコロシアムの集計を最短でソート | |
// @description デスマコロシアムの集計リストを最短のペナルティの昇順でソートします。 | |
// @include http://d.hatena.ne.jp/tbpg/* | |
// @version 1.0.0 | |
// @grant none | |
// ==/UserScript== | |
// タイトルでデスマコロシアムの集計記事っぽいか判定する | |
if(document.title.indexOf("デスマコロシアム")>=0 && | |
document.title.indexOf("集計報告")>=0) { | |
var tables = document.getElementsByTagName("table"); | |
var count=0; | |
for(var i=0;i<tables.length;i++) { | |
var data=tables[i].innerHTML; | |
// 言語ごとの情報が書かれてる所っぽいかを調べる | |
if(data.match(/<th> *言語名 *<\/th> *<th> *人数 *<\/th>/)) { | |
// 各言語の情報を取得する | |
var data_arr=data.split("<tr>"); | |
var data_arr2=new Array(); | |
var score_arr=new Array(); | |
for(var j=2;j<data_arr.length;j++) { | |
data_arr2.push(data_arr[j]); | |
var score_tmp=data_arr[j].split(/<\/td> *<td>/); | |
if(score_tmp.length>3) { | |
score_arr.push(~~(score_tmp[3].replace(/[^0-9]/g,""))); | |
} else { | |
score_arr.push(0); | |
} | |
} | |
// ソートを行う(バブルソート) | |
for(var j=data_arr2.length-1;j>0;j--) { | |
for(var k=0;k<j;k++) { | |
if(score_arr[k]>score_arr[k+1]) { | |
var temp; | |
temp=data_arr2[k]; | |
data_arr2[k]=data_arr2[k+1]; | |
data_arr2[k+1]=temp; | |
temp=score_arr[k]; | |
score_arr[k]=score_arr[k+1]; | |
score_arr[k+1]=temp; | |
} | |
} | |
} | |
// ソートの結果を反映させる | |
var sorted_html="<tr><th>順位</th>"+data_arr[1]; | |
for(var j=0;j<data_arr2.length;j++) { | |
sorted_html+="<tr><td>"+(j+1)+"</td>"+data_arr2[j]; | |
} | |
tables[i].innerHTML=sorted_html; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment