(function(w,d){'use strict';var DEFAULT_PERIOD_MONTH=1,period_month,max_date=new Date,max_date_string;max_date.setDate(max_date.getDate()-1);max_date_string=prompt('基準日(YYYY/MM/DD・デフォルト:昨日)',max_date.getFullYear()+'/'+(max_date.getMonth()+1)+'/'+max_date.getDate());if(max_date_string===null){return}max_date_string=max_date_string.replace(/^\s*|\s*$/g,'').replace(/[0-9-/]/g,(function(s){return String.fromCharCode(s.charCodeAt(0)-65248)})).replace(/-/g,'/');if(max_date_string.match(/^\d{4}\/\d{1,2}\/\d{1,2}$/)){try{max_date=new Date(max_date_string)}catch(e){max_date=new Date}}else{max_date=new Date}max_date_string=max_date.getFullYear()+'/'+(max_date.getMonth()+1)+'/'+max_date.getDate();period_month=prompt('収集期間: n(ヶ月) (※基準日('+max_date_string+')から、nヶ月前までの測定データが対象)',DEFAULT_PERIOD_MONTH);if(period_month===null){return}period_month=parseInt(period_month,10);if(period_month<=0){period_month=DEFAULT_PERIOD_MONTH}function collect_data(){if(!w.jQuery){setTimeout(collect_data,100);return}var $=w.jQuery;function change_speed_to_Mbps(speed){if(!$.trim(speed).match(/([\d.]+)\s*(\w?)bps/i)){return speed}var value=RegExp.$1,unit=RegExp.$2;switch(unit.toUpperCase()){case'K':value/=1e3;break;case'M':break;case'G':value*=1e3;break;case'T':value*=1e6;break;default:value/=1e6;break}return value}function get_filter_info(body){var searchform=body.find('form#searchformid'),option_text_list=[];searchform.find('select').each((function(){var select=$(this),value=select.val();select.find('option[value='+value+']').each((function(){var option=$(this),text=option.text().replace(/[─│┌┐┘└├┬┤┴┼]/g,'');option_text_list.push(text)}))}));var zipcode='';searchform.find('input').each((function(){var input=$(this),type=input.attr('type'),name=input.attr('name'),value=input.val();switch(type){case'checkbox':option_text_list.push(value+'='+(input.prop('checked')?'ON':'OFF'));break;case'text':if(name=='zipcode1'){zipcode+=value}else if(name=='zipcode2'){zipcode+='-'+value;option_text_list.push(zipcode)}break}}));return option_text_list.join('・')}function get_date_string(date){return date.getFullYear()+'/'+(parseInt(date.getMonth(),10)+1)+'/'+date.getDate()}function get_time_string(date){return date.getHours()+':'+date.getMinutes()}function get_date(speed_data){if(!speed_data.match(/(\d{4})\/(\d{1,2})\/(\d{1,2})[\s()a-zA-Z]+(\d{1,2}):(\d{1,2})/)){return null}return new Date(RegExp.$1,RegExp.$2-1,RegExp.$3,RegExp.$4,RegExp.$5)}function get_any_value(data,title,terminator){if(!data.match(title+'\\s*[::]\\s*(.*?)'+terminator)){return''}return $.trim(RegExp.$1)}function get_server(speed_data){return get_any_value(speed_data,'測定サーバー','\\*詳細情報\\*')}function get_service_type(speed_data2){return get_any_value(speed_data2,'使用回線','\\n')}function get_isp(speed_data2){return get_any_value(speed_data2,'プロバイダ','\\n')}function get_area(speed_data2){return get_any_value(speed_data2,'測定地','\\n')}function get_speed_info(table){var topic_id=$.trim(table.find('a[href *= "openresult.cgi?topic"]').first().text()),NA='',downlink_speed=NA,uplink_speed=NA,speed_list=[],speed_data=table.find('div.speeddata').first().text(),speed_data2=table.find('div.speeddata2').first().text();table.find('span.graphmarker').each((function(){speed_list.push(change_speed_to_Mbps($(this).text()))}));if(table.find('nobr:contains(下り)').size()<1){speed_list.unshift(NA)}if(table.find('nobr:contains(上り)').size()<1){speed_list.push(NA)}if(2<=speed_list.length){downlink_speed=speed_list[0];uplink_speed=speed_list[1]}return{topic_id:topic_id,date:get_date(speed_data),server:get_server(speed_data),service_type:get_service_type(speed_data2),isp:get_isp(speed_data2),area:get_area(speed_data2),downlink_speed:downlink_speed,uplink_speed:uplink_speed}}var get_page_info=function(){var next_url_dict={},topic_id_dict={};return function(page_root,since_date,until_date){var speed_info_list=[],next_url=null,first_date=new Date;page_root.find('table.graphscale').each((function(){var table=$(this).parents('table').eq(1),speed_info=get_speed_info(table),target_date=speed_info.date,topic_id=speed_info.topic_id;if(!speed_info.date){console.log('日付不正: '+topic_id);return}if(topic_id_dict[topic_id]){console.log('topic_id重複: '+topic_id);return}topic_id_dict[topic_id]=true;if(target_date