aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js')
-rw-r--r--src/js/plugins/youtube.js6
-rw-r--r--src/js/utils.js21
2 files changed, 13 insertions, 14 deletions
diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js
index 429e9eb8..6b4a54bd 100644
--- a/src/js/plugins/youtube.js
+++ b/src/js/plugins/youtube.js
@@ -59,10 +59,10 @@ const youtube = {
if (utils.is.string(key) && !utils.is.empty(key)) {
const url = `https://www.googleapis.com/youtube/v3/videos?id=${videoId}&key=${key}&fields=items(snippet(title))&part=snippet`;
- fetch(url)
- .then(response => (response.ok ? response.json() : null))
+ utils
+ .fetch(url)
.then(result => {
- if (result !== null && utils.is.object(result)) {
+ if (utils.is.object(result)) {
this.config.title = result.items[0].snippet.title;
ui.setTitle.call(this);
}
diff --git a/src/js/utils.js b/src/js/utils.js
index 03e51f97..3e9f06ff 100644
--- a/src/js/utils.js
+++ b/src/js/utils.js
@@ -93,11 +93,11 @@ const utils = {
return;
}
- request.addEventListener('readystatechange', () => {
- if (request.readyState === 4 && request.status === 200) {
+ request.addEventListener('load', () => {
+ try {
+ resolve(JSON.parse(request.responseText));
+ } catch(e) {
resolve(request.responseText);
- } else if (request.status === 0) {
- throw new Error(request.statusText);
}
});
@@ -206,11 +206,10 @@ const utils = {
}
// Get the sprite
- utils.fetch(url)
- .then(text => {
- console.log(text);
-
- if (text === null) {
+ utils
+ .fetch(url)
+ .then(result => {
+ if (utils.is.empty(result)) {
return;
}
@@ -218,12 +217,12 @@ const utils = {
window.localStorage.setItem(
prefix + id,
JSON.stringify({
- content: text,
+ content: result,
}),
);
}
- updateSprite.call(container, text);
+ updateSprite.call(container, result);
})
.catch(() => {});
}