mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 01:01:55 +01:00
Move more funcs to shared lib
This commit is contained in:
parent
33d098d78a
commit
92fabdf37a
7 changed files with 18 additions and 41 deletions
14
package-lock.json
generated
14
package-lock.json
generated
|
@ -27,7 +27,7 @@
|
|||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@ajayyy/maze-utils": "1.1.26",
|
||||
"@ajayyy/maze-utils": "1.1.27",
|
||||
"content-scripts-register-polyfill": "^4.0.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
|
@ -67,9 +67,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@ajayyy/maze-utils": {
|
||||
"version": "1.1.26",
|
||||
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.26.tgz",
|
||||
"integrity": "sha512-PlqDsdbqeG1qQa1ZGgO5d7N8VeuaKKiR7gzUq0m+ROYcRhQ4k66gxF9Lumhbq6X9B8o0pzNwTu9eT3LFyyfsVw==",
|
||||
"version": "1.1.27",
|
||||
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.27.tgz",
|
||||
"integrity": "sha512-z/n5Uz9WM1z4eMN8XxaCTbGwMg60sF1ciAmqdf0zGkJpCNjp0g0zhQlwI6eJHirbNWSeKNVU1TuNpH91POZgDQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
|
@ -13602,9 +13602,9 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@ajayyy/maze-utils": {
|
||||
"version": "1.1.26",
|
||||
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.26.tgz",
|
||||
"integrity": "sha512-PlqDsdbqeG1qQa1ZGgO5d7N8VeuaKKiR7gzUq0m+ROYcRhQ4k66gxF9Lumhbq6X9B8o0pzNwTu9eT3LFyyfsVw=="
|
||||
"version": "1.1.27",
|
||||
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.27.tgz",
|
||||
"integrity": "sha512-z/n5Uz9WM1z4eMN8XxaCTbGwMg60sF1ciAmqdf0zGkJpCNjp0g0zhQlwI6eJHirbNWSeKNVU1TuNpH91POZgDQ=="
|
||||
},
|
||||
"@ampproject/remapping": {
|
||||
"version": "2.2.0",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"description": "",
|
||||
"main": "background.js",
|
||||
"dependencies": {
|
||||
"@ajayyy/maze-utils": "1.1.26",
|
||||
"@ajayyy/maze-utils": "1.1.27",
|
||||
"content-scripts-register-polyfill": "^4.0.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
|
|
|
@ -7,8 +7,8 @@ import ThumbsDownSvg from "../svg-icons/thumbs_down_svg";
|
|||
import { downvoteButtonColor, SkipNoticeAction } from "../utils/noticeUtils";
|
||||
import { VoteResponse } from "../messageTypes";
|
||||
import { AnimationUtils } from "../utils/animationUtils";
|
||||
import { GenericUtils } from "../utils/genericUtils";
|
||||
import { Tooltip } from "../render/Tooltip";
|
||||
import { getErrorMessage } from "@ajayyy/maze-utils/lib/formating";
|
||||
|
||||
export interface CategoryPillProps {
|
||||
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
||||
|
@ -109,7 +109,7 @@ class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryP
|
|||
show: type === 1
|
||||
});
|
||||
} else if (response.statusCode !== 403) {
|
||||
alert(GenericUtils.getErrorMessage(response.statusCode, response.responseText));
|
||||
alert(getErrorMessage(response.statusCode, response.responseText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ import ThumbsDownSvg from "../svg-icons/thumbs_down_svg";
|
|||
import { downvoteButtonColor, SkipNoticeAction } from "../utils/noticeUtils";
|
||||
import { VoteResponse } from "../messageTypes";
|
||||
import { AnimationUtils } from "../utils/animationUtils";
|
||||
import { GenericUtils } from "../utils/genericUtils";
|
||||
import { Tooltip } from "../render/Tooltip";
|
||||
import { getErrorMessage } from "@ajayyy/maze-utils/lib/formating";
|
||||
|
||||
export interface ChapterVoteProps {
|
||||
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
||||
|
@ -124,7 +124,7 @@ class ChapterVoteComponent extends React.Component<ChapterVoteProps, ChapterVote
|
|||
show: type === 1
|
||||
});
|
||||
} else if (response.statusCode !== 403) {
|
||||
alert(GenericUtils.getErrorMessage(response.statusCode, response.responseText));
|
||||
alert(getErrorMessage(response.statusCode, response.responseText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import { importTimes } from "./utils/exporter";
|
|||
import { ChapterVote } from "./render/ChapterVote";
|
||||
import { openWarningDialog } from "./utils/warnings";
|
||||
import { isFirefoxOrSafari, waitFor } from "@ajayyy/maze-utils";
|
||||
import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating";
|
||||
import { getErrorMessage, getFormattedTime } from "@ajayyy/maze-utils/lib/formating";
|
||||
import { getChannelIDInfo, getVideo, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube } from "@ajayyy/maze-utils/lib/video";
|
||||
import { Keybind, StorageChangesObject, isSafari, keybindEquals } from "@ajayyy/maze-utils/lib/config";
|
||||
import { findValidElement } from "@ajayyy/maze-utils/lib/dom"
|
||||
|
@ -2016,7 +2016,7 @@ async function vote(type: number, UUID: SegmentUUID, category?: Category, skipNo
|
|||
if (response.statusCode === 403 && response.responseText.startsWith("Vote rejected due to a warning from a moderator.")) {
|
||||
openWarningDialog(skipNoticeContentContainer);
|
||||
} else {
|
||||
skipNotice.setNoticeInfoMessage.bind(skipNotice)(GenericUtils.getErrorMessage(response.statusCode, response.responseText))
|
||||
skipNotice.setNoticeInfoMessage.bind(skipNotice)(getErrorMessage(response.statusCode, response.responseText))
|
||||
}
|
||||
|
||||
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
|
||||
|
@ -2206,7 +2206,7 @@ async function sendSubmitMessage() {
|
|||
if (response.status === 403 && response.responseText.startsWith("Submission rejected due to a warning from a moderator.")) {
|
||||
openWarningDialog(skipNoticeContentContainer);
|
||||
} else {
|
||||
alert(GenericUtils.getErrorMessage(response.status, response.responseText));
|
||||
alert(getErrorMessage(response.status, response.responseText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,11 @@ import {
|
|||
} from "./messageTypes";
|
||||
import { showDonationLink } from "./utils/configUtils";
|
||||
import { AnimationUtils } from "./utils/animationUtils";
|
||||
import { GenericUtils } from "./utils/genericUtils";
|
||||
import { shortCategoryName } from "./utils/categoryUtils";
|
||||
import { localizeHtmlPage } from "@ajayyy/maze-utils/lib/setup";
|
||||
import { exportTimes } from "./utils/exporter";
|
||||
import GenericNotice from "./render/GenericNotice";
|
||||
import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating";
|
||||
import { getErrorMessage, getFormattedTime } from "@ajayyy/maze-utils/lib/formating";
|
||||
import { StorageChangesObject } from "@ajayyy/maze-utils/lib/config";
|
||||
import { getHash } from "@ajayyy/maze-utils/lib/hash";
|
||||
|
||||
|
@ -815,7 +814,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||
|
||||
PageElements.sponsorTimesContributionsContainer.classList.remove("hidden");
|
||||
} else {
|
||||
PageElements.setUsernameStatus.innerText = GenericUtils.getErrorMessage(response.status, response.responseText);
|
||||
PageElements.setUsernameStatus.innerText = getErrorMessage(response.status, response.responseText);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -868,7 +867,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||
//success (treat rate limits as a success)
|
||||
addVoteMessage(chrome.i18n.getMessage("voted"), UUID);
|
||||
} else if (response.successType == -1) {
|
||||
addVoteMessage(GenericUtils.getErrorMessage(response.statusCode, response.responseText), UUID);
|
||||
addVoteMessage(getErrorMessage(response.statusCode, response.responseText), UUID);
|
||||
}
|
||||
setTimeout(() => removeVoteMessage(UUID), 1500);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue