Skip to content

Commit a7324f9

Browse files
committed
v1.2.9 No more scraping! Live status from JSON.
1 parent 8e63f97 commit a7324f9

File tree

4 files changed

+34
-118
lines changed

4 files changed

+34
-118
lines changed

js/functions.js

Lines changed: 16 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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";
65
var gbLive;
76
var storage = $.localStorage;
87
var sendMessage;
@@ -11,76 +10,30 @@ var scheduleCounter;
1110
window.scheduleLoadingIcon = $('#lb-schedule-loading');
1211
window.buttonRefreshSchedule = $('#lb-refresh-schedule');
1312

14-
var parseHtml = function(data){
15-
return '<body>' + data.replace(/^[\s\S]*<body.*?>|<\/body>[\s\S]*$/g, '') + '</body>';
16-
}
17-
1813
//Check for live video
1914
var 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-
};

js/livebomb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ else if (storage.get('islive') == false && storage.get('show-schedule') == fals
192192
statusOffline.show();
193193
} else {
194194
chrome.browserAction.setBadgeText({text:"LIVE"});
195-
getShowImage();
195+
$('#lb-status-live').css('background-image', 'url("' + storage.get('liveImage') + '")');
196196
statusOnline.show();
197197
statusOffline.hide();
198198
$('#button-icon').css("color", 'red').addClass("animated swing");

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"name": "Live Bomb!",
55
"description": "This extension notifies you when GiantBomb is live and you can also check the site schedule.",
6-
"version": "1.2.8",
6+
"version": "1.2.9",
77
"permissions": [
88
"http://www.giantbomb.com/",
99
"background",

popup.html

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<input type="radio" id="tab2" name="nav-tabs"> <i class="fa fa-dot-circle-o fa-lg"></i>
3030
</label>
3131

32-
<label id="lb-schedule" class="btn btn-default active col-xs-4">
32+
<label id="lb-schedule" class="btn btn-default col-xs-4">
3333
<input type="radio" id="tab2" name="nav-tabs" checked> <i class="fa fa-calendar-o fa-lg"></i>
3434
</label>
3535
</div>
@@ -178,18 +178,24 @@ <h4 id="offline-bottom">The guys are busy <br>windjamming :(</h4>
178178
<div class="custom-scroll">
179179
<h4 id="about-page-title">About <i class="fa fa-times" id="offline-about-close"></i><i class="fa fa-times" id="settings-about-close"></i></h4>
180180
<img src="/images/128.png" id="about-image" class="animated tada">
181-
<h4 id="about-livebomb">LiveBomb v1.2.8</h4>
182-
<!--<i class="fa fa-times-o " id="about-close-icon"></i>-->
181+
182+
<h4 id="about-livebomb">LiveBomb v1.2.9</h4>
183+
183184
<h4 class="about-text-title">Developed by:</h4>
184-
<h4>André Milani</h4>
185-
<h4>Chase Pettit</h4>
185+
<h4><a href="https://twitter.com/andrem_m" target="_blank">André Milani</a></h4>
186+
<h4><a href="https://twitter.com/chasepettit" target="_blank">Chase Pettit</a></h4>
187+
188+
<h4 class="about-text-title"><a href="https://github.com/Chaser324/live-bomb" target="_blank"><i class="fa fa-github-square"></i> Fork on GitHub</a></h4>
189+
186190
<h4 class="about-text-title">Awesome Ryan fanart by:</h4>
187-
<a href="http://www.giantbomb.com/profile/shoddyrobot/" id="image-author">@Shoddy Robot</a>
191+
<a href="http://www.giantbomb.com/profile/shoddyrobot/" id="image-author" target="_blank">@Shoddy Robot</a>
192+
188193
<h4 class="about-text-title">Thanks to:</h4>
189-
<p><a href="http://www.giantbomb.com/profile/catsakimbo/" class="about-item">@CatsAkimbo</a></p>
190-
<p><a href="http://www.giantbomb.com/profile/chance_s/" class="about-item">@Chance_S</a></p>
191-
<p><a href="http://www.giantbomb.com/profile/cencen123/" class="about-item">@cencen123</a></p>
192-
<p><a href="http://www.giantbomb.com/profile/hamst3r/">@Hamst3r</a></p>
194+
<p><a href="http://www.giantbomb.com/profile/catsakimbo/" class="about-item" target="_blank">@CatsAkimbo</a></p>
195+
<p><a href="http://www.giantbomb.com/profile/chance_s/" class="about-item" target="_blank">@Chance_S</a></p>
196+
<p><a href="http://www.giantbomb.com/profile/cencen123/" class="about-item" target="_blank">@cencen123</a></p>
197+
<p><a href="http://www.giantbomb.com/profile/hamst3r/" target="_blank">@Hamst3r</a></p>
198+
193199
<div id="tools">
194200
<h4 class="about-text-title" id="lb-about-tools"> Tools used: </h4>
195201
<a href="http://getbootstrap.com/" target="_blank"><h5 class="about-item">Twitter Bootstrap</h5></a>
@@ -199,7 +205,6 @@ <h4 class="about-text-title" id="lb-about-tools"> Tools used: </h4>
199205
<a href="http://ionden.com/a/plugins/ion.sound/en.html" target="_blank"><h5 class="about-item">IonSound by Denis Ineshin</h5></a>
200206
<a href="https://github.com/julien-maurel/jQuery-Storage-API" target="_blank"><h5 class="about-item">Jquery Storage API by Julien Muriel</h5></a>
201207
<a href="http://rocha.la/jQuery-slimScroll" target="_blank"><h5 class="about-item">jQuery slimScroll by Piotr Rochala</h5></a>
202-
<a href="http://developer.yahoo.com/yql/console/" target="_blank"><h5 class="about-item">YQL - Yahoo Query Language</h5></a>
203208
<a href="http://fontawesome.io/" target="_blank"><h5 class="about-item">Font Awesome 4.0</h5></a>
204209
<a href="https://github.com/daneden/animate.css" target="_blank"><h5 class="about-item">Animate.css by Daniel Eden</h5></a>
205210
<h5 class="about-grey-text">Some art assets from GB website</h5>

0 commit comments

Comments
 (0)