mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-24 07:13:02 +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": {
|
||||
"message": "Stops counting your likes and dislikes."
|
||||
},
|
||||
"textTempUnavailable": {
|
||||
"message": "temporarily unavailable"
|
||||
},
|
||||
"textUpdate": {
|
||||
"message": "update to"
|
||||
},
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
"textSettingsHover": {
|
||||
"message": "Arrête de compter les likes et les dislikes mis sur les vidéos."
|
||||
},
|
||||
"textTempUnavailable": {
|
||||
"message": "temporairement indisponible"
|
||||
},
|
||||
"textUpdate": {
|
||||
"message": "mettre à jour vers"
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
getColorFromTheme,
|
||||
} from "./utils";
|
||||
import { sendVideoIds } from "./events";
|
||||
import { localize } from "./utils";
|
||||
|
||||
//TODO: Do not duplicate here and in ryd.background.js
|
||||
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) {
|
||||
storedData.previousState = isVideoDisliked()
|
||||
? DISLIKED_STATE
|
||||
@@ -144,8 +152,12 @@ async function setState(storedData) {
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
if (!response.ok) displayError(response.error);
|
||||
return response;
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.catch();
|
||||
.catch(displayError);
|
||||
cLog("response from api:");
|
||||
cLog(JSON.stringify(response));
|
||||
likesDisabledState =
|
||||
|
||||
@@ -29,6 +29,10 @@ function numberFormat(numberState) {
|
||||
);
|
||||
}
|
||||
|
||||
function localize(localeString) {
|
||||
return chrome.i18n.getMessage(localeString);
|
||||
}
|
||||
|
||||
function getNumberFormatter(optionSelect) {
|
||||
let formatterNotation;
|
||||
let formatterCompactDisplay;
|
||||
@@ -151,4 +155,5 @@ export {
|
||||
isVideoLoaded,
|
||||
cLog,
|
||||
getColorFromTheme,
|
||||
localize,
|
||||
};
|
||||
Reference in new issue
Block a user