function getfunc(myData){ $("html").callbk(myData); } $(document).ready(function(){ /////////////////// // property /////////////////// var bushos = ['劉備', '張飛', '関羽', '趙雲', '黄忠', '馬超', '諸葛亮', '法正', '曹操', '荀彧']; var connects = ['は', 'が', 'の', 'も', 'に', 'と']; /*, '達', '軍', '様'*/ var fortunewords = ['すごい','友達','小判','愛らしい']; var d; var sexes; var nMax0 = bushos.length - 1; var nMax1 = connects.length - 1; var nMax2 = fortunewords.length -1; var nMin = 0; var timers =[]; var nums = []; var stopCount = 0; var src = "http://fl.hokubatsu.com/list/fortuneword_json.json?callback=?"; /////////////////// // routin /////////////////// $('#stop0').click(function() { stopSlot(0); }); $('#stop1').click(function() { stopSlot(1); }); $('#stop2').click(function() { stopSlot(2); }); $('#reload').click(function(){ stopSlotAll(); startSlot(); reload.disabled = true; }); $.getJSON(src,function(data) {}); /////////////////// // method /////////////////// // grobalmethod jQuery.fn.callbk = function(myData){ d = myData; bushos = d["bushos"]["name"]; sexes = d["bushos"]["sex"]; fortunewords = d['fortunewords']; nMax0 = bushos.length - 1; nMax1 = connects.length - 1; nMax2 = fortunewords.length -1; startSlot(); reload.disabled = true; } function startSlot() { $("#gourl").remove(); timers =[]; nums = []; stopCount = 0; runLine(0); runLine(1); runLine(2); } function runLine(n) { nMax = eval('nMax'+n); var nRandomInt = Math.floor(Math.random()*(nMax-nMin+1))+nMin; if(n==0) $('#num' + n).html(bushos[nRandomInt]); if(n==1) $('#num' + n).html(connects[nRandomInt]); if(n==2) $('#num' + n).html(fortunewords[nRandomInt]); timers[n] = setTimeout(function(){ runLine(n); }, 50); } function stopSlot(n) { if (typeof nums[n] !== 'undefined') return; clearTimeout(timers[n]); nums[n] = $('#num' + n).html(); stopCount++; if (stopCount == 3){ checkSlot(); reload.disabled = false; } } function checkSlot() { var a = $('#num0').html(); var b = $('#num1').html(); var c = $('#num2').html(); var sss = "m"; for(var i=0; i結果').appendTo("body"); $('  結果').appendTo(".fr"); } function stopSlotAll() { for(var i=0; i<3; i++) { if (typeof nums[i] !== 'undefined') return; clearTimeout(timers[i]); } nums[n] = $('#num' + n).html(); stopCount=3; reload.disabled = false; } });