From 2b16649b8b653124d4fc295e957c3a19e5d47333 Mon Sep 17 00:00:00 2001 From: rnons Date: Fri, 19 Oct 2012 20:59:36 +0800 Subject: [PATCH] recent-channel-list --- css/popup.css | 6 ++++ popup.html | 4 +-- scripts/player.js | 43 +++++++++++++++++++++++++++++ scripts/popup.js | 70 +++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 108 insertions(+), 15 deletions(-) diff --git a/css/popup.css b/css/popup.css index 1b68d86..7252d60 100644 --- a/css/popup.css +++ b/css/popup.css @@ -89,4 +89,10 @@ a:hover{opacity:0.8} background: url("../img/rated.png") no-repeat right top; z-index: 9999; } + .del-recent-channel { + float: right; + height: 20px; + background: url("../img/rated.png") no-repeat right top; + z-index: 9999; + } diff --git a/popup.html b/popup.html index 3a1b6c8..6b92cc2 100644 --- a/popup.html +++ b/popup.html @@ -82,11 +82,9 @@
推荐兆赫
上升最快
-
- re +
diff --git a/scripts/player.js b/scripts/player.js index 2522617..ea6fe41 100644 --- a/scripts/player.js +++ b/scripts/player.js @@ -1,3 +1,29 @@ +// https://github.com/prettycode/Object.identical.js +Object.identical = function (a, b, sortArrays) { + function sort(object) { + + if (sortArrays === true && Array.isArray(object)) { + return object.sort(); + } + else if (typeof object !== "object" || object === null) { + return object; + } + + var result = []; + + Object.keys(object).sort().forEach(function(key) { + result.push({ + key: key, + value: sort(object[key]) + }); + }); + + return result; + } + + return JSON.stringify(sort(a)) === JSON.stringify(sort(b)); +}; + var radio = opera.extension.bgProcess.radio; console.log(radio.channel); @@ -196,6 +222,23 @@ $(".channel-box li").live("click", function () { radio.powerOn(); showSong(); } + var c = {}; + c.cid = $(this).data("cid"); + c.name = $(this).text(); + c.intro = $(this).find("a").attr("title"); + var recent_channels = []; + if (localStorage.recent_channels !== 'undefined') { + recent_channels = JSON.parse(localStorage.recent_channels); + var i=recent_channels.length + while (i--) { + if (Object.identical(recent_channels[i], c)) { + recent_channels.splice(i, 1); + } + } + } + console.log(c.name); + recent_channels.push(c); + localStorage.recent_channels = JSON.stringify(recent_channels); }) $("#close_c").bind("click", function () { diff --git a/scripts/popup.js b/scripts/popup.js index 7f42e68..3183103 100644 --- a/scripts/popup.js +++ b/scripts/popup.js @@ -8,6 +8,7 @@ for (c in intro_channels) { intro = intro_channels[c].intro; $('
  • ' + name + '
  • ').appendTo('div#ss_intros'); } + for (c in fast_channels) { //console.log(channels[c].cid, channels[c].name); cid = fast_channels[c].cid; @@ -17,16 +18,27 @@ for (c in fast_channels) { } $('