使用新浪财经7*24直播的数据

简单的做一个山寨品

在线地址:[痛苦啊,有GFW,却没有vpn,往heroku上传浪费了好多时间。。。]

http://wangxinsheng.herokuapp.com/sinaFinLive

效果图:

[模仿][JS]新浪财经7*24直播-LMLPHP

---

代码:

css:直接使用新浪的

index[代码简单,不写注释了]:

 <html>
<head>
<title>新浪财经[7*24直播]</title>
<link rel="stylesheet" href="live_fin_v1.css">
<script src='jquery-1.11.1.min.js'></script>
</head>
<body>
<style>
.bd_topic{cursor:pointer;}
</style>
<div class="wrap clearfix">
<div class="bd_weibo">
<div class="bd_tt clearfix">
<div class="bd_topics clearfix">
<span class="bd_topic bd_topic_cur" onclick='setTagAndGet(0,this);'>全部</span>
<span class="bd_topic"><a onclick='setTagAndGet(10,this);'>A股</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(1,this);'>宏观</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(2,this);'>行业</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(3,this);'>公司</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(4,this);'>数据</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(5,this);'>市场</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(6,this);'>观点</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(7,this);'>央行</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(8,this);'>其他</a></span>
</div>
<div class="bd_refresh clearfix">
<div class="refresh_ck">
<label class="autorefreshlb" for="autorefresh"><span class="autorefreshsecs">X</span><span class="autorefreshlbtxt">秒后刷新</span></label>
</div>
</div>
</div>
<div class="bd_c">
<div class="bd_c0" id="bd_c0">
<!-- data list -->
</div>
</div>
</div>
</div>
<script>
/*
// 文字转16进制
var toUnicode = function (s) {
var str = "";
for (var i = 0; i < s.length; i++) {
str +="\\u"+s.charCodeAt(i).toString(16)+"\t";
}
return str;
}
var a = '胜多负89%少'; document.write(toUnicode(a)); // \u80dc \u591a \u8d1f \u5c11
// 16进制转文字
var toStr = function (n){
var str = "";
var s = n.split('\\u');
for(var i = 0;i < s.length;i++){
str += String.fromCharCode(parseInt(s[i],16))+"\t";
}
return str;
}
var b = "\\u80dc \\u591a \\u8d1f \\u5c11\\u3002\\u8fbe";
b = "\\u53d1\\u6539\\u59d4\\u6279\\u51c6\\u5efa\\u8bbe\\u9999\\u683c\\u91cc\\u62c9\\u81f3\\u4e3d\\u6c5f\\u516c\\u8def\\uff0c\\u9879\\u76ee\\u9884\\u8ba1\\u6295\\u8d44203\\u4ebf\\u5143\\u4eba\\u6c11\\u5e01\\u3002 \\u65b0\\u6d6a\\u4e8b\\u4ef6\\u76f4\\u64ad"; document.write(toStr(b)); // 胜 多 负 少
*/
// 时间戳转日期
function getDate(tm){
var tt=new Date(parseInt(tm) * 1000);//.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
return tt;
}
// 数据取得或的callBack方法
function t14222533(data){
if(data.result.status.code==0){
if(data.result.data.length>0){
//append
for(var i = data.result.data.length-1;i >=0;i--){
var item = data.result.data[i];
var day = getDate(item.created_at);
var dayName = day.getFullYear()+"年"+((day.getMonth()+1)<10?'0'+(day.getMonth()+1):(day.getMonth()+1))+"月"+(day.getDate()<10?'0'+day.getDate():day.getDate())+"日";
var timeName = ((''+day.getHours()).length<2?('0'+day.getHours()):day.getHours())+":"+((''+day.getMinutes()).length<2?('0'+day.getMinutes()):day.getMinutes())+":"+((''+day.getSeconds()).length<2?('0'+day.getSeconds()):day.getSeconds());
var tmpStr = oneData.replace(/\{\%today\%\}/g,dayName).replace(/\{\%id\%\}/g,item.id).replace(/\{\%day\%\}/g,dayName).replace(/\{\%time\%\}/g,timeName).replace(/\{\%tag\%\}/g,'').replace(/\{\%content\%\}/g,item.content);
var display = 'none';
tmpStr = tmpStr.replace(/\{\%display\%\}/g,display);
$("#bd_c0").prepend(tmpStr); $("div[data-today='"+dayName+"']").find(".bd_date").hide();
$("div[data-today='"+dayName+"']").eq(0).find(".bd_date").show();
/* 隐藏当天日期
var toDay = new Date();
todayName=toDay.getFullYear()+"年"+((toDay.getMonth()+1)<10?'0'+(toDay.getMonth()+1):(toDay.getMonth()+1))+"月"+(toDay.getDate()<10?'0'+toDay.getDate():toDay.getDate())+"日";
$("div[data-today='"+todayName+"']").find(".bd_date").hide();
*/
id = item.id;
}
} $(".autorefreshsecs").html(maxTime);
clearTimeout(setTimeoutObj);
setTimeoutObj = setTimeout(animate,1000);
//console.log('go');
}else{
console.log(data);
}
}
/*
http://live.sina.com.cn/zt/api/f/get/finance/globalnews1/index.htm?format=json&callback=t14222547&id=114975&tag=0&pagesize=15&dire=b&dpc=1 http://live.sina.com.cn/zt/api/f/get/finance/globalnews1/index.htm?format=json&callback=t14222533&id=114986&tag=0&pagesize=45&dire=f&dpc=1 t14222533({"result":{"status":{"code":0,"msg":"\u83b7\u53d6\u6210\u529f, succ"},"pageStr":{"totalPage":1,"pageSize":45,"prePage":1,"nextPage":1,"firstPage":1,"lastPage":1,"totalNum":1,"pName":"page","page":1,"paramStr":"http:\/\/live.sina.com.cn\/zt\/api\/app_zt\/f\/get\/finance\/globalnews1\/index.htm\/?format=json&callback=t14222533&id=114986&tag=0&pagesize=45&dire=f&"},"data":[{"id":"114988","mid":"3803267903335890","sp_id":"152","uid":"3969238805","content":"\u53d1\u6539\u59d4\u6279\u51c6\u5efa\u8bbe\u9999\u683c\u91cc\u62c9\u81f3\u4e3d\u6c5f\u516c\u8def\uff0c\u9879\u76ee\u9884\u8ba1\u6295\u8d44203\u4ebf\u5143\u4eba\u6c11\u5e01\u3002","source":"<a href=\"http:\/\/app.weibo.com\/t\/feed\/6n8uPl\" rel=\"nofollow\">\u65b0\u6d6a\u4e8b\u4ef6\u76f4\u64ad<\/a>","created_at":"1422253192","original_pic":"","pic_ids":"","video":"","reposts":0,"comments":0,"attitudes":0,"pmid":"0","re_mid":"0","re_uid":"0","re_content":"","re_source":"","re_created_at":"0","re_original_pic":"","re_pic_ids":"","re_video":"","re_reposts":"0","re_comments":"0","re_attitudes":"0","is_audit":"1","is_launch":"0","is_del":"0","creator":"yongliang3","mender":"","created_time":"1422253192","modified_time":"0","notes":"","user":{"id":3969238805,"idstr":"3969238805","class":1,"screen_name":"fin_\u56fe\u6587\u76f4\u64ad","name":"fin_\u56fe\u6587\u76f4\u64ad","province":"11","city":"1000","location":"\u5317\u4eac","description":"","url":"","profile_image_url":"http:\/\/tp2.sinaimg.cn\/3969238805\/50\/5690088076\/1","profile_url":"u\/3969238805","domain":"","weihao":"","gender":"m","followers_count":1849,"friends_count":2,"pagefriends_count":0,"statuses_count":72181,"favourites_count":0,"created_at":"Wed Jan 08 15:47:33 +0800 2014","following":false,"allow_all_act_msg":false,"geo_enabled":true,"verified":false,"verified_type":-1,"remark":"","ptype":0,"allow_all_comment":true,"avatar_large":"http:\/\/tp2.sinaimg.cn\/3969238805\/180\/5690088076\/1","avatar_hd":"http:\/\/ww4.sinaimg.cn\/crop.0.0.179.179.1024\/ec95c715jw1ecc6o54vfcj2050050aad.jpg","verified_reason":"","verified_trade":"","verified_reason_url":"","verified_source":"","verified_source_url":"","follow_me":false,"online_status":0,"bi_followers_count":0,"lang":"zh-cn","star":0,"mbtype":0,"mbrank":0,"block_word":0,"block_app":0,"credit_score":80,"urank":11},"base62mid":"C1n0OdZOG","base62pmid":"","base62re_mid":"","pic_ids_plus":"","re_pic_ids_plus":"","tag":[{"tag_id":"2","tag_name":"\u884c\u4e1a"}]}]}});
*/ var oneData = '<div class="bd_list" data-today="{%today%}">'
+'<div class="bd_i bd_i_og bd_i_1st clearfix " data-id="{%id%}">'
+'<div class="bd_date" style="display:{%display%};">{%day%}<!--2015年1月1日--></div>'
+'<div class="bd_i_time clearfix">'
+'<p class="bd_i_time_c">{%time%}<!--19:32:37--></p>'
+'<p class="bd_i_tags"> {%tag%}<!--类型-->&nbsp;</p>'
+'</div>'
+'<div class="bd_i_c">'
+'<div class="bd_i_txt clearfix">'
+'<p class="bd_i_txt_c">{%content%}</p>'
+'</div>'
+'</div>'
+'</div>'; var scriptStr = "<script id=\'getData\' src=\'{%url%}\'><\/script>";
var pagesize = 10;
var tag = 0;
var urlStr = 'http://live.sina.com.cn/zt/api/f/get/finance/globalnews1/index.htm?format=json&callback=t14222533&id={%id%}&tag={%tag%}&pagesize={%pagesize%}&dire=f&dpc=1';
var id = '114765';
var orgId = '114765';
var scriptObj = null;
var maxTime = 60;
var setTimeoutObj = null;
function getData(){
$('#getData').remove();
var urlTmp = urlStr.replace(/{%id%}/g,id).replace(/{%pagesize%}/g,pagesize).replace(/{%tag%}/g,tag);
scriptObj = $((scriptStr.replace(/{%url%}/g,urlTmp)));
$('body').append(scriptObj);
//console.log(scriptObj);
}
$(function(){
var urlTmp = urlStr.replace(/{%id%}/g,id).replace(/{%pagesize%}/g,pagesize).replace(/{%tag%}/g,tag);
scriptObj = $((scriptStr.replace(/{%url%}/g,urlTmp)));
$('body').append(scriptObj);
$(".autorefreshsecs").html(maxTime);
});
function animate(){
var time = parseInt($(".autorefreshsecs").html())-1;
$(".autorefreshsecs").html(time);
//console.log(time);
if(time==0){
getData();
}else{
clearTimeout(setTimeoutObj);
setTimeoutObj = setTimeout(animate,1000);
}
};
function setTagAndGet(tag,obj){
$(".autorefreshsecs").html(maxTime);
$("#bd_c0").html('');
clearTimeout(setTimeoutObj);
$('.bd_topic_cur').removeClass('bd_topic_cur');
$(obj).addClass('bd_topic_cur');
id=orgId;
tag=tag
$('#getData').remove();
var urlTmp = urlStr.replace(/{%id%}/g,id).replace(/{%pagesize%}/g,pagesize).replace(/{%tag%}/g,tag);
scriptObj = $((scriptStr.replace(/{%url%}/g,urlTmp)));
$('body').append(scriptObj);
} </script> </body>
</html>

---

CSDN下载:

http://download.csdn.net/detail/wangxsh42/8398785

05-13 05:11