1 if (typeof(
Cc) ==
"undefined")
2 var
Cc = Components.classes;
3 if (typeof(
Ci) ==
"undefined")
4 var
Ci = Components.interfaces;
5 if (typeof(
Cu) ==
"undefined")
6 var
Cu = Components.utils;
8 if (typeof(RADIO_ICON_SMALL) ==
"undefined")
9 var RADIO_ICON_SMALL =
"chrome://sb-lastfm/skin/icon_radio_small.png";
10 if (typeof(GLOBE_ICON) ==
"undefined")
11 var GLOBE_ICON =
"chrome://sb-lastfm/skin/homepage.png";
12 if (typeof(LASTFM_ICON) ==
"undefined")
13 var LASTFM_ICON =
"chrome://sb-lastfm/skin/as.png";
14 if (typeof(htmlns) ==
"undefined")
15 var htmlns =
"http://www.w3.org/1999/xhtml";
17 if (typeof(DISPLAY_SEARCH_LIMIT) ==
"undefined")
18 var DISPLAY_SEARCH_LIMIT = 16;
19 if (typeof(DISPLAY_RECENT_STATIONS_LIMIT) ==
"undefined")
20 var DISPLAY_RECENT_STATIONS_LIMIT = 10;
21 if (typeof(DISPLAY_RELATED_TAGS_LIMIT) ==
"undefined")
22 var DISPLAY_RELATED_TAGS_LIMIT = 6;
23 if (typeof(DISPLAY_RELATED_ARTISTS_LIMIT) ==
"undefined")
24 var DISPLAY_RELATED_ARTISTS_LIMIT = 6;
25 if (typeof(DISPLAY_TOP_FANS_LIMIT) ==
"undefined")
26 var DISPLAY_TOP_FANS_LIMIT = 6;
27 if (typeof(LIMIT_NAV_RESULTS) ==
"undefined")
28 var LIMIT_NAV_RESULTS = 10;
31 Cu.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
32 if (typeof(SBProperties) ==
"undefined")
33 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
35 if (typeof(gBrowser) ==
"undefined")
36 var gBrowser = Components.classes[
'@mozilla.org/appshell/window-mediator;1']
37 .getService(Components.interfaces.nsIWindowMediator)
38 .getMostRecentWindow(
'Songbird:Main').gBrowser;
45 this._metrics = Cc[
'@songbirdnest.com/Songbird/Metrics;1']
46 .getService(Ci.sbIMetrics);
49 LastfmTuner._strings = Cc[
"@mozilla.org/intl/stringbundle;1"]
50 .getService(Ci.nsIStringBundleService)
51 .createBundle(
"chrome://sb-lastfm/locale/overlay.properties");
54 LastfmTuner.svc = Cc[
'@songbirdnest.com/lastfm;1']
55 .getService().wrappedJSObject;
58 LastfmTuner.jsonSvc = Cc[
"@mozilla.org/dom/json;1"]
59 .createInstance(Ci.nsIJSON);
62 LastfmTuner.svc.listeners.add(LastfmTuner);
64 LastfmTuner.populateBox(
"nav-recent-stations",
65 LastfmTuner.dataRecentStations);
68 LastfmTuner.prefs = Cc[
"@mozilla.org/preferences-service;1"]
69 .getService(Ci.nsIPrefService).getBranch(
"extensions.lastfm.")
70 .QueryInterface(Ci.nsIPrefBranch2);
71 LastfmTuner.prefs.addObserver(
"", LastfmTuner,
false);
74 LastfmTuner.populateBox(
"nav-played-artists-sb",
75 LastfmTuner.dataSBMostPlayedArtists);
76 LastfmTuner.populateBox(
"nav-rated-artists-sb",
77 LastfmTuner.dataSBHighestRatedArtists);
78 LastfmTuner.populateBox(
"nav-genres-sb",
79 LastfmTuner.dataSBGenres);
82 LastfmTuner.setHeaderDisplay();
83 $(
"#lastfm-header-style").click(
function(e) {
86 LastfmTuner.toggleHeaderDisplay();
92 LastfmTuner.svc.listeners.remove(LastfmTuner);
93 LastfmTuner.prefs.removeObserver(
"", LastfmTuner,
false);
96 loadPage:
function(
url, metricKey) {
97 LastfmTuner._metrics.metricsInc(
'lastfm',
'pageclick', metricKey);
98 gBrowser.loadOneTab(
url);
102 onAuthorisationSuccess:
function() {
104 onLoginSucceeded:
function() {
105 dump(
"login success hook called: " + LastfmTuner.svc.subscriber +
"\n");
106 LastfmTuner.populateBox(
"nav-recommended-artists", this.dataRecArtists);
107 LastfmTuner.populateBox(
"nav-top-artists", this.dataTopArtists);
108 LastfmTuner.populateBox(
"nav-top-tags", this.dataTopTags);
109 LastfmTuner.populateBox(
"nav-friends", this.dataMyFriends, 999);
110 LastfmTuner.populateBox(
"nav-neighbours", this.dataMyNeighbours);
113 $(
"#right-nav-last-fm").slideDown(
"slow");
115 if (LastfmTuner.svc.subscriber) {
116 $(
"#subscriber-page").hide();
119 onLoginFailed:
function() {
121 onProfileUpdated:
function() {
123 var avatar =
"chrome://sb-lastfm/skin/default-avatar.png";
124 if (LastfmTuner.svc.avatar)
125 avatar = LastfmTuner.svc.avatar;
126 var imageEl = document.getElementById(
"lastfm-user-image");
127 imageEl.src = avatar;
128 imageEl.onload =
function() {
129 $(
"#user-profile").fadeIn(
"slow");
132 var
name = LastfmTuner.svc.realname;
133 LastfmTuner.profileurl = LastfmTuner.svc.profileurl;
136 $(
"#lastfm-user-name").
empty();
137 $(
"#lastfm-user-name").
append(name);
140 var username = LastfmTuner.svc.username;
141 $(
"#nav-user-stations-results a").
each(
function() {
142 this.
href =
"lastfm://user/" + username +
"/" + this.
id;
149 $(
"#login-page").hide();
150 if (!LastfmTuner.svc.subscriber)
151 $(
"#subscriber-page").show();
153 onLoveBan:
function() {
155 onShouldScrobbleChanged:
function() {
157 onUserLoggedOutChanged:
function() {
159 $(
"#user-profile").fadeOut(
"slow");
160 $(
"#lastfm-user-stations").fadeOut(
"slow");
163 $(
"#right-nav-last-fm").slideUp(
"slow");
166 $(
"#login-page").show();
167 $(
"#subscriber-page").hide();
169 showLogin:
function() {
170 Cc[
'@mozilla.org/appshell/window-mediator;1']
171 .getService(Ci.nsIWindowMediator)
172 .getMostRecentWindow(
'Songbird:Main').LastFm.showPanel();
174 onLoggedInStateChanged:
function() {
176 onErrorChanged:
function() {
178 onLoginBegins:
function() {
180 onLoginCancelled:
function() {
187 collectResults:
function(success, xml, type,
limit) {
189 dump(
"Failed search\n");
192 var tagResults = xml.getElementsByTagName(type);
193 if (tagResults.length == 0) {
194 dump(
"No results found\n");
199 var tags =
node.getElementsByTagName(
tag);
202 return tags[0].textContent;
204 for (var
i=0;
i<tags.length;
i++) {
206 return tags[
i].textContent;
209 return tags[0].textContent;
216 var results =
new Array();
217 for (var
i=0;
i<tagResults.length;
i++) {
218 var tagResult = tagResults[
i];
219 var notStreamable = (xmlText(tagResult,
'streamable') ==
"0");
225 name: xmlText(tagResult,
'name')
226 .replace(/&/g,
"&").replace(/>/g,
"gt;")
227 .replace(/</g,
"<").replace(/
"/g, ""
"),
228 url: xmlText(tagResult, 'url'),
231 var pattern, replace;
234 pattern = /^.*www\.last\.fm\/music/;
236 info.sImageUrl = xmlText(tagResult,
237 'image',
"size",
"small");
238 info.mImageUrl = xmlText(tagResult,
239 'image',
"size",
"medium");
240 info.lImageUrl = xmlText(tagResult,
241 'image',
"size",
"large");
244 pattern = /^.*www\.last\.fm\/
tag/;
245 replace =
"lastfm://tag";
246 info.sImageUrl =
"chrome://sb-lastfm/skin/tag.png";
247 info.mImageUrl =
"chrome://sb-lastfm/skin/tag_m.png";
248 info.lImageUrl =
"chrome://sb-lastfm/skin/tag_l.png";
251 pattern = /^.*www\.last\.fm\/user/;
252 replace =
"lastfm://user";
253 info.sImageUrl = xmlText(tagResult,
254 'image',
"size",
"small");
255 info.mImageUrl = xmlText(tagResult,
256 'image',
"size",
"medium");
257 info.lImageUrl = xmlText(tagResult,
258 'image',
"size",
"large");
264 info.sImageUrl =
"http://cdn.last.fm/flatness/catalogue/noimage/2/default_user_small.png";
266 info.mImageUrl =
"http://cdn.last.fm/flatness/catalogue/noimage/2/default_user_medium.png";
268 info.lImageUrl =
"http://cdn.last.fm/flatness/catalogue/noimage/2/default_user_large.png";
269 info.stationUrl = info.url.replace(pattern, replace);
279 runSearch:
function() {
283 var e = $(
'#explorer');
286 e.append(
"<div id='artist-results' /><div id='tag-results' />");
289 LastfmTuner.svc.apiCall(
"artist.search", {
artist:search},
290 function response(success, xml)
292 var results = LastfmTuner.collectResults(success, xml,
"artist",
293 DISPLAY_SEARCH_LIMIT);
295 var ar = $(
"#artist-results", e);
297 var
str = LastfmTuner._strings.formatStringFromName(
298 "lastfm.radio.no_artists_found", [search], 1);
299 ar.append(
"<h2 class='title'>" + str +
"</h2>");
304 var artistsHeader = LastfmTuner._strings.GetStringFromName(
305 "lastfm.radio.artists");
306 ar.append(
"<h2 class='title'>" + artistsHeader +
"</h2>");
307 LastfmTuner.drawMultipleResults(results,
"artist",
"l", 9, ar,
309 LastfmTuner.drawSingleArtist(station.stationInfo);
313 LastfmTuner.svc.apiCall(
"tag.search", {
tag:search},
314 function response(success, xml)
316 var results = LastfmTuner.collectResults(success, xml,
"tag",
317 DISPLAY_SEARCH_LIMIT);
319 var tr = $(
"#tag-results", e);
321 var
str = LastfmTuner._strings.formatStringFromName(
322 "lastfm.radio.no_tags_found", [search], 1);
323 tr.append(
"<h2 class='title'>" + str +
"</h2>");
328 var tagsHeader = LastfmTuner._strings.GetStringFromName(
329 "lastfm.radio.tags");
330 tr.append(
"<h2 class='title'>" + tagsHeader +
"</h2>");
331 LastfmTuner.drawMultipleResults(results,
"tag",
"s", 9, tr,
333 LastfmTuner.drawSingleTag(station.stationInfo);
339 drawMultipleResults:
function(results, type, imgSize,
limit,
node, onclick)
341 var resultClass = type +
"-result";
342 var imageClass = type +
"-image";
343 node.append(
"<div class='search-results'>");
344 results.forEach(
function(
val,
i, arr) {
348 var image =
val[imgSize +
"ImageUrl"];
350 var playStr = LastfmTuner._strings.GetStringFromName(
351 "lastfm.radio.play");
353 "<div class='single-result " + resultClass +
"'>" +
355 "<div class='station-info'>" +
356 "<div class='station-name'>" +
357 "<img class='" + imageClass +
"' src='" + image +
361 "<div class='station-nav'>" +
362 "<div class='station-play'><a href='" +
val.stationUrl +
363 "'><img src='" + RADIO_ICON_SMALL +
364 "'/>" + playStr +
"</a></div>" +
365 "<div class='station-web'>" +
366 "<img height='12' src='" + GLOBE_ICON +
"'/>" +
373 var nav = $(
".station-nav", singleResult);
375 singleResult.hover(
function over(e) {
379 nav.css({
'left': x,
'top': y});
385 var playStr = LastfmTuner._strings.GetStringFromName(
386 "lastfm.radio.play");
388 "<div class='single-result " + resultClass +
"'>" +
391 "<div class='img-outer-shadow-bottom'><div class='img-outer-shadow'><div class='img-outer'><div class='img-inner'>" +
392 "<img src='" + image +
"' height='80' border='0' />" +
393 "</div></div></div></div>" +
395 "<div class='station-info'>" +
val.name +
396 "<div class='station-nav'>" +
397 "<div class='station-play'><a href='" +
val.stationUrl +
398 "'><img src='" + RADIO_ICON_SMALL +
399 "'/>" + playStr +
"</a></div>" +
400 "<div class='station-web'>" +
401 "<img height='12' src='" + GLOBE_ICON +
"'/>" +
408 $(
".station-nav", singleResult).hide();
409 singleResult.hover(
function over(e) {
410 $(
".station-nav",
this).fadeIn(
'normal');
412 $(
".station-nav",
this).fadeOut(100);
415 $(
'.search-results',
node).
append(singleResult);
417 $(
'.station-play', singleResult).click(
function(e) {
420 LastfmTuner.saveRecentStation(
val);
421 LastfmTuner.svc.radioPlay(
val.stationUrl);
423 $(
'.station-web', singleResult).click(
function(e) {
426 gBrowser.loadOneTab(
val.url);
429 singleResult.stationInfo =
val;
430 singleResult.click(
function(e) {
433 onclick(singleResult);
438 createDetailBlock:
function(info, type) {
439 var playStr = LastfmTuner._strings.GetStringFromName(
440 "lastfm.radio.play");
441 var block = $(
"<div class='detail-view detail-view-" + type +
"'>" +
442 "<img class='" + type +
"-image' src='" + info.lImageUrl +
"'/>" +
443 "<div class='detail-info-" + type +
"'><h3>" + info.name +
"</h3>" +
444 "<div class='detail-info-homepage'><a href=''>" +
445 "<img src='" + GLOBE_ICON +
"'/>View station page" +
447 "<div class='station-play-button'><a href='" + info.stationUrl +
448 "'><img src='" + RADIO_ICON_SMALL +
"'/>" +
449 playStr +
"</a></div>"
452 $(
".station-play-button", block).click(
function(e) {
455 LastfmTuner.saveRecentStation(info);
456 LastfmTuner.svc.radioPlay(info.stationUrl);
458 $(
".detail-info-homepage", block).click(
function(e) {
461 gBrowser.loadOneTab(info.url);
464 if (!info.lImageUrl) {
465 LastfmTuner.svc.apiCall(
'artist.getInfo', {
468 },
function response(success, xml) {
469 var results = LastfmTuner.collectResults(success, xml,
471 if (results ==
null) {
472 dump(
"artist.getInfo failed\n");
475 dump(
"setting image to: " + results[0].lImageUrl +
"\n");
476 $(
"img." + type +
"-image", block)[0].src =
477 results[0].lImageUrl;
484 drawSingleArtist:
function(info) {
485 var artistDetail = LastfmTuner._strings.GetStringFromName(
486 "lastfm.radio.artist.detail");
487 $(
'#explorer').
empty();
488 $(
'#explorer').
append(
"<h2 class='title'>" + artistDetail +
"</h2>");
492 var detailBlock = LastfmTuner.createDetailBlock(info,
"artist");
493 $(
'#explorer').
append(detailBlock);
494 $(
'#explorer').
append(
"<div style='clear:left;' />");
496 $(
'#explorer').
append(
"<div id='tags'>");
497 var tagsDiv = $(
'#explorer > #tags');
499 $(
'#explorer').
append(
"<div id='artists'>");
500 var artistsDiv = $(
'#explorer > #artists');
502 $(
'#explorer').
append(
"<div id='fans'>");
503 var fansDiv = $(
'#explorer > #fans');
506 var tagsStr = LastfmTuner._strings.GetStringFromName(
507 "lastfm.radio.artist.tags");
508 tagsDiv.append(
"<h3 class='subtitle'>" + tagsStr +
"</h3>");
509 tagsDiv.append(
"<div class='results'>");
511 var similarStr = LastfmTuner._strings.GetStringFromName(
512 "lastfm.radio.similar.artists");
513 artistsDiv.append(
"<h3 class='subtitle'>" + similarStr +
"</h3>");
514 artistsDiv.append(
"<div class='results'>");
516 var fansStr = LastfmTuner._strings.GetStringFromName(
517 "lastfm.radio.fans");
518 fansDiv.append(
"<h3 class='subtitle'>" + fansStr +
"</h3>");
519 fansDiv.append(
"<div class='results'>");
521 LastfmTuner.svc.apiCall(
'artist.gettoptags', {
524 },
function response(success, xml) {
525 var results = LastfmTuner.collectResults(success, xml,
"tag",
526 DISPLAY_RELATED_TAGS_LIMIT);
527 if (results ==
null) {
528 dump(
"collect artist top tags failed\n");
531 LastfmTuner.drawMultipleResults(results,
"tag",
"s", 9,
532 $(
'.results', tagsDiv),
function(station) {
533 LastfmTuner.drawSingleTag(station.stationInfo);
535 tagsDiv.append(
"<div style='clear:left;' />");
536 tagsDiv.fadeIn(
'slow');
540 LastfmTuner.svc.apiCall(
'artist.getsimilar', {
543 },
function response(success, xml) {
544 var results = LastfmTuner.collectResults(success, xml,
"artist",
545 DISPLAY_RELATED_ARTISTS_LIMIT);
546 if (results ==
null) {
547 dump(
"collect artist similar artists failed\n");
550 LastfmTuner.drawMultipleResults(results,
"artist",
"l", 9,
551 $(
'.results', artistsDiv),
function(station) {
552 LastfmTuner.drawSingleArtist(station.stationInfo);
554 artistsDiv.append(
"<div style='clear:left;' />");
555 artistsDiv.fadeIn(
'slow');
559 LastfmTuner.svc.apiCall(
'artist.getTopFans', {
562 },
function response(success, xml) {
563 var results = LastfmTuner.collectResults(success, xml,
"user",
564 DISPLAY_TOP_FANS_LIMIT);
565 if (results ==
null) {
566 dump(
"collect artist top fans failed\n");
569 LastfmTuner.drawMultipleResults(results,
"artist",
"l", 9,
570 $(
'.results', fansDiv),
function(station) {
571 LastfmTuner.drawSingleUser(station.stationInfo);
573 fansDiv.append(
"<div style='clear:left;' />");
574 fansDiv.fadeIn(
'slow');
579 drawSingleTag:
function(info) {
580 var tagDetail = LastfmTuner._strings.GetStringFromName(
581 "lastfm.radio.tag.detail");
582 $(
'#explorer').
empty();
583 $(
'#explorer').
append(
"<h2 class='title'>" + tagDetail +
"</h2>");
585 var detailBlock = LastfmTuner.createDetailBlock(info,
"tag");
586 $(
'#explorer').
append(detailBlock);
588 $(
'#explorer').
append(
"<div style='clear:left;' />");
590 $(
'#explorer').
append(
"<div id='tags'>");
591 var tagsDiv = $(
'#explorer > #tags');
593 $(
'#explorer').
append(
"<div id='artists'>");
594 var artistsDiv = $(
'#explorer > #artists');
597 var similarTags = LastfmTuner._strings.GetStringFromName(
598 "lastfm.radio.similar.tags");
599 tagsDiv.append(
"<h3 class='subtitle'>" + similarTags +
"</h3>");
600 tagsDiv.append(
"<div class='results'>");
602 var tagArtists = LastfmTuner._strings.GetStringFromName(
603 "lastfm.radio.tag.artists");
604 artistsDiv.append(
"<h3 class='subtitle'>" + tagArtists +
"</h3>");
605 artistsDiv.append(
"<div class='results'>");
607 LastfmTuner.svc.apiCall(
'tag.getsimilar', {
610 },
function response(success, xml) {
611 var results = LastfmTuner.collectResults(success, xml,
"tag",
612 DISPLAY_RELATED_TAGS_LIMIT);
613 if (results ==
null) {
614 dump(
"collect tag similar tags failed\n");
618 LastfmTuner.drawMultipleResults(results,
"tag",
"s", 9,
619 $(
'.results', tagsDiv),
function(station) {
620 LastfmTuner.drawSingleTag(station.stationInfo);
622 tagsDiv.append(
"<div style='clear:left;' />");
623 tagsDiv.fadeIn(
'slow');
627 LastfmTuner.svc.apiCall(
'tag.gettopartists', {
630 },
function response(success, xml) {
631 var results = LastfmTuner.collectResults(success, xml,
"artist",
632 DISPLAY_RELATED_ARTISTS_LIMIT);
633 if (results ==
null) {
634 dump(
"collect tag tagged artists failed\n");
638 LastfmTuner.drawMultipleResults(results,
"artist",
"l", 9,
639 $(
'.results', artistsDiv),
function(station) {
640 LastfmTuner.drawSingleArtist(station.stationInfo);
642 artistsDiv.append(
"<div style='clear:left;' />");
643 artistsDiv.fadeIn(
'slow');
648 drawSingleUser:
function(info) {
649 var userDetail = LastfmTuner._strings.GetStringFromName(
650 "lastfm.radio.user.detail");
651 $(
'#explorer').
empty();
652 $(
'#explorer').
append(
"<h2 class='title'>" + userDetail +
"</h2>");
655 var detailBlock = LastfmTuner.createDetailBlock(info,
"user");
656 $(
'#explorer').
append(detailBlock);
658 $(
'#explorer').
append(
"<div style='clear:left;' />");
660 $(
'#explorer').
append(
"<div id='tags'>");
661 var tagsDiv = $(
'#explorer > #tags');
663 $(
'#explorer').
append(
"<div id='artists'>");
664 var artistsDiv = $(
'#explorer > #artists');
667 var topTags = LastfmTuner._strings.GetStringFromName(
668 "lastfm.radio.tags.top");
669 var topArtists = LastfmTuner._strings.GetStringFromName(
670 "lastfm.radio.artists.top");
671 tagsDiv.append(
"<h3 class='subtitle'>" + topTags +
"</h3>");
672 tagsDiv.append(
"<div class='results'>");
674 artistsDiv.append(
"<h3 class='subtitle'>" + topArtists +
"</h3>");
675 artistsDiv.append(
"<div class='results'>");
677 LastfmTuner.svc.apiCall(
'user.getTopTags', {
680 },
function response(success, xml) {
681 var results = LastfmTuner.collectResults(success, xml,
"tag",
682 DISPLAY_RELATED_TAGS_LIMIT);
683 if (results ==
null) {
684 dump(
"collect user top tags failed\n");
688 LastfmTuner.drawMultipleResults(results,
"tag",
"s", 9,
689 $(
'.results', tagsDiv),
function(station) {
690 LastfmTuner.drawSingleTag(station.stationInfo);
692 tagsDiv.append(
"<div style='clear:left;' />");
693 tagsDiv.fadeIn(
'slow');
697 LastfmTuner.svc.apiCall(
'user.getTopArtists', {
700 },
function response(success, xml) {
701 var results = LastfmTuner.collectResults(success, xml,
"artist",
702 DISPLAY_RELATED_ARTISTS_LIMIT);
703 if (results ==
null) {
704 dump(
"collect user top artists failed\n");
708 LastfmTuner.drawMultipleResults(results,
"artist",
"l", 9,
709 $(
'.results', artistsDiv),
function(station) {
710 LastfmTuner.drawSingleArtist(station.stationInfo);
712 artistsDiv.append(
"<div style='clear:left;' />");
713 artistsDiv.fadeIn(
'slow');
718 saveRecentStation:
function(thisStation) {
721 for (var
i=0;
i<LastfmTuner.recentStations.length;
i++) {
722 if (LastfmTuner.recentStations[
i].stationUrl == thisStation.stationUrl) {
728 dump(
"duplicate station found @ " + prevIdx +
"\n");
729 LastfmTuner.recentStations.splice(prevIdx, 1);
731 LastfmTuner.recentStations.push(thisStation);
732 Application.prefs.setValue(
"extensions.lastfm.recent.stations",
733 LastfmTuner.jsonSvc.encode(LastfmTuner.recentStations));
736 setHeaderDisplay:
function() {
737 var paintBlack =
Application.prefs.getValue(
"extensions.lastfm.header",
739 var hTopEl = document.getElementById(
"header-top");
740 $(
"#lastfm-header-style").
empty();
743 $(
"#lastfm-header-style").
append(
"Simply Red");
744 hTopEl.setAttribute(
"paintblack",
"true");
746 $(
"#lastfm-header-style").
append(
"Paint it Black");
747 hTopEl.setAttribute(
"paintblack",
"false");
751 toggleHeaderDisplay:
function() {
752 var paintBlack =
Application.prefs.getValue(
"extensions.lastfm.header",
754 Application.prefs.setValue(
"extensions.lastfm.header", !paintBlack);
755 this.setHeaderDisplay();
759 if (subject instanceof Components.interfaces.nsIPrefBranch) {
760 if (
data ==
"recent.stations") {
761 dump(
"recent stations changed!\n");
762 LastfmTuner.populateBox(
"nav-recent-stations",
763 LastfmTuner.dataRecentStations);
772 LastfmTuner.recentStations =
773 LastfmTuner.jsonSvc.decode(
Application.prefs.getValue(
774 "extensions.lastfm.recent.stations",
"[]"));
775 while (LastfmTuner.recentStations.length > DISPLAY_RECENT_STATIONS_LIMIT)
776 LastfmTuner.recentStations.shift();
781 LastfmTuner.svc.apiCall(
'user.getRecommendedArtists', {
782 },
function response(success, xml) {
783 var results = LastfmTuner.collectResults(success, xml,
"artist");
784 if (results ==
null) {
785 dump(
"collect recommended artists failed\n");
793 LastfmTuner.svc.apiCall(
'user.getTopArtists', {
794 user: LastfmTuner.svc.username
795 },
function response(success, xml) {
796 var results = LastfmTuner.collectResults(success, xml,
"artist");
797 if (results ==
null) {
798 dump(
"collect recommended artists failed\n");
806 LastfmTuner.svc.apiCall(
'user.getTopTags', {
807 user: LastfmTuner.svc.username
808 },
function response(success, xml) {
809 var results = LastfmTuner.collectResults(success, xml,
"tag");
810 if (results ==
null) {
811 dump(
"collect top tags failed\n");
819 LastfmTuner.svc.apiCall(
'user.getFriends', {
820 user: LastfmTuner.svc.username
821 },
function response(success, xml) {
822 var results = LastfmTuner.collectResults(success, xml,
"user");
823 if (results ==
null) {
824 dump(
"collect my friends failed\n");
832 LastfmTuner.svc.apiCall(
'user.getNeighbours', {
833 user: LastfmTuner.svc.username
834 },
function response(success, xml) {
835 var results = LastfmTuner.collectResults(success, xml,
"user");
836 if (results ==
null) {
837 dump(
"collect my neighbours failed\n");
844 dataSBCollect:
function(primary, secondary, type,
callback) {
846 var collectResults = lib.collectDistinctValues(primary,
847 Ci.sbILibraryStatistics.COLLECT_SUM, secondary,
false, 30);
848 var results =
new Array();
849 for (var
i=0;
i<collectResults.length;
i++) {
850 var s = collectResults.queryElementAt(
i, Ci.nsIVariant)
851 .replace(/&/g,
"&").replace(/>/g,
"gt;")
852 .replace(/</g,
"<").replace(/
"/g, ""
");
853 var url = encodeURIComponent(s).replace(/'/g, "%27
");
858 stationUrl:
"lastfm://" + type +
"/" +
url
865 LastfmTuner.dataSBCollect(SBProperties.artistName,
869 LastfmTuner.dataSBCollect(SBProperties.artistName,
873 LastfmTuner.dataSBCollect(SBProperties.genre,
878 var resultsEl = $(
'#' + elementId +
"-results");
881 if (results ==
null || results.length == 0)
883 results.forEach(
function(
val,
i, arr) {
884 if ((!
limit && (
i >= LIMIT_NAV_RESULTS)) ||
887 var rowClass =
"row-even";
889 rowClass =
"row-odd";
890 var playStr = LastfmTuner._strings.GetStringFromName(
891 "lastfm.radio.play");
893 "<div class='nav-station " + rowClass +
"'>" +
894 "<div class='station-play-button'><a href='" +
895 val.stationUrl +
"'><img src='" + RADIO_ICON_SMALL +
896 "'/>" + playStr +
"</a></div>" +
897 "<img src ='chrome://sb-lastfm/skin/" +
val.type +
898 ".png' class='icon-type' />" +
val.name +
"</div>");
899 $(
".station-play-button", stationEl).click(
function(e) {
902 dump(
"Saving recent station\n");
903 LastfmTuner.saveRecentStation(
val);
904 LastfmTuner.svc.radioPlay(
val.stationUrl);
906 stationEl.click(
function(e) {
908 dump(
"type: " +
val.type +
"\n");
911 LastfmTuner.drawSingleArtist(
val);
914 LastfmTuner.drawSingleTag(
val);
917 LastfmTuner.drawSingleUser(
val);
921 gBrowser.loadOneTab(
val.url);
924 stationEl.hover(
function(e) {
930 resultsEl.append(stationEl);
938 var bodyHeight = $(
'body')[0].scrollHeight;
939 var
height = bodyHeight - $(
'#header')[0].scrollHeight;
940 var height2 = $(
'#left-content')[0].scrollHeight;
942 if (height2 > height)
944 $(
'#right-nav').
css({
"min-height":height});
946 height = $(
'#content')[0].scrollHeight + $(
'#header')[0].scrollHeight;
947 $(
".wrapper-box").
css({
"height":bodyHeight,
"max-height":bodyHeight});
948 $(
"#login-page").
css({
"min-height":height});
949 $(
"#subscriber-page").
css({
"min-height":height});
952 $(document).ready(
function() {
956 $(
"#right-nav-last-fm").hide();
959 $(
"#user-profile").hide();
962 $(
'.nav-results:not(.section-open)').hide();
965 $(
'#nav-user-stations-results .nav-station').hover(
function over(e) {
973 $(
'#search-box').
focus(
function() {
974 $(
this).
css({
"color":
"#555"});
978 $(
'#right-nav h3.nav-stations').click(
function() {
979 var resultsId = this.parentNode.parentNode.id +
"-results";
980 $(
'.nav-results:not(#'+resultsId+
')').hide(
'fast');
981 if ($(
'#' + resultsId).is(
':hidden')) {
982 $(
'#' + resultsId).slideDown(
'fast');
983 this.
className =
"nav-stations section-open";
985 $(
'#' + resultsId).hide(
'fast');
993 $(
"#start-artists").hide();
994 $(
"#start-tags").hide();
995 $.get(
"http://api.hostip.info/", {},
function(
data) {
997 data.getElementsByTagName(
"countryName")[0].textContent;
1003 },
function response(success, xml) {
1004 var results =
LastfmTuner.collectResults(success, xml,
"artist");
1005 if (results ==
null) {
1006 dump(
"collect geo top artists failed\n");
1010 var e = $(
"#start-artists");
1011 LastfmTuner.drawMultipleResults(results,
"artist",
"l", 12, e,
1013 LastfmTuner.drawSingleArtist(station.stationInfo);
1015 e.slideDown(
"slow",
function() {
1022 function response(success, xml) {
1023 var results =
LastfmTuner.collectResults(success, xml,
"tag");
1024 if (results ==
null) {
1025 dump(
"collect last.fm top tags failed\n");
1029 var e = $(
"#start-tags");
1030 LastfmTuner.drawMultipleResults(results,
"tag",
"s", 12, e,
1034 e.slideDown(
"slow",
function() {
1039 $(
"#lastfm-user-info").click(
function(e) {
1041 e.stopPropagation();
1044 $(
"#lastfm-user-image").click(
function(e) {
1046 e.stopPropagation();
1063 $(
"#search-box")[0].
focus();
sbOSDControlService prototype className
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties artist
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird dataSBMostPlayedArtists
function search(aFolderId, aSearchStr, aExpectedScopeButtonId)
this _dialogInput val(dateText)
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties populateCallback
return aWindow document documentElement getAttribute(aAttribute)||dimension
Javascript wrappers for common library tasks.
window resize(function(e){var bodyHeight=$('body')[0].scrollHeight;var height=bodyHeight-$('#header')[0].scrollHeight;var height2=$('#left-content')[0].scrollHeight;if(height2 > height) height=height2;$('#right-nav').css({"min-height":height});height=$('#content')[0].scrollHeight+$('#header')[0].scrollHeight;$(".wrapper-box").css({"height":bodyHeight,"max-height":bodyHeight});$("#login-page").css({"min-height":height});$("#subscriber-page").css({"min-height":height});})
dataSBGenres SBProperties tag
this _dialogInput css('left', this._pos[0]+'px').css('top'
let< body >< buttononblur="this.parentNode.removeChild(this);">< script > document body firstChild focus()
_getSelectedPageStyle s i
if(typeof(Cc)=="undefined") var Cc
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird LastfmTuner
sbDeviceFirmwareAutoCheckForUpdate prototype observe