mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 06:27:14 +03:00
Move more funcs to shared lib
This commit is contained in:
@@ -1,24 +1,3 @@
|
||||
/**
|
||||
* Gets the error message in a nice string
|
||||
*
|
||||
* @param {int} statusCode
|
||||
* @returns {string} errorMessage
|
||||
*/
|
||||
function getErrorMessage(statusCode: number, responseText: string): string {
|
||||
const postFix = ((responseText && !(responseText.includes(`cf-wrapper`) || responseText.includes("<!DOCTYPE html>"))) ? "\n\n" + responseText : "");
|
||||
// display response body for 4xx
|
||||
if([400, 429, 409, 0].includes(statusCode)) {
|
||||
return chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode + postFix;
|
||||
} else if (statusCode >= 500 && statusCode <= 599) {
|
||||
// 503 == 502
|
||||
if (statusCode == 503) statusCode = 502;
|
||||
return chrome.i18n.getMessage(statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + statusCode
|
||||
+ "\n\n" + chrome.i18n.getMessage("statusReminder");
|
||||
} else {
|
||||
return chrome.i18n.getMessage("connectionError") + statusCode + postFix;
|
||||
}
|
||||
}
|
||||
|
||||
/* Gets percieved luminance of a color */
|
||||
function getLuminance(color: string): number {
|
||||
const {r, g, b} = hexToRgb(color);
|
||||
@@ -50,7 +29,6 @@ function indexesOf<T>(array: T[], value: T): number[] {
|
||||
}
|
||||
|
||||
export const GenericUtils = {
|
||||
getErrorMessage,
|
||||
getLuminance,
|
||||
indexesOf
|
||||
}
|
||||
Reference in New Issue
Block a user