mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-03 19:31:20 +01:00
Display 'temporarily unavailable' when the API can't be reached
This commit is contained in:
1 parent
2e6ed5298b
commit
1d2f89a38c
4 files changed
+24
-1
No files matched your search
@@ -29,6 +29,9 @@
|
|||||||
"textSettingsHover": {
|
"textSettingsHover": {
|
||||||
"message": "Stops counting your likes and dislikes."
|
"message": "Stops counting your likes and dislikes."
|
||||||
},
|
},
|
||||||
|
"textTempUnavailable": {
|
||||||
|
"message": "temporarily unavailable"
|
||||||
|
},
|
||||||
"textUpdate": {
|
"textUpdate": {
|
||||||
"message": "update to"
|
"message": "update to"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -29,6 +29,9 @@
|
|||||||
"textSettingsHover": {
|
"textSettingsHover": {
|
||||||
"message": "Arrête de compter les likes et les dislikes mis sur les vidéos."
|
"message": "Arrête de compter les likes et les dislikes mis sur les vidéos."
|
||||||
},
|
},
|
||||||
|
"textTempUnavailable": {
|
||||||
|
"message": "temporairement indisponible"
|
||||||
|
},
|
||||||
"textUpdate": {
|
"textUpdate": {
|
||||||
"message": "mettre à jour vers"
|
"message": "mettre à jour vers"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
getColorFromTheme,
|
getColorFromTheme,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { sendVideoIds } from "./events";
|
import { sendVideoIds } from "./events";
|
||||||
|
import { localize } from "./utils";
|
||||||
|
|
||||||
//TODO: Do not duplicate here and in ryd.background.js
|
//TODO: Do not duplicate here and in ryd.background.js
|
||||||
const apiUrl = "https://returnyoutubedislikeapi.com";
|
const apiUrl = "https://returnyoutubedislikeapi.com";
|
||||||
@@ -124,6 +125,13 @@ function processResponse(response, storedData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tells the user if the API is down
|
||||||
|
function displayError(error) {
|
||||||
|
getButtons().children[1].querySelector("#text").innerText = localize(
|
||||||
|
"textTempUnavailable"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function setState(storedData) {
|
async function setState(storedData) {
|
||||||
storedData.previousState = isVideoDisliked()
|
storedData.previousState = isVideoDisliked()
|
||||||
? DISLIKED_STATE
|
? DISLIKED_STATE
|
||||||
@@ -144,8 +152,12 @@ async function setState(storedData) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
.then((response) => {
|
||||||
|
if (!response.ok) displayError(response.error);
|
||||||
|
return response;
|
||||||
|
})
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.catch();
|
.catch(displayError);
|
||||||
cLog("response from api:");
|
cLog("response from api:");
|
||||||
cLog(JSON.stringify(response));
|
cLog(JSON.stringify(response));
|
||||||
likesDisabledState =
|
likesDisabledState =
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ function numberFormat(numberState) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function localize(localeString) {
|
||||||
|
return chrome.i18n.getMessage(localeString);
|
||||||
|
}
|
||||||
|
|
||||||
function getNumberFormatter(optionSelect) {
|
function getNumberFormatter(optionSelect) {
|
||||||
let formatterNotation;
|
let formatterNotation;
|
||||||
let formatterCompactDisplay;
|
let formatterCompactDisplay;
|
||||||
@@ -151,4 +155,5 @@ export {
|
|||||||
isVideoLoaded,
|
isVideoLoaded,
|
||||||
cLog,
|
cLog,
|
||||||
getColorFromTheme,
|
getColorFromTheme,
|
||||||
|
localize,
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user