Skip to content

Commit 54fb5b0

Browse files
committed
feat(popup): Use game cases and urls for youtube and speedrun.com
1 parent 18d1b4f commit 54fb5b0

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

background/sources/collections/haloruns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default async () => {
5555
desc: 'Previous Record: ' + $previousRecord.outerHTML +
5656
' by ' + $previousUser.outerHTML + '<br />' +
5757
'Time Saved: ' + timeSaved,
58-
game: game,
58+
game: { name: game },
5959
});
6060
}
6161
return items;

background/sources/collections/speedrundotcom.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ export default async () => {
5656
transform: async (response) => {
5757
const url = response.data.weblink;
5858
const user = url.slice(url.lastIndexOf('/') + 1);
59-
let thumbnail =
59+
let image =
6060
`https://www.speedrun.com/themes/user/${user}/image.png`;
61-
const imageRes = await fetch(thumbnail, {
61+
const imageRes = await fetch(image, {
6262
method: 'HEAD'
6363
});
64-
if (!imageRes.ok) { thumbnail = null; }
64+
if (!imageRes.ok) { image = null; }
6565
return {
6666
url,
6767
name: response.data.names.international,
68-
thumbnail,
68+
image,
6969
};
7070
},
7171
ttl: 1000 * 60 * 60 * 24 // 1day
@@ -77,18 +77,19 @@ export default async () => {
7777
return !!users.filter(u => !!u).length;
7878
};
7979

80-
const addMetaToVideo = async (run, meta) => {
80+
const addGameToVideo = async (run, meta) => {
8181
if (!run.game && meta.gameID) {
82-
const game = await util.ajax(
82+
run.game = await util.ajax(
8383
'https://www.speedrun.com/api/v1/games/' + meta.gameID, {
8484
cache: {
8585
transform: (response) => ({
86-
name: response.data.names.international
86+
name: response.data.names.international,
87+
url: response.data.weblink,
88+
image: response.data.assets['cover-small'].uri,
8789
}),
8890
ttl: 1000 * 60 * 60 * 24 // 1day
8991
},
9092
});
91-
run.game = game.name;
9293
return true;
9394
} else {
9495
return true;
@@ -102,7 +103,7 @@ export default async () => {
102103
run.desc = meta.desc;
103104
const results = await Promise.all([
104105
addUsersToRun(run, meta),
105-
addMetaToVideo(run, meta)
106+
addGameToVideo(run, meta)
106107
]);
107108
return results[0] && results[1];
108109
};

background/sources/videos/twitch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ export default {
7272
thumbnail : response.preview,
7373
length : response.length,
7474
title : response.title,
75-
game : response.game,
75+
game : { name: response.game },
7676
views : response.views,
7777
user : {
7878
url: 'https://www.twitch.tv/' + response.channel.name,
7979
name: response.channel.display_name,
80-
thumbnail: userImages.get(response.channel.name),
80+
image: userImages.get(response.channel.name),
8181
},
8282
};
8383
},
@@ -98,7 +98,7 @@ export default {
9898
user: {
9999
url: 'https://www.twitch.tv/' + video.channel.name,
100100
name: video.channel.display_name,
101-
thumbnail: userImages.get(video.channel.name),
101+
image: userImages.get(video.channel.name),
102102
},
103103
url: video.url,
104104
thumbnail: video.preview,
@@ -107,7 +107,7 @@ export default {
107107
timestamp: new Date(video.created_at).getTime(),
108108
views: video.views,
109109
desc: video.description,
110-
game: video.game,
110+
game: { name: video.game },
111111
};
112112
});
113113
},

background/sources/videos/youtube.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default {
4545
user: {
4646
url: info.author.channel_url,
4747
name: info.author.name,
48-
thumbnail: info.author.avatar,
48+
image: info.author.avatar,
4949
verified: info.author.verified,
5050
},
5151

@@ -57,7 +57,7 @@ export default {
5757
game: info.media && info.media.game ? {
5858
name: info.media.game,
5959
url: info.media.game_url,
60-
thumbnail: info.media.image,
60+
image: info.media.image,
6161
} : null,
6262
};
6363
ytdlCache.push(id, meta);
@@ -119,7 +119,7 @@ export default {
119119
return {
120120
user: {
121121
url: userUrl,
122-
thumbnail: item.channelThumbnail.thumbnails[0].url,
122+
image: item.channelThumbnail.thumbnails[0].url,
123123
name: user.text,
124124
verified: item.ownerBadges && item.ownerBadges.some((badge) => {
125125
badge.tooltip == 'Verified';

popup/popup.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ const renderGroupVideo = (group, video) => {
206206
href: user.url || '#',
207207
target: '_blank',
208208
}, [
209-
user.thumbnail ?
210-
m('img.lazy', { 'data-src': user.thumbnail }) : null,
209+
user.image ?
210+
m('img.lazy', { 'data-src': user.image }) : null,
211211
m('span.name', user.name),
212212
user.verified ?
213213
m('span.verified', { 'data-title': 'Verified' }) : null,
@@ -239,13 +239,14 @@ const renderGroupVideo = (group, video) => {
239239
}),
240240
video.game ?
241241
m('a.game', {
242-
href: 'https://www.twitch.tv/directory/game/' +
243-
encodeURIComponent(video.game) + '/videos/week',
244-
'data-title': video.game,
242+
href: video.game.url || 'https://www.twitch.tv/directory/game/' +
243+
encodeURIComponent(video.game.name) + '/videos/week',
244+
'data-title': video.game.name,
245245
target: '_blank',
246246
}, m('img.lazy', {
247-
'data-src': 'http://static-cdn.jtvnw.net/ttv-boxart/' +
248-
encodeURIComponent(video.game) + '-138x190.jpg',
247+
'data-src': video.game.image ||
248+
'http://static-cdn.jtvnw.net/ttv-boxart/' +
249+
encodeURIComponent(video.game.name) + '-138x190.jpg',
249250
})) : null,
250251
video.length && m('span.length', formatVideoLength(video.length)),
251252
openedVideo && openedVideo.playing && m('span.queue', {

0 commit comments

Comments
 (0)