From 92faa199e41ba10bfc54f6b70829c6f3ace16875 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Sat, 19 Nov 2016 14:11:33 -0800 Subject: [PATCH] Add "live now" label. --- public/js/live.js | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/public/js/live.js b/public/js/live.js index af1c5e4..b3f6e03 100644 --- a/public/js/live.js +++ b/public/js/live.js @@ -75,9 +75,10 @@ function update_accounts() { $("#facebook_accounts").empty(); facebook.accounts.forEach(function(a) { var panel = $(` -
+
${a.username} (${a.id}) + Open
@@ -113,6 +114,7 @@ function update_accounts() {
${a.username} (${a.id}) + Open
@@ -148,6 +150,7 @@ function update_accounts() {
${a.display_name} + IRC VLC @@ -203,9 +206,9 @@ function poll() { return; } var data = JSON.parse(r.body).data; - var live_videos = data.filter(function(v){ return v.live_status }).slice(0, 3); - log("facebook", a.username, new Date, live_videos); - live_videos.reverse().forEach(function(v) { + var videos = data.filter(function(v){ return v.live_status }).slice(0, 3); + log("facebook", a.username, new Date, videos); + videos.reverse().forEach(function(v) { var tbody = $(`tbody[data-facebook-id="${a.id}"]`); var tr_id = `${v.live_status}-${v.id}`; if (tbody.find(`#${tr_id}`).length > 0) { @@ -235,6 +238,12 @@ function poll() { }); } }); + if (videos.some(function(v) { return v.live_status == "LIVE" })) { + $(`div[data-facebook-id="${a.id}"] [data-live-label]`).removeClass("hidden"); + } + else { + $(`div[data-facebook-id="${a.id}"] [data-live-label]`).addClass("hidden"); + } }); $("time.timeago").timeago(); }); @@ -303,6 +312,12 @@ function poll() { tr[0].scrollIntoView(); }); }); + if (this.response.items.some(function(v) { return v.liveStreamingDetails && v.liveStreamingDetails.actualStartTime })) { + $(`div[data-youtube-id="${a.id}"] [data-live-label]`).removeClass("hidden"); + } + else { + $(`div[data-youtube-id="${a.id}"] [data-live-label]`).addClass("hidden"); + } $("time.timeago").timeago(); }); xhr2.send(); @@ -318,10 +333,10 @@ function poll() { xhr.setRequestHeader("Accept", "application/vnd.twitchtv.v3+json"); xhr.setRequestHeader("Client-ID", twitch.client_id); xhr.addEventListener("load", function() { - var live_videos = this.response.videos.slice(0, 3); - log("twitch", a.username, new Date, live_videos); + var videos = this.response.videos.slice(0, 3); + log("twitch", a.username, new Date, videos); var tbody = $(`tbody[data-twitch-id="${a.id}"]`); - live_videos.reverse().forEach(function(v) { + videos.reverse().forEach(function(v) { var tr_id = `twitch-${v.status}-${v._id}`; if (tbody.find(`#${tr_id}`).length > 0) { return; @@ -355,6 +370,12 @@ function poll() { }); } }); + if (videos.some(function(v) { return v.status == "recording" })) { + $(`div[data-twitch-id="${a.id}"] [data-live-label]`).removeClass("hidden"); + } + else { + $(`div[data-twitch-id="${a.id}"] [data-live-label]`).addClass("hidden"); + } $("time.timeago").timeago(); }); xhr.send();