function rss_toast() { $.ajax({ url: 'https://bisan.co.jp/shop/rss8.cgi?XML=test.xml', type: 'get', dataType: 'xml', timeout: 5000, success: function(xml, status) { if (status === 'success') { var row = 0; var data = []; var nodeName; $(xml).find('item').each(function() { data[row] = {}; $(this).children().each(function() { nodeName = $(this)[0].nodeName; data[row][nodeName] = {}; attributes = $(this)[0].attributes; for (var i in attributes) { data[row][nodeName][attributes[i].name] = attributes[i].value; } data[row][nodeName]['text'] = $(this).text(); }); row++; }); var rndi = Math.round( Math.random()*20 ); $('#rss').wrapInner(''); for (i in data) { if(rndi==i){ $.toast({ text : '
  • 最近、' + data[i].title.text + 'のページが更新されました
  • ', showHideTransition : 'slide', hideAfter : 28000, bgColor : '#659931', textAlign : 'left', position : 'bottom-left', loaderBg : '#fff', allowToastClose: true }); } } } } }); } var timer; function countDown() { rss_toast(); // alert("count down"); return true; } function restartTimer() { clearTimeout(timer); timer=setTimeout('countDown()',20000); return true; } function load() { timer=setTimeout('countDown()',5000); document.body.addEventListener("mousemove", restartTimer, false); document.body.addEventListener("keypress", restartTimer, false); document.body.addEventListener("touchstart", restartTimer, false); } document.addEventListener("DOMContentLoaded", load, false);