Skip to content

Instantly share code, notes, and snippets.

@haruair
Created June 17, 2013 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haruair/5794722 to your computer and use it in GitHub Desktop.
Save haruair/5794722 to your computer and use it in GitHub Desktop.
게임코디 주사위 결과정리 북마클릿
(function() {
var jq = document.createElement('script'); jq.type = 'text/javascript'; jq.async = false;
jq.src = '//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(jq, s);
var dice_result_gen = function(){
if(jQuery("#dice_result").length != 0) return false;
var dice_img = jQuery("img[src^=\"/dice_\"]");
var list = [];
if(dice_img.length == 0) return false;
dice_img.each(function(i){
if(i==0) return true;
var self = jQuery(this);
var num = self.parent().html().split("<br><br>")[0].split(" ");
num = num[num.length-1];
var name = jQuery.trim(self.parent().parent().find("td:first").text());
if(typeof list[num] == "undefined") list[num] = [];
list[num].push(name);
});
var table = jQuery("<table>");
for(i in list){
if( typeof list[i] != 'object'){
continue;
}
var tr = jQuery("<tr>");
var th = jQuery("<th>").text(i).appendTo(tr);
var roller = list[i].join(", ");
var td = jQuery("<td>").text(roller).appendTo(tr);
tr.appendTo(table);
}
var dice_result = jQuery("<div>").attr("id","dice_result").css({"margin-top":"10px","border-top":"1px solid #333","padding-top":"10px"}).html(" <b>주사위 결과</b>");
dice_img.eq(0).clone().prependTo(dice_result);
table.appendTo(dice_result);
dice_img.eq(0).parents("td:first").append(dice_result);
};
var jQuery_init = function(){
if(typeof jQuery == 'undefined')
{
setTimeout(jQuery_init, 100);
}
else
{
dice_result_gen();
}
};
jQuery_init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment