每年过年回家买火车票都是件痛苦的事情.
特为此写了一个火车票提醒的扩展.
我用此扩展及时的提醒了火车票,还是比较有用的.
比较遗憾的是,没有做配置页面.写的比较仓促,不到1个小时完成的.后续完善吧.
<script>
var tomorrow_weather; //明天天气
var tomorrow_temp; //明天温度
var req; //请求
var req2;
var req3;
function showNotify(title, content){
if(webkitNotifications){
var notification = webkitNotifications.createNotification(
'ticket.png',
title,
content
);
notification.show()
}
}
function handlewResponse(request, date){
var text = request.responseText;
var tempDiv = document.createElement("div");
tempDiv.innerHTML = text.replace(/<script(.|/s)*?//script>/g, '');
var content = tempDiv.getElementsByClassName('tblist');
var tlist = content[0].children[1].children;
var title = date + "--该死的春运";
var bshownotify = false;
for(i = 0; i < tlist.length; i++)
{
var item = tlist[i];
var update = item.getElementsByClassName('pd');
if(update.length > 0)
{
var lasttime = update[0].innerText;
if( lasttime && (lasttime.search('分钟') != -1 ||
lasttime.search('小时') != -1) )
{
ticket = "发布时间" + lasttime + "前 ";
var content = item.getElementsByClassName('t');
if(content)
{
if(content[0] && content[0].children.length > 1){
var info = content[0].children[1].innerText;
ticket += info;
bshownotify = true;
break;
}
}
}
}
}
if(bshownotify)
showNotify(title, ticket);
}
function reqWeather(){
var url = "http://bj.58.com/huochepiao/?StartStation=%E5%8C%97%E4%BA%AC&EndStation=%E9%9D%92%E5%B7%9E%E5%B8%82&StartTime=2011013000";
if(!req)
req = new XMLHttpRequest();
req.open(
"GET",
url,
false
);
req.send();
handlewResponse(req, "1月30号票有更新/n");
var url2 = "http://bj.58.com/huochepiao/?StartStation=%E5%8C%97%E4%BA%AC&EndStation=%E9%9D%92%E5%B7%9E%E5%B8%82&StartTime=2011013100";
if(!req2)
req2 = new XMLHttpRequest();
req2.open(
"GET",
url2,
false
);
req2.send();
handlewResponse(req2, "1月31号票有更新/n");
var url3 = "http://bj.58.com/huochepiao/?StartStation=%E5%8C%97%E4%BA%AC&EndStation=%E9%9D%92%E5%B7%9E%E5%B8%82&StartTime=2011020100";
if(!req3)
req3 = new XMLHttpRequest();
req3.open(
"GET",
url3,
false
);
req3.send();
handlewResponse(req3, "2月1号票有更新/n");
}
var t;
function timedCount()
{
reqWeather();
t=setTimeout("timedCount()",60000*2);
}
timedCount();
</script>
插件的下载链接 http://deppcyan.appspot.com/media/aghkZXBwY3lhbnINCxIFTWVkaWEY8asBDA/ticket.crx
为解决春运期间购票难题,作者开发了一款火车票提醒浏览器扩展。该扩展每两分钟检查指定日期从北京到青岛的列车余票情况,并通过桌面通知的形式提醒用户票务更新。
990

被折叠的 条评论
为什么被折叠?



