Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add link to douban page

  • Loading branch information...
commit 6cc2c1f1cdbdd59931db6222e21a166211139586 2 parents ccd514b + 2adc2a4
@rnons authored
View
2  .gitignore
@@ -1,2 +1,4 @@
*.*~
*~
+*swp
+*oex
View
BIN  .notification.html.swp
Binary file not shown
View
7 background.html
@@ -1,11 +1,8 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 5.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
- <title> New Document </title>
- <meta name="Generator" content="EditPlus">
- <meta name="Author" content="">
- <meta name="Keywords" content="">
- <meta name="Description" content="">
+ <title>豆瓣电台</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="lib/jquery.min.js"></script>
<script type="text/javascript">
View
18 css/popup.css
@@ -1,23 +1,25 @@
body{margin:0}
-#main{width:280px;padding:7px 4px 7px 4px;height:95px;overflow:hidden;}
+span{font-family: 微软雅黑;}
+a:hover{opacity:0.8}
+#main{width:280px;padding:7px 4px 7px 4px;height:105px;overflow:hidden;}
#power {float:right;width:20px;margin-top:8px;clear:both}
#power:hover{opacity:0.7}
-#song_title {white-space:nowrap;font-size:10px;color:#3B5343;display:inline-block;overflow:hidden;width:238px}
-#song_artist {white-space:nowrap;font-size:15px;color:#3B5343;font-weight:bold;display:inline-block;overflow:hidden;width:238px}
-#display{margin-top:5px;width:240px;height:20px}
+#song_title a{white-space:nowrap;font-size:12px;color:#3B5343;display:inline-block;overflow:hidden;width:238px;line-height:15px;margin-bottom:1px;text-decoration:none}
+#song_artist {white-space:nowrap;font-size:15px;color:#3B5343;font-weight:bold;display:inline-block;overflow:hidden;width:238px;line-height:15px}
+#display{margin-top:5px;width:240px;}
#loaded{height:3px;background-color:#E9F4E9;width:240px;opacity:0.8;margin-top:2px}
#played{height:3px;background-color:#3B5343;width:0px;opacity:0.8}
-#timer{margin-top:3px;font-size:10px;color:#777;float:right;display:block;vertical-align:middle;}
+#timer{margin-top:3px;font-size:10px;color:#777;float:right;display:block;vertical-align:middle;line-height:13px}
#switcher{width:20px;float:right;margin-top:4px;clear:both}
#switcher:hover{opacity:0.7}
-#wrapper{padding-top: 30px;}
+#wrapper{height:40px;margin-top:20px;width:280px}
#pause {float:right;width:20px;height:18px;clear:both}
#pause:hover{opacity:0.7}
#operation{width:120px;float:left}
.button {margin-right:7px;cursor:pointer;width:20px;height:20px}
.button:hover{opacity:0.7}
#share{float:right;padding-top:5px}
-#share img{width:16px;height:16px;opacity:0.4;margin-left:3px;float:right;}
+#share img{width:16px;height:16px;opacity:0.4;margin-left:3px;float:right}
#share img:hover{opacity:1.0}
.clear{clear:both}
#channel_popup{background-color:#fff;height:100%;width:100%;overflow-y:scroll;position:absolute;z-index:999;left:0;top:0;padding:0px;opacity:0.95;display:none}
@@ -28,7 +30,7 @@ body{margin:0}
#close_c{position:fixed;right:15px;top:5px;width:15px;opacity:0.5}
#close_c:hover{opacity:1.0}
#comment_popup{margin-bottom:5px}
-#comment_input{width:100%;height:60px;border-radius:5px;border-color:#3B5343}
+#comment_input{width:100%;height:70px;border-radius:5px;border-color:#3B5343;color:#888;font-size:15px}
#comment_commit{float:right;border-radius:5px;width:75px;height:23px;border:none;margin-top:4px;color:#3B5343;background: -webkit-gradient(
linear,
left bottom,
View
6 manifest.json
@@ -1,7 +1,7 @@
{
- "name": "doubanFMExt",
- "version": "1.0",
- "description": "Douban Radio Extension",
+ "name": "豆瓣电台Chrome版",
+ "version": "0.9.1",
+ "description": "豆瓣电台Chrome版,提供分享歌曲到微博功能",
"icons":{
"128": "img/icon_128.png"
},
View
61 notification.html
@@ -1,48 +1,29 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<!-- Not Valid XHTML 1.1 ! -->
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<html>
<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="lib/jquery.min.js"></script>
- <script type="text/javascript" src="lib/jquery.base64.js"></script>
- <script type="text/javascript" src="lib/jquery-jtemplates.js"></script>
- <script type="text/javascript">
- </script>
- <style type="text/css">
- .jTemplatesTest {
- background: #DDD;
- width: 250px;
- }
- .jTemplatesTest * {
- padding: 4px;
- margin: 2px auto;
- }
- .jTemplatesTest td,tr {
- background: #EEE;
- border: 1px solid black;
- }
- </style>
+ <style type="text/css">
+ #main{margin:2px;width:220px}
+ #title {white-space:nowrap;font-size:10px;color:#3B5343;display:inline-block;overflow:hidden;width:208px;margin-left:2px}
+ #artist {white-space:nowrap;font-size:15px;color:#3B5343;font-weight:bold;display:inline-block;overflow:hidden;width:208px}
+ </style>
</head>
<body>
- <!-- Template content -->
- <textarea id="template" style="display:none">
- <strong>{$T.title}-{$T.artist}</strong>
- </textarea>
- <!-- Output elements -->
- <div id="result1" class="jTemplatesTest"></div>
- <script type="text/javascript">
- var radio=chrome.extension.getBackgroundPage().radio;
- var showSong=function(){
- var data=radio.getSong();
- // attach the template
- $("#result1").setTemplateElement("template");
- // process the template
- $("#result1").processTemplate(data);
- }
- showSong();
- setTimeout("window.close()",1000)
- </script>
+ <div id="main">
+ <span id="artist">豆瓣电台</span>
+ <span id="title">--</span>
+ </div>
+ <script type="text/javascript">
+ setTimeout(function(){
+ window.close()
+ },2000)
+ var radio=chrome.extension.getBackgroundPage().radio;
+ var song=radio.c_song
+ $("#artist").text(song.artist)
+ $("#title").text(song.title)
+ </script>
+
</body>
</html>
View
6 options.html
@@ -63,7 +63,11 @@
}
}
})
- localStorage["users"]=newUsers
+ if(newUsers){
+ localStorage["users"]=newUsers
+ }else{
+ localStorage.removeItem("users")
+ }
if(localStorage[key]){
$(value).show()
$("#"+key).hide()
View
1  popup.html
@@ -48,6 +48,7 @@
<div class="clear"></div>
</div>
<span id="timer">0:00/0:00</span>
+ <div class="clear"></div>
</div>
<div id="wrapper">
<div id="operation">
View
598 scripts/player.js
@@ -1,281 +1,317 @@
-//var radio=chrome.extension.getBackgroundPage().radio;
-var radio=opera.extension.bgProcess.radio
-console.log(radio.channel);
-
-function showSong(){
- var data=radio.c_song;
- if(data&&data.like==1){
- $("#like").attr("src","img/rated.png")
- }else{
- $("#like").attr("src","img/unrated.png")
- }
- if(radio.power==true){
- $("#power").attr("src","img/off.png")
- $("#pause").show()
- }else{
- $("#power").attr("src","img/on.png")
- $("#pause").hide()
- }
- if(data.title){
- $("#song_title").html(data.title)
- $("#song_title").attr("title",data.title)
- $("#song_artist").html(data.artist)
- $("#song_artist").attr("title",data.artist)
- }
-};
-
-$("#skip").bind("click",function(){
- radio.skip();
- showSong();
- return false;
-});
-
-$("#power").bind("click",function(){
- if(radio.power===false){
- radio.powerOn();
- $(this).attr("src","img/off.png")
- $("#pause").show()
- showSong();
- }else{
- radio.powerOff();
- $(this).attr("src","img/on.png")
- $("#pause").hide()
- $("#song_title").html("豆瓣电台")
- $("#song_title").attr("title","豆瓣电台")
- }
- return false;
-});
-
-$("#like").bind("click",function(){
- if(radio.c_song.like==0){
- radio.like();
- $("#like").attr("src","img/rated.png");
- radio.c_song.like=1;
- }else{
- radio.unlike();
- $("#like").attr("src","img/unrated.png");
- radio.c_song.like=0;
- }
- return false;
-});
-
-$("#delete").bind("click",function(){
- radio.del();
- showSong()
- return false;
-});
-
-$("#comment_commit").bind("click",function(){
- var nodes=$(".comment_button")
- content=$("#comment_input").val()
- $.each(nodes,function(index,value){
- var isSelected=$(value).attr("selected")
- if(isSelected=="true"){
- doComment($(value).attr("id"),content)
- }
- })
-});
-
-$("#range")[0].addEventListener("input",function(){
- var d=$(this).val()
- var len=$(this).val()/100*50
- $("#volume_bar").css("width",len+"px")
- //var a=radio.audio.volume=$(this).val()/100
- radio.jaudio.jPlayer("volume",$(this).val()/100)
-})
-
-$("#volume img").toggle(function(){
- $("#range").show()
- $("#volume_bar").show()
-},function(){
- $("#range").hide()
- $("#volume_bar").hide()
-})
-
-
-function doComment(id,content){
-
- var s=localStorage[id]
- var ts=s.split(",")
-
- if(id=="fanfou"){
- sendApiRequest({
- url:"http://api.fanfou.com/statuses/update.json",
- method:"POST",
- content:{status:content},
- consumer_key:"327fe47f56d57ead9539c3498772fc3d",
- consumer_secret:"688edd10e5a2c923cf9421a644240e70",
- access_token:ts[0],
- access_secret:ts[1],
- onSuccess:function(data){
- console.log(data)
- $("#comment_popup").slideUp("slow",function(){
- $("#notify").fadeIn("slow").fadeOut("slow")
- })
- }
- })
- }
-
- if(id=="douban"){
- var request_body = "<entry xmlns:ns0=\"http://www.w3.org/2005/Atom\" xmlns:db=\"http://www.douban.com/xmlns/\">";
- request_body += "<content>"+content+"</content>";
- request_body += "</entry>";
- sendApiRequest({
- url:"http://api.douban.com/miniblog/saying",
- method:"POST",
- content:request_body,
- consumer_key:"0458f5fa0cd49e2a0d0ae1ee267dda7e",
- consumer_secret:"8670104fb9f59f9d",
- access_token:ts[0],
- access_secret:ts[1],
- contentType:"application/atom+xml;charset=utf-8",
- onSuccess:function(data){
- console.log(data)
- $("#comment_popup").slideUp("slow",function(){
- $("#notify").fadeIn("slow").fadeOut("slow")
- })
- }
- })
- }
-}
-
-$("#comment_close").bind("click",function(){
- $("#comment_popup").slideUp()
-})
-
-$(".comment_button").bind("click",function(){
- var isSelected=$(this).attr("selected")
- if(isSelected=="true"){
- $(this).attr("selected","false")
- $(this).css("opacity","0.4")
- }else{
- $(this).attr("selected","true")
- $(this).css("opacity","1.0")
- }
-})
-
-$("#share img").bind("click",function(){
- $("#comment_popup").slideDown("slow")
- var c= $(this).attr("class")
- $("#"+c).css("opacity","1.0")
- .attr("selected","true")
- var content=$("#song_title").attr("title")
- content="#豆瓣电台# "+content
- console.log(content)
- $("#comment_input").val(content)
-})
-
-$("#switcher").bind("click",function(){
- $("#channel_popup").fadeIn("slow")
- var sc=localStorage["channel"]?localStorage["channel"]:"0"
- var c=$("#"+sc)
- $("#"+sc).addClass("channel_selected")
- .siblings().removeClass("channel_selected")
-})
-
-$("#channels li").bind("click",function(){
- var sc=$(this).attr("id")
- localStorage["channel"]=sc
- radio.channel=sc
- $(this).addClass("channel_selected")
- .siblings().removeClass("channel_selected")
- $("#channel_popup").fadeOut("slow")
- if(radio.power==true){
- radio.powerOn();
- showSong();
- }
-})
-
-$("#close_c").bind("click",function(){
- $("#channel_popup").fadeOut("slow")
-})
-
-
-$("#pause").bind("click",function(){
- //radio.audio.pause()
- radio.jaudio.jPlayer("pause")
- $("#mask").show()
-})
-
-$("#mask").bind("click",function(){
- //radio.audio.play()
- radio.jaudio.jPlayer("play")
- $("#mask").hide()
-})
-
-/*var audio=radio.audio
-audio.addEventListener("ended",function(){
- showSong()
-})
-
-audio.addEventListener("timeupdate",function(){
- var t=(this.currentTime/this.duration)*230
- $("#played").css("width",t+"px")
- var min=0
- var second=0
- var current=this.currentTime
- min=parseInt(current/60)
- second=parseInt(current%60)
- if(second<10){
- second="0"+second
- }
- var c=min+":"+second
- min=0
- second=0
- total=this.duration
- min=parseInt(total/60)
- second=parseInt(total%60)
- if(second<10){
- second="0"+second
- }
- var t=min+":"+second
- $("#timer").text(c+"/"+t)
-
-})
-
-audio.addEventListener("play",function(){
-})*/
-radio.jaudio.unbind(".douRadio")
-radio.jaudio.bind($.jPlayer.event.timeupdate+'.douRadio', function(event){
- //var t=(this.currentTime/this.duration)*230
- var current=radio.jaudio.data("jPlayer").status.currentTime
- var total=radio.jaudio.data("jPlayer").status.duration
- var t=(current/total)*230
- $("#played").css("width",t+"px")
- var min=0
- var second=0
- //var current=this.currentTime
- min=parseInt(current/60)
- second=parseInt(current%60)
- if(second<10){
- second="0"+second
- }
- var c=min+":"+second
- min=0
- second=0
- //total=this.duration
- min=parseInt(total/60)
- second=parseInt(total%60)
- if(second<10){
- second="0"+second
- }
- var t=min+":"+second
- $("#timer").text(c+"/"+t)
-})
-
-var shares=localStorage["users"]
-if(shares){
- $.each(shares.split(","),function(index,value){
- $("."+value.split("|")[2]).show()
- $("#"+value.split("|")[2]).show()
- })
-}
-
-if(radio.power){
- showSong();
- //if(radio.audio.paused){
- if(radio.jaudio.data("jPlayer").status.paused){
- $("#mask").show()
- }
-}
-
+//var radio=chrome.extension.getBackgroundPage().radio;
+var radio=opera.extension.bgProcess.radio
+console.log(radio.channel);
+
+function showSong(){
+ var data=radio.c_song;
+ var page="http://music.douban.com"+data.album
+ if(data&&data.like==1){
+ $("#like").attr("src","img/rated.png")
+ }else{
+ $("#like").attr("src","img/unrated.png")
+ }
+ if(radio.power==true){
+ $("#power").attr("src","img/off.png")
+ $("#pause").show()
+ }else{
+ $("#power").attr("src","img/on.png")
+ $("#pause").hide()
+ }
+ if(data.title){
+ $("#song_title").html("<a href='"+page+"'>"+data.title+"</a>")
+ $("#song_title").attr("title",data.title)
+ //$("#song_title").attr("href",page)
+ $("#song_artist").html(data.artist)
+ $("#song_artist").attr("title",data.artist)
+ $("#song_artist").attr("href",page)
+ }
+};
+
+$("#skip").bind("click",function(){
+ if(!radio.power){
+ return false;
+ }
+ radio.skip();
+ showSong();
+ return false;
+});
+
+$("#power").bind("click",function(){
+ if(radio.power===false){
+ radio.powerOn();
+ $(this).attr("src","img/off.png")
+ $("#pause").show()
+ showSong();
+ }else{
+ radio.powerOff();
+ $(this).attr("src","img/on.png")
+ $("#pause").hide()
+ $("#song_title").html("--")
+ $("#song_title").attr("title","")
+ $("#song_artist").html("豆瓣电台")
+ $("#song_artist").attr("title","豆瓣电台")
+ }
+ return false;
+});
+
+$("#like").bind("click",function(){
+ if(!radio.power){
+ return false;
+ }
+ if(radio.c_song.like==0){
+ radio.like();
+ $("#like").attr("src","img/rated.png");
+ radio.c_song.like=1;
+ }else{
+ radio.unlike();
+ $("#like").attr("src","img/unrated.png");
+ radio.c_song.like=0;
+ }
+ return false;
+});
+
+$("#delete").bind("click",function(){
+ if(!radio.power){
+ return false;
+ }
+ radio.del();
+ showSong()
+ return false;
+});
+
+$("#comment_commit").bind("click",function(){
+ var nodes=$(".comment_button")
+ content=$("#comment_input").val()
+ $.each(nodes,function(index,value){
+ var isSelected=$(value).attr("selected")
+ if(isSelected=="true"){
+ doComment($(value).attr("id"),content)
+ }
+ })
+});
+
+$("#range")[0].addEventListener("input",function(){
+ var d=$(this).val()
+ var len=$(this).val()/100*50
+ $("#volume_bar").css("width",len+"px")
+ //var a=radio.audio.volume=$(this).val()/100
+ radio.jaudio.jPlayer("volume",$(this).val()/100)
+ localStorage["volume"]=$(this).val()/100
+})
+
+$("#volume img").toggle(function(){
+ $("#range").show()
+ $("#volume_bar").show()
+},function(){
+ $("#range").hide()
+ $("#volume_bar").hide()
+})
+
+
+function doComment(id,content){
+
+ var s=localStorage[id]
+ var ts=s.split(",")
+
+ if(id=="fanfou"){
+ sendApiRequest({
+ url:"http://api.fanfou.com/statuses/update.json",
+ method:"POST",
+ content:{status:content},
+ consumer_key:"327fe47f56d57ead9539c3498772fc3d",
+ consumer_secret:"688edd10e5a2c923cf9421a644240e70",
+ access_token:ts[0],
+ access_secret:ts[1],
+ onSuccess:function(data){
+ console.log(data)
+ $("#comment_popup").slideUp("slow",function(){
+ $("#notify").fadeIn("slow").fadeOut("slow")
+ })
+ }
+ })
+ }
+
+ if(id=="douban"){
+ var request_body = "<entry xmlns:ns0=\"http://www.w3.org/2005/Atom\" xmlns:db=\"http://www.douban.com/xmlns/\">";
+ request_body += "<content>"+content+"</content>";
+ request_body += "</entry>";
+ sendApiRequest({
+ url:"http://api.douban.com/miniblog/saying",
+ method:"POST",
+ content:request_body,
+ consumer_key:"0458f5fa0cd49e2a0d0ae1ee267dda7e",
+ consumer_secret:"8670104fb9f59f9d",
+ access_token:ts[0],
+ access_secret:ts[1],
+ contentType:"application/atom+xml;charset=utf-8",
+ onSuccess:function(data){
+ console.log(data)
+ $("#comment_popup").slideUp("slow",function(){
+ $("#notify").fadeIn("slow").fadeOut("slow")
+ })
+ }
+ })
+ }
+}
+
+$("#comment_close").bind("click",function(){
+ $("#comment_popup").slideUp()
+})
+
+$(".comment_button").bind("click",function(){
+ var isSelected=$(this).attr("selected")
+ if(isSelected=="true"){
+ $(this).attr("selected","false")
+ $(this).css("opacity","0.4")
+ }else{
+ $(this).attr("selected","true")
+ $(this).css("opacity","1.0")
+ }
+})
+
+$("#share img").bind("click",function(){
+ $("#comment_popup").slideDown("slow")
+ var c= $(this).attr("class")
+ $("#"+c).css("opacity","1.0")
+ .attr("selected","true")
+ var content=$("#song_artist").attr("title")+"--"+$("#song_title").attr("title")
+ content="#豆瓣电台# "+content
+ console.log(content)
+ $("#comment_input").val(content)
+})
+
+$("#switcher").bind("click",function(){
+ $("#channel_popup").fadeIn("slow")
+ var sc=localStorage["channel"]?localStorage["channel"]:"0"
+ var c=$("#"+sc)
+ $("#"+sc).addClass("channel_selected")
+ .siblings().removeClass("channel_selected")
+})
+
+$("#channels li").bind("click",function(){
+ var sc=$(this).attr("id")
+ localStorage["channel"]=sc
+ radio.channel=sc
+ $(this).addClass("channel_selected")
+ .siblings().removeClass("channel_selected")
+ $("#channel_popup").fadeOut("slow")
+ if(radio.power==true){
+ radio.powerOn();
+ showSong();
+ }
+})
+
+$("#close_c").bind("click",function(){
+ $("#channel_popup").fadeOut("slow")
+})
+
+
+$("#pause").bind("click",function(){
+ //radio.audio.pause()
+ radio.jaudio.jPlayer("pause")
+ if(!radio.power){
+ return false;
+ }
+ $("#mask").show()
+})
+
+$("#mask").bind("click",function(){
+ //radio.audio.play()
+ radio.jaudio.jPlayer("play")
+ $("#mask").hide()
+})
+
+/*var audio=radio.audio
+audio.addEventListener("ended",function(){
+ showSong()
+})
+
+audio.addEventListener("timeupdate",function(){
+ var t=(this.currentTime/this.duration)*240
+ $("#played").css("width",t+"px")
+ var min=0
+ var second=0
+ var current=this.currentTime
+ min=parseInt(current/60)
+ second=parseInt(current%60)
+ if(second<10){
+ second="0"+second
+ }
+ var c=min+":"+second
+ min=0
+ second=0
+ total=this.duration
+ min=parseInt(total/60)
+ second=parseInt(total%60)
+ if(second<10){
+ second="0"+second
+ }
+ var t=min+":"+second
+ $("#timer").text(c+"/"+t)
+
+})
+
+audio.addEventListener("play",function(){
+})*/
+radio.jaudio.unbind(".douRadio")
+radio.jaudio.bind($.jPlayer.event.timeupdate+'.douRadio', function(event){
+ //var t=(this.currentTime/this.duration)*230
+ var current=radio.jaudio.data("jPlayer").status.currentTime
+ var total=radio.jaudio.data("jPlayer").status.duration
+ var t=(current/total)*240
+ $("#played").css("width",t+"px")
+ var min=0
+ var second=0
+ //var current=this.currentTime
+ min=parseInt(current/60)
+ second=parseInt(current%60)
+ if(second<10){
+ second="0"+second
+ }
+ var c=min+":"+second
+ min=0
+ second=0
+ //total=this.duration
+ min=parseInt(total/60)
+ second=parseInt(total%60)
+ if(second<10){
+ second="0"+second
+ }
+ var t=min+":"+second
+ $("#timer").text(c+"/"+t)
+})
+
+radio.jaudio.bind($.jPlayer.event.ended+'.douRadio', function(event){
+ opera.postError("ended")
+ radio.reportEnd()
+ radio.changeSong("p")
+ opera.postError(radio.c_song.title)
+ showSong()
+})
+
+
+var shares=localStorage["users"]
+if(shares){
+ $.each(shares.split(","),function(index,value){
+ $("."+value.split("|")[2]).show()
+ $("#"+value.split("|")[2]).show()
+ })
+}
+
+if(radio.power){
+ showSong();
+ //if(radio.audio.paused){
+ if(radio.jaudio.data("jPlayer").status.paused){
+ $("#mask").show()
+ }
+}
+var vol=localStorage["volume"]
+if(!vol){
+ vol=0.8
+}
+$("#range").val(vol*100)
+$("#volume_bar").css("width",vol*50+"px")
+radio.jaudio.jPlayer("volume",vol)
+//audio.volume=vol
+
+
View
282 scripts/radio.js
@@ -1,140 +1,142 @@
-/**
- * 封装radio操作
- * */
-var Radio=function(){
- this.c_song={};
- this.song_list=[];
- this.channel=0;
- this.power=false;
- this.audio=null;
- this.jaudio=null;
- this.power=false;
- this.uid='';
- this.heared='';
-}
-
-/**
- *初始化播放器
- * */
-Radio.init=function(audio){
- $.ajaxSetup({async:false})
- console.log("init radio...")
- var radio=new Radio()
- radio.audio=audio
- radio.jaudio=$("#jquery_jplayer")
- radio.channel=localStorage['channel']?localStorage['channel']:0
- $("#jquery_jplayer").bind($.jPlayer.event.ended, function(event){
- opera.postError("ended")
- radio.reportEnd()
- radio.changeSong("p")
- })
-
- //douban.fm的cookie是session级别,从豆瓣主站获取dbcl2的cookie到
- /*chrome.cookies.get({
- url:"http://douban.com",
- name:"dbcl2"
- },function(b){
- if(b){
- chrome.cookies.set({
- url:"http://douban.fm",
- name:"dbcl2",
- value:b.value
- })
- }
- })*/
- return radio
-}
-
-/**
- *获取播放列表
- * */
-Radio.prototype.getPlayList=function(t,skip){
- var self =this
- if(skip){
- this.audio.pause()
- }
- $.getJSON("http://douban.fm/j/mine/playlist",{
- type:t,
- channel:this.channel,
- h:this.heared,
- sid:this.c_song? this.c_song.sid:'',
- r:Math.random(),
- uid:this.uid,
- from:"mainsite"
- },function(data){
- var songs=data.song
- for(s in songs){
- self.song_list[s]=songs[s]
- }
- })
- if(skip){
- this.changeSong(t)
- }
-}
-
-Radio.prototype.onGetPlayList=function(data){
- console.log(this)
-}
-
-
-Radio.prototype.reportEnd=function(){
- temp=this.heared.split("|")
- temp.push(this.c_song.sid+":"+"p")
- this.heared=temp.slice(-20).join("|")
- $.get("http://douban.fm/j/mine/playlist",{
- type:'e',
- sid:this.c_song.sid,
- channel:this.channel,
- from:"mainsite"
- })
-}
-
-Radio.prototype.changeSong=function(t){
- this.c_song=this.song_list.shift();
- if(t!='n'){
- h_songs=this.heared.split("|");
- h_songs.push(this.c_song.sid+":"+t);
- this.heared=h_songs.slice(-20).join("|")
- }
- //this.audio.pause()
- console.log("get next song: "+this.c_song.sid)
- this.audio.src=this.c_song.url
- this.audio.play()
- opera.postError(this.c_song.url)
- this.jaudio.jPlayer("clearMedia")
- this.jaudio.jPlayer("setMedia", {mp3: this.c_song.url})
- this.jaudio.jPlayer("load")
- this.jaudio.jPlayer("play")
-
- if(this.song_list.length<=0){
- console.log("get new song list")
- this.getPlayList("p",false)
- }
-}
-
-Radio.prototype.skip=function(){
- this.getPlayList("s",true)
-}
-
-Radio.prototype.like=function(){
- this.getPlayList("r",false)
-}
-
-Radio.prototype.unlike=function(){
- this.getPlayList("u",false)
-}
-
-Radio.prototype.del=function(){
- this.getPlayList("b",true)
-}
-
-Radio.prototype.powerOn=function(){
- this.power=true
- this.getPlayList("n",true)
-}
-
-Radio.prototype.powerOff=function(){
- this.power=false
- //this.audio.pause()
- this.jaudio.jPlayer("pause")
-}
+/**
+ * 封装radio操作
+ * */
+var Radio=function(){
+ this.c_song={};
+ this.song_list=[];
+ this.channel=0;
+ this.power=false;
+ this.audio=null;
+ this.jaudio=null;
+ this.power=false;
+ this.uid='';
+ this.heared='';
+}
+
+/**
+ *初始化播放器
+ * */
+Radio.init=function(audio){
+ $.ajaxSetup({async:false})
+ console.log("init radio...")
+ var radio=new Radio()
+ radio.audio=audio
+ radio.jaudio=$("#jquery_jplayer")
+ radio.channel=localStorage['channel']?localStorage['channel']:0
+ /*audio.addEventListener("ended",function(){
+ radio.reportEnd()
+ radio.changeSong("p")
+ console.log("song end")
+ var notification = webkitNotifications.createHTMLNotification('notification.html');
+ notification.show();
+ })*/
+
+ //douban.fm的cookie是session级别,从豆瓣主站获取dbcl2的cookie到
+ /*chrome.cookies.get({
+ url:"http://douban.com",
+ name:"dbcl2"
+ },function(b){
+ if(b){
+ chrome.cookies.set({
+ url:"http://douban.fm",
+ name:"dbcl2",
+ value:b.value
+ })
+ }/
+ })*/
+ return radio
+}
+
+/**
+ *获取播放列表
+ * */
+Radio.prototype.getPlayList=function(t,skip){
+ var self =this
+ if(skip){
+ this.audio.pause()
+ }
+ var self=this
+ $.getJSON("http://douban.fm/j/mine/playlist",{
+ type:t,
+ channel:this.channel,
+ h:this.heared,
+ sid:this.c_song? this.c_song.sid:'',
+ r:Math.random(),
+ uid:this.uid,
+ from:"mainsite"
+ },function(data){
+ var songs=data.song
+ for(s in songs){
+ self.song_list[s]=songs[s]
+ }
+ if(skip){
+ self.changeSong(t)
+ }
+ })
+}
+
+Radio.prototype.onGetPlayList=function(data){
+ console.log(this)
+}
+
+
+Radio.prototype.reportEnd=function(){
+ temp=this.heared.split("|")
+ temp.push(this.c_song.sid+":"+"p")
+ this.heared=temp.slice(-20).join("|")
+ $.get("http://douban.fm/j/mine/playlist",{
+ type:'e',
+ sid:this.c_song.sid,
+ channel:this.channel,
+ from:"mainsite"
+ })
+}
+
+Radio.prototype.changeSong=function(t){
+ this.c_song=this.song_list.shift();
+ if(t!='n'){
+ h_songs=this.heared.split("|");
+ h_songs.push(this.c_song.sid+":"+t);
+ this.heared=h_songs.slice(-20).join("|")
+ }
+ console.log("get next song: "+this.c_song.sid)
+ this.audio.src=this.c_song.url
+ this.audio.play()
+ opera.postError(this.c_song.url)
+ this.jaudio.jPlayer("clearMedia")
+ this.jaudio.jPlayer("setMedia", {mp3: this.c_song.url})
+ this.jaudio.jPlayer("load")
+ this.jaudio.jPlayer("play")
+
+ if(this.song_list.length<=0){
+ console.log("get new song list")
+ this.getPlayList("p",false)
+ }
+}
+
+Radio.prototype.skip=function(){
+ this.getPlayList("s",true)
+}
+
+Radio.prototype.like=function(){
+ this.getPlayList("r",false)
+}
+
+Radio.prototype.unlike=function(){
+ this.getPlayList("u",false)
+}
+
+Radio.prototype.del=function(){
+ this.getPlayList("b",true)
+}
+
+Radio.prototype.powerOn=function(){
+ this.power=true
+ this.getPlayList("n",true)
+}
+
+Radio.prototype.powerOff=function(){
+ this.power=false
+ //this.audio.pause()
+ this.jaudio.jPlayer("pause")
+}
Please sign in to comment.
Something went wrong with that request. Please try again.