diff options
author | Ajay <[email protected]> | 2023-05-09 22:12:15 -0400 |
---|---|---|
committer | Ajay <[email protected]> | 2023-05-09 22:12:15 -0400 |
commit | 92fabdf37a9f8d1e64616dadd245ff8449f629e6 (patch) | |
tree | b080ec3254a9cfb0737ec92ab207aba0b84f4bac | |
parent | 33d098d78a125b10199f0b088583e17746434718 (diff) | |
download | SponsorBlock-92fabdf37a9f8d1e64616dadd245ff8449f629e6.tar.gz SponsorBlock-92fabdf37a9f8d1e64616dadd245ff8449f629e6.zip |
Move more funcs to shared lib
-rw-r--r-- | package-lock.json | 14 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/components/CategoryPillComponent.tsx | 4 | ||||
-rw-r--r-- | src/components/ChapterVoteComponent.tsx | 4 | ||||
-rw-r--r-- | src/content.ts | 6 | ||||
-rw-r--r-- | src/popup.ts | 7 | ||||
-rw-r--r-- | src/utils/genericUtils.ts | 22 |
7 files changed, 18 insertions, 41 deletions
diff --git a/package-lock.json b/package-lock.json index 009225e9..e9a0d4a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 0d7e7622..04fb6921 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/components/CategoryPillComponent.tsx b/src/components/CategoryPillComponent.tsx index e2bbb0dd..adcc7d4a 100644 --- a/src/components/CategoryPillComponent.tsx +++ b/src/components/CategoryPillComponent.tsx @@ -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)); } } } diff --git a/src/components/ChapterVoteComponent.tsx b/src/components/ChapterVoteComponent.tsx index 73f14d06..1c37a200 100644 --- a/src/components/ChapterVoteComponent.tsx +++ b/src/components/ChapterVoteComponent.tsx @@ -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)); } } } diff --git a/src/content.ts b/src/content.ts index a716eddf..1d8b1b9c 100644 --- a/src/content.ts +++ b/src/content.ts @@ -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)); } } } diff --git a/src/popup.ts b/src/popup.ts index 526db59f..dc6713e5 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -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); } diff --git a/src/utils/genericUtils.ts b/src/utils/genericUtils.ts index 7902b6b6..032539c2 100644 --- a/src/utils/genericUtils.ts +++ b/src/utils/genericUtils.ts @@ -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 }
\ No newline at end of file |