mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 22:47:18 +03:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
522a04eecb | ||
|
|
d8dfbef1a7 | ||
|
|
60ea7190f9 | ||
|
|
804870f18a | ||
|
|
7c302af207 | ||
|
|
2cc1dcc6fd | ||
|
|
31cc4b4960 | ||
|
|
af86534992 | ||
|
|
0f9122aa1c | ||
|
|
d0e35032a5 | ||
|
|
acf26d3127 | ||
|
|
80c67d8340 |
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@@ -30,7 +30,7 @@ jobs:
|
||||
name: ChromeExtension
|
||||
path: dist
|
||||
- run: mkdir ./builds
|
||||
- uses: montudor/action-zip@v1
|
||||
- uses: montudor/action-zip@0852c26906e00f8a315c704958823928d8018b28
|
||||
with:
|
||||
args: zip -qq -r ./builds/ChromeExtension.zip ./dist
|
||||
|
||||
@@ -41,7 +41,7 @@ jobs:
|
||||
with:
|
||||
name: FirefoxExtension
|
||||
path: dist
|
||||
- uses: montudor/action-zip@v1
|
||||
- uses: montudor/action-zip@0852c26906e00f8a315c704958823928d8018b28
|
||||
with:
|
||||
args: zip -qq -r ./builds/FirefoxExtension.zip ./dist
|
||||
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
with:
|
||||
name: ChromeExtensionBeta
|
||||
path: dist
|
||||
- uses: montudor/action-zip@v1
|
||||
- uses: montudor/action-zip@0852c26906e00f8a315c704958823928d8018b28
|
||||
with:
|
||||
args: zip -qq -r ./builds/ChromeExtensionBeta.zip ./dist
|
||||
|
||||
@@ -62,7 +62,7 @@ jobs:
|
||||
with:
|
||||
name: FirefoxExtensionBeta
|
||||
path: dist
|
||||
- uses: montudor/action-zip@v1
|
||||
- uses: montudor/action-zip@0852c26906e00f8a315c704958823928d8018b28
|
||||
with:
|
||||
args: zip -qq -r ./builds/FirefoxExtensionBeta.zip ./dist
|
||||
|
||||
|
||||
2
.github/workflows/take-action.yml
vendored
2
.github/workflows/take-action.yml
vendored
@@ -9,6 +9,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: take the issue
|
||||
uses: bdougie/take-action@main
|
||||
uses: bdougie/take-action@28b86cd8d25593f037406ecbf96082db2836e928
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
|
||||
2
.github/workflows/update-oss-attribution.yml
vendored
2
.github/workflows/update-oss-attribution.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
||||
mv ./oss-attribution/attribution.txt ./public/oss-attribution/attribution.txt
|
||||
|
||||
- name: Create pull request to update list
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
uses: peter-evans/create-pull-request@923ad837f191474af6b1721408744feb989a4c27
|
||||
with:
|
||||
commit-message: Update OSS Attribution
|
||||
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
||||
|
||||
2
.github/workflows/updateInvidous.yml
vendored
2
.github/workflows/updateInvidous.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
run: npm run ci:invidious
|
||||
|
||||
- name: Create pull request to update list
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
uses: peter-evans/create-pull-request@923ad837f191474af6b1721408744feb989a4c27
|
||||
with:
|
||||
commit-message: Update Invidious List
|
||||
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "__MSG_fullName__",
|
||||
"short_name": "SponsorBlock",
|
||||
"version": "4.6.4",
|
||||
"version": "4.7.1",
|
||||
"default_locale": "en",
|
||||
"description": "__MSG_Description__",
|
||||
"homepage_url": "https://sponsor.ajay.app",
|
||||
|
||||
13671
package-lock.json
generated
13671
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@@ -8,33 +8,33 @@
|
||||
"react-dom": "^17.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chrome": "^0.0.188",
|
||||
"@types/chrome": "^0.0.193",
|
||||
"@types/firefox-webext-browser": "^94.0.1",
|
||||
"@types/jest": "^27.5.1",
|
||||
"@types/react": "^17.0.43",
|
||||
"@types/react-dom": "^17.0.14",
|
||||
"@types/jest": "^28.1.5",
|
||||
"@types/react": "^17.0.47",
|
||||
"@types/react-dom": "^17.0.17",
|
||||
"@types/selenium-webdriver": "^4.1.1",
|
||||
"@types/wicg-mediasession": "^1.1.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
||||
"@typescript-eslint/parser": "^5.26.0",
|
||||
"chromedriver": "^101.0.0",
|
||||
"concurrently": "^7.2.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.30.6",
|
||||
"@typescript-eslint/parser": "^5.30.6",
|
||||
"chromedriver": "^103.0.0",
|
||||
"concurrently": "^7.2.2",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"eslint": "^8.16.0",
|
||||
"eslint-plugin-react": "^7.30.0",
|
||||
"fork-ts-checker-webpack-plugin": "^7.2.11",
|
||||
"jest": "^28.1.0",
|
||||
"eslint": "^8.19.0",
|
||||
"eslint-plugin-react": "^7.30.1",
|
||||
"fork-ts-checker-webpack-plugin": "^7.2.12",
|
||||
"jest": "^28.1.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"schema-utils": "^4.0.0",
|
||||
"selenium-webdriver": "^4.2.0",
|
||||
"selenium-webdriver": "^4.3.1",
|
||||
"speed-measure-webpack-plugin": "^1.5.0",
|
||||
"ts-jest": "^28.0.3",
|
||||
"ts-loader": "^9.3.0",
|
||||
"ts-node": "^10.8.0",
|
||||
"ts-jest": "^28.0.5",
|
||||
"ts-loader": "^9.3.1",
|
||||
"ts-node": "^10.8.2",
|
||||
"typescript": "4.7",
|
||||
"web-ext": "^6.8.0",
|
||||
"webpack": "^5.72.1",
|
||||
"webpack-cli": "^4.9.2",
|
||||
"web-ext": "^7.1.1",
|
||||
"webpack": "^5.73.0",
|
||||
"webpack-cli": "^4.10.0",
|
||||
"webpack-merge": "^5.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -867,11 +867,19 @@
|
||||
"message": "Hide forever"
|
||||
},
|
||||
"warningChatInfo": {
|
||||
"message": "You got a warning and cannot submit segments temporarily. This means that we noticed you were making some common mistakes that are not malicious, please just confirm that you understand the rules and we will remove the warning. You can also join this chat using discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app"
|
||||
"message": "We noticed you were making some common mistakes that are not malicious"
|
||||
},
|
||||
"voteRejectedWarning": {
|
||||
"message": "Vote rejected due to a warning. Click to open a chat to resolve it, or come back later when you have time.",
|
||||
"description": "This is an integrated chat panel that will appearing allowing them to talk to the Discord/Matrix chat without leaving their browser."
|
||||
"warningTitle": {
|
||||
"message": "You got a warning"
|
||||
},
|
||||
"questionButton": {
|
||||
"message": "I have a question"
|
||||
},
|
||||
"warningConfirmButton": {
|
||||
"message": "I understand the reason"
|
||||
},
|
||||
"warningError": {
|
||||
"message": "Error when trying to acknowledge warning:"
|
||||
},
|
||||
"Donate": {
|
||||
"message": "Donate"
|
||||
|
||||
@@ -351,6 +351,7 @@
|
||||
.sponsorTimesInfoMessage {
|
||||
font-size: 13.3333px;
|
||||
color: rgb(235, 235, 235);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.sb-guidelines-notice .sponsorTimesInfoMessage td {
|
||||
@@ -543,17 +544,6 @@ input::-webkit-inner-spin-button {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.sbChatNotice iframe {
|
||||
height: 32px;
|
||||
cursor: pointer;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.sbChatClose {
|
||||
height: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.skipButtonControlBarContainer {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Registration } from "./types";
|
||||
window.SB = Config;
|
||||
|
||||
import Utils from "./utils";
|
||||
import { GenericUtils } from "./utils/genericUtils";
|
||||
const utils = new Utils({
|
||||
registerFirefoxContentScript,
|
||||
unregisterFirefoxContentScript
|
||||
@@ -205,7 +206,7 @@ async function asyncRequestToServer(type: string, address: string, data = {}) {
|
||||
async function sendRequestToCustomServer(type: string, url: string, data = {}) {
|
||||
// If GET, convert JSON to parameters
|
||||
if (type.toLowerCase() === "get") {
|
||||
url = utils.objectToURI(url, data, true);
|
||||
url = GenericUtils.objectToURI(url, data, true);
|
||||
|
||||
data = null;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,9 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
|
||||
let option: CategorySkipOption;
|
||||
|
||||
switch (event.target.value) {
|
||||
case "disable":
|
||||
case "disable":
|
||||
Config.config.categorySelections = Config.config.categorySelections.filter(
|
||||
categorySelection => categorySelection.name !== this.props.category);
|
||||
return;
|
||||
case "showOverlay":
|
||||
option = CategorySkipOption.ShowOverlay;
|
||||
|
||||
@@ -36,12 +36,31 @@ class NoticeTextSelectionComponent extends React.Component<NoticeTextSelectionPr
|
||||
: null}
|
||||
|
||||
<span>
|
||||
{this.props.text}
|
||||
{this.getTextElements(this.props.text)}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
private getTextElements(text: string): Array<string | React.ReactElement> {
|
||||
const elements: Array<string | React.ReactElement> = [];
|
||||
const textParts = text.split(/(?=\s+)/);
|
||||
for (const textPart of textParts) {
|
||||
if (textPart.match(/^\s*http/)) {
|
||||
elements.push(
|
||||
<a href={textPart} target="_blank" rel="noreferrer">
|
||||
{textPart}
|
||||
</a>
|
||||
);
|
||||
} else {
|
||||
elements.push(textPart);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
|
||||
export default NoticeTextSelectionComponent;
|
||||
@@ -10,7 +10,6 @@ import SkipNotice from "./render/SkipNotice";
|
||||
import SkipNoticeComponent from "./components/SkipNoticeComponent";
|
||||
import SubmissionNotice from "./render/SubmissionNotice";
|
||||
import { Message, MessageResponse, VoteResponse } from "./messageTypes";
|
||||
import * as Chat from "./js-components/chat";
|
||||
import { SkipButtonControlBar } from "./js-components/skipButtonControlBar";
|
||||
import { getStartTimeFromUrl } from "./utils/urlParser";
|
||||
import { findValidElement, getControls, getHashParams, isVisible } from "./utils/pageUtils";
|
||||
@@ -19,6 +18,7 @@ import { CategoryPill } from "./render/CategoryPill";
|
||||
import { AnimationUtils } from "./utils/animationUtils";
|
||||
import { GenericUtils } from "./utils/genericUtils";
|
||||
import { logDebug } from "./utils/logger";
|
||||
import { openWarningDialog } from "./utils/warnings";
|
||||
|
||||
// Hack to get the CSS loaded on permission-based sites (Invidious)
|
||||
utils.wait(() => Config.config !== null, 5000, 10).then(addCSS);
|
||||
@@ -508,7 +508,16 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
||||
}
|
||||
lastTimeFromWaitingEvent = null;
|
||||
|
||||
if (videoMuted && !inMuteSegment(currentTime)) {
|
||||
const skipInfo = getNextSkipIndex(currentTime, includeIntersectingSegments, includeNonIntersectingSegments);
|
||||
|
||||
const currentSkip = skipInfo.array[skipInfo.index];
|
||||
const skipTime: number[] = [currentSkip?.scheduledTime, skipInfo.array[skipInfo.endIndex]?.segment[1]];
|
||||
const timeUntilSponsor = skipTime?.[0] - currentTime;
|
||||
const videoID = sponsorVideoID;
|
||||
const skipBuffer = 0.003;
|
||||
|
||||
if (videoMuted && !inMuteSegment(currentTime, skipInfo.index !== -1
|
||||
&& timeUntilSponsor < skipBuffer && shouldAutoSkip(currentSkip))) {
|
||||
video.muted = false;
|
||||
videoMuted = false;
|
||||
|
||||
@@ -518,22 +527,15 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
||||
}
|
||||
}
|
||||
|
||||
logDebug(`Ready to start skipping: ${skipInfo.index} at ${currentTime}`);
|
||||
if (skipInfo.index === -1) return;
|
||||
|
||||
if (Config.config.disableSkipping || channelWhitelisted || (channelIDInfo.status === ChannelIDStatus.Fetching && Config.config.forceChannelCheck)){
|
||||
return;
|
||||
}
|
||||
|
||||
if (incorrectVideoCheck()) return;
|
||||
|
||||
const skipInfo = getNextSkipIndex(currentTime, includeIntersectingSegments, includeNonIntersectingSegments);
|
||||
|
||||
logDebug(`Ready to start skipping: ${skipInfo.index} at ${currentTime}`);
|
||||
if (skipInfo.index === -1) return;
|
||||
|
||||
const currentSkip = skipInfo.array[skipInfo.index];
|
||||
const skipTime: number[] = [currentSkip.scheduledTime, skipInfo.array[skipInfo.endIndex].segment[1]];
|
||||
const timeUntilSponsor = skipTime[0] - currentTime;
|
||||
const videoID = sponsorVideoID;
|
||||
|
||||
// Find all indexes in between the start and end
|
||||
let skippingSegments = [skipInfo.array[skipInfo.index]];
|
||||
if (skipInfo.index !== skipInfo.endIndex) {
|
||||
@@ -552,7 +554,6 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
||||
// Don't skip if this category should not be skipped
|
||||
if (!shouldSkip(currentSkip) && !sponsorTimesSubmitting?.some((segment) => segment.segment === currentSkip.segment)) return;
|
||||
|
||||
const skipBuffer = 0.003;
|
||||
const skippingFunction = (forceVideoTime?: number) => {
|
||||
let forcedSkipTime: number = null;
|
||||
let forcedIncludeIntersectingSegments = false;
|
||||
@@ -639,8 +640,10 @@ function getVirtualTime(): number {
|
||||
}
|
||||
}
|
||||
|
||||
function inMuteSegment(currentTime: number): boolean {
|
||||
const checkFunction = (segment) => segment.actionType === ActionType.Mute && segment.segment[0] <= currentTime && segment.segment[1] > currentTime;
|
||||
function inMuteSegment(currentTime: number, includeOverlap: boolean): boolean {
|
||||
const checkFunction = (segment) => segment.actionType === ActionType.Mute
|
||||
&& segment.segment[0] <= currentTime
|
||||
&& (segment.segment[1] > currentTime || (includeOverlap && segment.segment[1] + 0.02 > currentTime));
|
||||
return sponsorTimes?.some(checkFunction) || sponsorTimesSubmitting.some(checkFunction);
|
||||
}
|
||||
|
||||
@@ -1041,8 +1044,8 @@ function startSkipScheduleCheckingForStartSponsors() {
|
||||
}
|
||||
}
|
||||
|
||||
function getYouTubeVideoID(document: Document): string | boolean {
|
||||
const url = document.URL;
|
||||
function getYouTubeVideoID(document: Document, url?: string): string | boolean {
|
||||
url ||= document.URL;
|
||||
// clips should never skip, going from clip to full video has no indications.
|
||||
if (url.includes("youtube.com/clip/")) return false;
|
||||
// skip to document and don't hide if on /embed/
|
||||
@@ -1209,7 +1212,7 @@ function getNextSkipIndex(currentTime: number, includeIntersectingSegments: bool
|
||||
|
||||
const autoSkipSorter = (segment: ScheduledTime) => {
|
||||
const skipOption = utils.getCategorySelection(segment.category)?.option;
|
||||
if (skipOption === CategorySkipOption.AutoSkip
|
||||
if ((skipOption === CategorySkipOption.AutoSkip || shouldAutoSkip(segment))
|
||||
&& segment.actionType === ActionType.Skip) {
|
||||
return 0;
|
||||
} else if (skipOption !== CategorySkipOption.ShowOverlay) {
|
||||
@@ -1834,10 +1837,7 @@ async function vote(type: number, UUID: SegmentUUID, category?: Category, skipNo
|
||||
skipNotice.afterVote.bind(skipNotice)(utils.getSponsorTimeFromUUID(sponsorTimes, UUID), type, category);
|
||||
} else if (response.successType == -1) {
|
||||
if (response.statusCode === 403 && response.responseText.startsWith("Vote rejected due to a warning from a moderator.")) {
|
||||
skipNotice.setNoticeInfoMessageWithOnClick.bind(skipNotice)(() => {
|
||||
Chat.openWarningChat(response.responseText);
|
||||
skipNotice.closeListener.call(skipNotice);
|
||||
}, chrome.i18n.getMessage("voteRejectedWarning"));
|
||||
openWarningDialog(skipNoticeContentContainer);
|
||||
} else {
|
||||
skipNotice.setNoticeInfoMessage.bind(skipNotice)(GenericUtils.getErrorMessage(response.statusCode, response.responseText))
|
||||
}
|
||||
@@ -2025,7 +2025,7 @@ async function sendSubmitMessage() {
|
||||
playerButtons.submit.image.src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker.svg");
|
||||
|
||||
if (response.status === 403 && response.responseText.startsWith("Submission rejected due to a warning from a moderator.")) {
|
||||
Chat.openWarningChat(response.responseText);
|
||||
openWarningDialog(skipNoticeContentContainer);
|
||||
} else {
|
||||
alert(GenericUtils.getErrorMessage(response.status, response.responseText));
|
||||
}
|
||||
@@ -2205,7 +2205,8 @@ function checkForPreloadedSegment() {
|
||||
const navigationApiAvailable = "navigation" in window;
|
||||
if (navigationApiAvailable) {
|
||||
// TODO: Remove type cast once type declarations are updated
|
||||
(window as unknown as { navigation: EventTarget }).navigation.addEventListener("navigate", () => videoIDChange(getYouTubeVideoID(document)));
|
||||
(window as unknown as { navigation: EventTarget }).navigation.addEventListener("navigate", (e) =>
|
||||
videoIDChange(getYouTubeVideoID(document, (e as unknown as Record<string, Record<string, string>>).destination.url)));
|
||||
}
|
||||
|
||||
// Record availability of Navigation API
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import Config from "../config";
|
||||
import Utils from "../utils";
|
||||
const utils = new Utils();
|
||||
|
||||
export interface ChatConfig {
|
||||
displayName: string,
|
||||
composerInitialValue?: string,
|
||||
customDescription?: string
|
||||
}
|
||||
|
||||
export function openChat(config: ChatConfig): void {
|
||||
const chat = document.createElement("div");
|
||||
chat.classList.add("sbChatNotice");
|
||||
chat.style.zIndex = "2000";
|
||||
|
||||
const iframe= document.createElement("iframe");
|
||||
iframe.src = "https://chat.sponsor.ajay.app/#" + utils.objectToURI("", config, false);
|
||||
chat.appendChild(iframe);
|
||||
|
||||
const closeButton = document.createElement("img");
|
||||
closeButton.classList.add("sbChatClose");
|
||||
closeButton.src = chrome.extension.getURL("icons/close.png");
|
||||
closeButton.addEventListener("click", () => {
|
||||
chat.remove();
|
||||
closeButton.remove();
|
||||
});
|
||||
chat.appendChild(closeButton);
|
||||
|
||||
const referenceNode = utils.findReferenceNode();
|
||||
referenceNode.prepend(chat);
|
||||
}
|
||||
|
||||
export async function openWarningChat(warningMessage: string): Promise<void> {
|
||||
const warningReasonMatch = warningMessage.match(/Warning reason: '(.+)'/);
|
||||
alert(chrome.i18n.getMessage("warningChatInfo") + `\n\n${warningReasonMatch ? ` Warning reason: ${warningReasonMatch[1]}` : ``}`);
|
||||
|
||||
const userNameData = await utils.asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
|
||||
const userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
|
||||
const publicUserID = await utils.getHash(Config.config.userID);
|
||||
|
||||
openChat({
|
||||
displayName: `${userName ? userName : ``}${userName !== publicUserID ? ` | ${publicUserID}` : ``}`,
|
||||
composerInitialValue: `I got a warning and confirm I [REMOVE THIS CAPITAL TEXT TO CONFIRM] reread the guidelines.` +
|
||||
warningReasonMatch ? ` Warning reason: ${warningReasonMatch[1]}` : ``,
|
||||
customDescription: chrome.i18n.getMessage("warningChatInfo")
|
||||
});
|
||||
}
|
||||
@@ -64,7 +64,13 @@ export default class GenericNotice {
|
||||
extraClass={options.extraClass}
|
||||
closeListener={() => this.close()} >
|
||||
|
||||
{this.getMessageBox(this.idSuffix, options.textBoxes)}
|
||||
<tr id={"sponsorSkipNoticeMiddleRow" + this.idSuffix}
|
||||
className="sponsorTimeMessagesRow"
|
||||
style={{maxHeight: (this.contentContainer().v.offsetHeight - 200) + "px"}}>
|
||||
<td style={{width: "100%"}}>
|
||||
{this.getMessageBoxes(this.idSuffix, options.textBoxes)}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr id={"sponsorSkipNoticeSpacer" + this.idSuffix}
|
||||
className="sponsorBlockSpacer">
|
||||
@@ -81,7 +87,7 @@ export default class GenericNotice {
|
||||
);
|
||||
}
|
||||
|
||||
getMessageBox(idSuffix: string, textBoxes: TextBox[]): JSX.Element[] {
|
||||
getMessageBoxes(idSuffix: string, textBoxes: TextBox[]): JSX.Element[] {
|
||||
if (textBoxes) {
|
||||
const result = [];
|
||||
for (let i = 0; i < textBoxes.length; i++) {
|
||||
|
||||
13
src/utils.ts
13
src/utils.ts
@@ -376,19 +376,6 @@ export default class Utils {
|
||||
return referenceNode;
|
||||
}
|
||||
|
||||
objectToURI<T>(url: string, data: T, includeQuestionMark: boolean): string {
|
||||
let counter = 0;
|
||||
for (const key in data) {
|
||||
const seperator = (url.includes("?") || counter > 0) ? "&" : (includeQuestionMark ? "?" : "");
|
||||
const value = (typeof(data[key]) === "string") ? data[key] as unknown as string : JSON.stringify(data[key]);
|
||||
url += seperator + encodeURIComponent(key) + "=" + encodeURIComponent(value);
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
getFormattedTime(seconds: number, precise?: boolean): string {
|
||||
seconds = Math.max(seconds, 0);
|
||||
|
||||
|
||||
@@ -72,9 +72,23 @@ function indexesOf<T>(array: T[], value: T): number[] {
|
||||
return array.map((v, i) => v === value ? i : -1).filter(i => i !== -1);
|
||||
}
|
||||
|
||||
function objectToURI<T>(url: string, data: T, includeQuestionMark: boolean): string {
|
||||
let counter = 0;
|
||||
for (const key in data) {
|
||||
const seperator = (url.includes("?") || counter > 0) ? "&" : (includeQuestionMark ? "?" : "");
|
||||
const value = (typeof(data[key]) === "string") ? data[key] as unknown as string : JSON.stringify(data[key]);
|
||||
url += seperator + encodeURIComponent(key) + "=" + encodeURIComponent(value);
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
export const GenericUtils = {
|
||||
wait,
|
||||
getErrorMessage,
|
||||
getLuminance,
|
||||
indexesOf
|
||||
indexesOf,
|
||||
objectToURI
|
||||
}
|
||||
66
src/utils/warnings.ts
Normal file
66
src/utils/warnings.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import Config from "../config";
|
||||
import GenericNotice, { NoticeOptions } from "../render/GenericNotice";
|
||||
import { ContentContainer } from "../types";
|
||||
import Utils from "../utils";
|
||||
import { GenericUtils } from "./genericUtils";
|
||||
const utils = new Utils();
|
||||
|
||||
export interface ChatConfig {
|
||||
displayName: string,
|
||||
composerInitialValue?: string,
|
||||
customDescription?: string
|
||||
}
|
||||
|
||||
export async function openWarningDialog(contentContainer: ContentContainer): Promise<void> {
|
||||
const userInfo = await utils.asyncRequestToServer("GET", "/api/userInfo", {
|
||||
userID: Config.config.userID,
|
||||
values: ["warningReason"]
|
||||
});
|
||||
|
||||
if (userInfo.ok) {
|
||||
const warningReason = JSON.parse(userInfo.responseText)?.warningReason;
|
||||
const userNameData = await utils.asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
|
||||
const userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
|
||||
const publicUserID = await utils.getHash(Config.config.userID);
|
||||
|
||||
let notice: GenericNotice = null;
|
||||
const options: NoticeOptions = {
|
||||
title: chrome.i18n.getMessage("warningTitle"),
|
||||
textBoxes: [{
|
||||
text: chrome.i18n.getMessage("warningChatInfo"),
|
||||
icon: null
|
||||
}, ...warningReason.split("\n").map((reason) => ({
|
||||
text: reason,
|
||||
icon: null
|
||||
}))],
|
||||
buttons: [{
|
||||
name: chrome.i18n.getMessage("questionButton"),
|
||||
listener: () => openChat({
|
||||
displayName: `${userName ? userName : ``}${userName !== publicUserID ? ` | ${publicUserID}` : ``}`
|
||||
})
|
||||
},
|
||||
{
|
||||
name: chrome.i18n.getMessage("warningConfirmButton"),
|
||||
listener: async () => {
|
||||
const result = await utils.asyncRequestToServer("POST", "/api/warnUser", {
|
||||
userID: Config.config.userID,
|
||||
enabled: false
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
notice?.close();
|
||||
} else {
|
||||
alert(`${chrome.i18n.getMessage("warningError")} ${result.status}`);
|
||||
}
|
||||
}
|
||||
}],
|
||||
timed: false
|
||||
};
|
||||
|
||||
notice = new GenericNotice(contentContainer, "warningNotice", options);
|
||||
}
|
||||
}
|
||||
|
||||
export function openChat(config: ChatConfig): void {
|
||||
window.open("https://chat.sponsor.ajay.app/#" + GenericUtils.objectToURI("", config, false));
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const merge = require('webpack-merge');
|
||||
const { merge } = require('webpack-merge');
|
||||
const common = require('./webpack.common.js');
|
||||
|
||||
module.exports = env => merge(common(env), {
|
||||
|
||||
Reference in New Issue
Block a user