Skip to content

Instantly share code, notes, and snippets.

@to
Created September 27, 2010 12:42
Show Gist options
  • Save to/598959 to your computer and use it in GitHub Desktop.
Save to/598959 to your computer and use it in GitHub Desktop.
Tombloo.Service.actions.register({
name : 'BBモバイルポイントをコピーする',
type : 'context',
check : function(ctx){
return new RegExp('/bbmp.softbanktelecom.co.jp/cgi-bin/service/bbmobile_search/list_city.cgi\\?ac=').test(ctx.href);
},
execute : function(ctx){
// http://bbmp.softbanktelecom.co.jp/cgi-bin/service/bbmobile_search/list_city.cgi?ac=13
var self = this;
var area = {
name : $x('id("Main")//strong[1]').textContent.split('/').pop(),
code : parseQueryString(ctx.search).ac,
}
var cities = [];
deferredForEach($x('//a[starts-with(@href, "list.cgi")]', ctx.document, true), function(link){
var num = 1;
var city = {
code : parseQueryString(link.href).cityc,
name : link.textContent.extract(/(.*?)\(/),
spots : [],
};
log(city.name);
cities.push(city);
return (function(){
var me = arguments.callee;
return request('http://bbmp.softbanktelecom.co.jp/cgi-bin/service/bbmobile_search/list.cgi', {
queryString : {
ac : area.code,
cityc : city.code,
num : num,
}
}).addCallback(function(res){
var doc = convertToHTMLDocument(res.responseText);
$x('//table[contains(@class, "TableColor100")]//tr', doc, true).forEach(function(row){
var cols = row.getElementsByTagName('td');
if(!cols.length)
return;
var spot = {
station : cols[0].textContent.trim(),
name : cols[1].textContent.trim(),
tel : cols[2].textContent.trim(),
address : cols[3].textContent.trim(),
}
city.spots.push(spot);
});
if($x('//a[contains(text(), "次の")]', doc)){
num++;
return me();
}
});
})();
}).addCallback(function(){
var res = [];
res.push('BBモバイルポイント: ' + area.name);
res.push('-'.repeat(80));
res.push('');
cities.forEach(function(city){
res.push('■' + city.name);
city.spots.forEach(function(spot){
res.push(' ' + [spot.station || '-', spot.name, spot.tel, spot.address].join('\t'));
});
res.push('');
});
copyString(res.join('\n'));
notify(self.name, 'コピー終了', notify.ICON_INFO);
});
},
}, '----');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment