11//Live check query variables.
22//Variables
33
4- var gb_url = "http://www.giantbomb.com/" ;
5- var gb_upcoming_url = "http://www.giantbomb.com/upcoming_json" ;
4+ var gb_url = "http://www.giantbomb.com/upcoming_json" ;
65var gbLive ;
76var storage = $ . localStorage ;
87var sendMessage ;
@@ -11,76 +10,30 @@ var scheduleCounter;
1110window . scheduleLoadingIcon = $ ( '#lb-schedule-loading' ) ;
1211window . buttonRefreshSchedule = $ ( '#lb-refresh-schedule' ) ;
1312
14- var parseHtml = function ( data ) {
15- return '<body>' + data . replace ( / ^ [ \s \S ] * < b o d y .* ?> | < \/ b o d y > [ \s \S ] * $ / g, '' ) + '</body>' ;
16- }
17-
1813//Check for live video
1914var checkLive = function ( ) {
2015 var checkLiveDone = $ . Deferred ( ) ;
2116
22- $ . get ( gb_url , function ( data ) {
23- var parsedHtml = parseHtml ( data ) ;
24- var parsedElem = $ ( parsedHtml ) . find ( '.header-promo.live.show' ) ;
17+ $ . getJSON ( gb_url , function ( data ) {
18+ if ( data . liveNow != null )
19+ {
20+ gbLive = true ;
21+ storage . set ( {
22+ 'islive' : true ,
23+ 'title' : data . liveNow . title ,
24+ 'liveImage' : data . liveNow . image ,
25+ 'counter' :false
26+ } ) ;
2527
26- if ( parsedElem . length == 0 ) {
28+ checkLiveDone . resolve ( ) ;
29+ }
30+ else
31+ {
2732 gbLive = false ;
28- console . log ( 'No text on frontpage, no live video' ) ;
2933 storage . set ( {
3034 'islive' :false ,
3135 'counter' :false
3236 } ) ;
33- checkLiveDone . resolve ( ) ;
34- } else {
35- var liveLink = $ ( parsedElem ) . find ( 'p a' ) ;
36- if ( liveLink . length > 0 ) {
37- gbLive = true ;
38- var titleName = liveLink . text ( ) . replace ( / [ < > ] / , '' ) ;
39- storage . set ( {
40- 'islive' : true ,
41- 'title' : titleName ,
42- 'counter' :false
43- } ) ;
44- getShowImage ( ) ;
45- console . log ( 'Video is live and link is ok' ) ;
46- checkLiveDone . resolve ( ) ;
47- } else {
48- //Scraping the frontpage for live video promo-header
49- var liveVideo = $ ( parsedHtml ) . find ( '.kubrick-chat-player' ) ;
50- if ( liveVideo . length > 0 ) {
51- var test = $ ( parsedHtml ) . find ( '.kubrick-info a h4' ) . text ( ) ;
52- var compare = "Live on Giant Bomb!" ;
53-
54- if ( test === compare ) {
55- gbLive = true ;
56- var titleName = $ ( parsedHtml ) . find ( '.kubrick-info a h2' ) . text ( ) . replace ( / [ < > ] / , '' ) ;
57- storage . set ( {
58- 'islive' : true ,
59- 'title' : titleName ,
60- 'counter' :false
61- } ) ;
62- getShowImage ( ) ;
63- console . log ( 'Video is live but link is disabled' ) ;
64- checkLiveDone . resolve ( ) ;
65- } else {
66- gbLive = false ;
67- storage . set ( {
68- 'islive' : false ,
69- 'counter' :true
70- } ) ;
71- console . log ( 'Text is there but video is no longer live or something broke on this end' ) ;
72- checkLiveDone . resolve ( ) ;
73- }
74- } else {
75- gbLive = false ;
76- storage . set ( {
77- 'islive' : false ,
78- 'counter' : true
79- } ) ;
80- console . log ( 'Counter is up but no live video' ) ;
81- checkLiveDone . resolve ( ) ;
82- }
83- }
8437 }
8538 } ) ;
8639 return checkLiveDone . promise ( ) ;
@@ -92,7 +45,7 @@ var getSchedule = function(){
9245
9346 var getScheduleDone = $ . Deferred ( ) ;
9447
95- $ . getJSON ( gb_upcoming_url , function ( data ) {
48+ $ . getJSON ( gb_url , function ( data ) {
9649
9750 scheduleCounter = 0 ;
9851
@@ -155,45 +108,3 @@ var getSchedule = function(){
155108
156109 return getScheduleDone . promise ( ) ;
157110} ;
158-
159- var getShowImage = function ( ) {
160-
161- var getShowImageDone = $ . Deferred ( ) ;
162-
163- $ . get ( gb_url , function ( liveshow ) {
164-
165- var liveShowElem = null ;
166- if ( liveshow != null ) {
167- var parsedHtml = parseHtml ( liveshow ) ;
168- var liveShowElem = $ ( parsedHtml ) . find ( '.header-promo.live.show' ) ;
169- }
170-
171- if ( liveShowElem != null && liveShowElem . length < 1 ) {
172- $ ( '#lb-status-live' ) . css ( 'background-image' , 'url(/images/premium-background.png)' ) ;
173- getShowImageDone . resolve ( ) ;
174- } else {
175-
176- var checkForVideo = $ ( liveShowElem ) . find ( 'p a' ) ;
177-
178- if ( checkForVideo . length > 0 ) {
179- var parsedElem = $ ( parsedHtml ) . find ( '.kubrick-promo-video' ) ;
180-
181- if ( $ ( parsedElem ) . css ( 'background-image' ) != '' ) {
182- var backgroundImage = $ ( parsedElem ) . css ( 'background-image' ) ;
183- $ ( '#lb-status-live' ) . css ( 'background-image' , backgroundImage ) ;
184- getShowImageDone . resolve ( ) ;
185- } else {
186- parsedElem = $ ( parsedHtml ) . find ( '#wrapper section.promo-strip div ul li' ) . eq ( 0 ) ;
187- var backgroundImage = $ ( parsedElem ) . css ( 'background-image' ) ;
188- $ ( '#lb-status-live' ) . css ( 'background-image' , backgroundImage ) ;
189- getShowImageDone . resolve ( ) ;
190- }
191- } else {
192- $ ( '#lb-status-live' ) . css ( 'background-image' , 'url(/images/premium-background.png)' ) ;
193- getShowImageDone . resolve ( ) ;
194- }
195- }
196- } ) ;
197-
198- return getShowImageDone . promise ( ) ;
199- } ;
0 commit comments