mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 20:47:11 +03:00
Add dearrow promo based on title and remove old one
Also refactor requests out to seperate file
This commit is contained in:
Submodule maze-utils updated: 92d368b051...6bdc9402c6
Submodule public/_locales updated: 6ff5f86e9a...9ba877c006
@@ -742,6 +742,7 @@ input::-webkit-inner-spin-button {
|
|||||||
color: white;
|
color: white;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
z-index: 10000;
|
z-index: 10000;
|
||||||
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sponsorBlockTooltip a {
|
.sponsorBlockTooltip a {
|
||||||
@@ -764,6 +765,12 @@ input::-webkit-inner-spin-button {
|
|||||||
right: 50%;
|
right: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sponsorBlockTooltip.sbTriangle.sbTopTriangle::after {
|
||||||
|
bottom: 100%;
|
||||||
|
top: unset;
|
||||||
|
border-color: transparent transparent rgba(28, 28, 28, 0.7) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
.sponsorBlockLockedColor {
|
.sponsorBlockLockedColor {
|
||||||
color: #ffc83d !important;
|
color: #ffc83d !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,12 @@ import * as React from "react";
|
|||||||
import * as CompileConfig from "../../config.json";
|
import * as CompileConfig from "../../config.json";
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { ActionType, Category, ChannelIDStatus, ContentContainer, SponsorTime } from "../types";
|
import { ActionType, Category, ChannelIDStatus, ContentContainer, SponsorTime } from "../types";
|
||||||
import Utils from "../utils";
|
|
||||||
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
|
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
|
||||||
import { RectangleTooltip } from "../render/RectangleTooltip";
|
import { RectangleTooltip } from "../render/RectangleTooltip";
|
||||||
import SelectorComponent, { SelectorOption } from "./SelectorComponent";
|
import SelectorComponent, { SelectorOption } from "./SelectorComponent";
|
||||||
import { DEFAULT_CATEGORY } from "../utils/categoryUtils";
|
import { DEFAULT_CATEGORY } from "../utils/categoryUtils";
|
||||||
import { getFormattedTime, getFormattedTimeToSeconds } from "../../maze-utils/src/formating";
|
import { getFormattedTime, getFormattedTimeToSeconds } from "../../maze-utils/src/formating";
|
||||||
|
import { asyncRequestToServer } from "../utils/requests";
|
||||||
const utils = new Utils();
|
|
||||||
|
|
||||||
export interface SponsorTimeEditProps {
|
export interface SponsorTimeEditProps {
|
||||||
index: number;
|
index: number;
|
||||||
@@ -727,7 +725,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
if (this.props.contentContainer().channelIDInfo.status !== ChannelIDStatus.Found) return;
|
if (this.props.contentContainer().channelIDInfo.status !== ChannelIDStatus.Found) return;
|
||||||
|
|
||||||
this.fetchingSuggestions = true;
|
this.fetchingSuggestions = true;
|
||||||
const result = await utils.asyncRequestToServer("GET", "/api/chapterNames", {
|
const result = await asyncRequestToServer("GET", "/api/chapterNames", {
|
||||||
description,
|
description,
|
||||||
channelID: this.props.contentContainer().channelIDInfo.id
|
channelID: this.props.contentContainer().channelIDInfo.id
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ interface SBConfig {
|
|||||||
deArrowInstalled: boolean;
|
deArrowInstalled: boolean;
|
||||||
showDeArrowPromotion: boolean;
|
showDeArrowPromotion: boolean;
|
||||||
showDeArrowInSettings: boolean;
|
showDeArrowInSettings: boolean;
|
||||||
|
shownDeArrowPromotion: boolean;
|
||||||
showZoomToFillError2: boolean;
|
showZoomToFillError2: boolean;
|
||||||
cleanPopup: boolean;
|
cleanPopup: boolean;
|
||||||
|
|
||||||
@@ -318,8 +319,9 @@ const syncDefaults = {
|
|||||||
showSegmentFailedToFetchWarning: true,
|
showSegmentFailedToFetchWarning: true,
|
||||||
allowScrollingToEdit: true,
|
allowScrollingToEdit: true,
|
||||||
deArrowInstalled: false,
|
deArrowInstalled: false,
|
||||||
showDeArrowPromotion: false,
|
showDeArrowPromotion: true,
|
||||||
showDeArrowInSettings: true,
|
showDeArrowInSettings: true,
|
||||||
|
shownDeArrowPromotion: false,
|
||||||
showZoomToFillError2: true,
|
showZoomToFillError2: true,
|
||||||
cleanPopup: false,
|
cleanPopup: false,
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { getControls, getExistingChapters, getHashParams, isPlayingPlaylist, isV
|
|||||||
import { CategoryPill } from "./render/CategoryPill";
|
import { CategoryPill } from "./render/CategoryPill";
|
||||||
import { AnimationUtils } from "./utils/animationUtils";
|
import { AnimationUtils } from "./utils/animationUtils";
|
||||||
import { GenericUtils } from "./utils/genericUtils";
|
import { GenericUtils } from "./utils/genericUtils";
|
||||||
import { logDebug } from "./utils/logger";
|
import { logDebug, logWarn } from "./utils/logger";
|
||||||
import { importTimes } from "./utils/exporter";
|
import { importTimes } from "./utils/exporter";
|
||||||
import { ChapterVote } from "./render/ChapterVote";
|
import { ChapterVote } from "./render/ChapterVote";
|
||||||
import { openWarningDialog } from "./utils/warnings";
|
import { openWarningDialog } from "./utils/warnings";
|
||||||
@@ -36,17 +36,17 @@ import { isFirefoxOrSafari, waitFor } from "../maze-utils/src";
|
|||||||
import { getErrorMessage, getFormattedTime } from "../maze-utils/src/formating";
|
import { getErrorMessage, getFormattedTime } from "../maze-utils/src/formating";
|
||||||
import { getChannelIDInfo, getVideo, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube } from "../maze-utils/src/video";
|
import { getChannelIDInfo, getVideo, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube } from "../maze-utils/src/video";
|
||||||
import { Keybind, StorageChangesObject, isSafari, keybindEquals } from "../maze-utils/src/config";
|
import { Keybind, StorageChangesObject, isSafari, keybindEquals } from "../maze-utils/src/config";
|
||||||
import { findValidElement, waitForElement } from "../maze-utils/src/dom"
|
import { findValidElement } from "../maze-utils/src/dom"
|
||||||
import { getHash, HashedValue } from "../maze-utils/src/hash";
|
import { getHash, HashedValue } from "../maze-utils/src/hash";
|
||||||
import { generateUserID } from "../maze-utils/src/setup";
|
import { generateUserID } from "../maze-utils/src/setup";
|
||||||
import { updateAll } from "../maze-utils/src/thumbnailManagement";
|
import { updateAll } from "../maze-utils/src/thumbnailManagement";
|
||||||
import { setupThumbnailListener } from "./utils/thumbnails";
|
import { setupThumbnailListener } from "./utils/thumbnails";
|
||||||
import * as documentScript from "../dist/js/document.js";
|
import * as documentScript from "../dist/js/document.js";
|
||||||
import { Tooltip } from "./render/Tooltip";
|
|
||||||
import { isDeArrowInstalled } from "./utils/crossExtension";
|
|
||||||
import { runCompatibilityChecks } from "./utils/compatibility";
|
import { runCompatibilityChecks } from "./utils/compatibility";
|
||||||
import { cleanPage } from "./utils/pageCleaner";
|
import { cleanPage } from "./utils/pageCleaner";
|
||||||
import { addCleanupListener } from "../maze-utils/src/cleanup";
|
import { addCleanupListener } from "../maze-utils/src/cleanup";
|
||||||
|
import { hideDeArrowPromotion, tryShowingDeArrowPromotion } from "./dearrowPromotion";
|
||||||
|
import { asyncRequestToServer } from "./utils/requests";
|
||||||
|
|
||||||
cleanPage();
|
cleanPage();
|
||||||
|
|
||||||
@@ -57,43 +57,6 @@ utils.wait(() => Config.isReady(), 5000, 10).then(() => {
|
|||||||
addCSS();
|
addCSS();
|
||||||
setCategoryColorCSSVariables();
|
setCategoryColorCSSVariables();
|
||||||
|
|
||||||
// DeArrow promotion
|
|
||||||
setTimeout(async () => {
|
|
||||||
if (document.URL === "https://www.youtube.com/"
|
|
||||||
&& Config.config.showDeArrowPromotion
|
|
||||||
&& Config.config.showUpsells
|
|
||||||
&& Config.config.showNewFeaturePopups
|
|
||||||
&& (Config.config.skipCount > 30 || !Config.config.trackViewCount)
|
|
||||||
&& Math.random() < 0.05) {
|
|
||||||
|
|
||||||
if (!await isDeArrowInstalled()) {
|
|
||||||
const element = await waitForElement("#contents") as HTMLElement;
|
|
||||||
if (element) {
|
|
||||||
Config.config.showDeArrowPromotion = false;
|
|
||||||
|
|
||||||
new Tooltip({
|
|
||||||
text: chrome.i18n.getMessage("DeArrowPromotionMessage2"),
|
|
||||||
linkOnClick: () => window.open("https://dearrow.ajay.app"),
|
|
||||||
referenceNode: element,
|
|
||||||
prependElement: element.firstElementChild as HTMLElement,
|
|
||||||
timeout: 15000,
|
|
||||||
positionRealtive: false,
|
|
||||||
containerAbsolute: true,
|
|
||||||
bottomOffset: "inherit",
|
|
||||||
topOffset: "-82px",
|
|
||||||
leftOffset: "0",
|
|
||||||
rightOffset: "0",
|
|
||||||
displayTriangle: false,
|
|
||||||
center: true,
|
|
||||||
opacity: 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Config.config.showDeArrowPromotion = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
|
|
||||||
runCompatibilityChecks();
|
runCompatibilityChecks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -440,6 +403,8 @@ function resetValues() {
|
|||||||
for (let i = 0; i < skipNotices.length; i++) {
|
for (let i = 0; i < skipNotices.length; i++) {
|
||||||
skipNotices.pop()?.close();
|
skipNotices.pop()?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hideDeArrowPromotion();
|
||||||
}
|
}
|
||||||
|
|
||||||
function videoIDChange(): void {
|
function videoIDChange(): void {
|
||||||
@@ -480,6 +445,8 @@ function videoIDChange(): void {
|
|||||||
// Clear unsubmitted segments from the previous video
|
// Clear unsubmitted segments from the previous video
|
||||||
sponsorTimesSubmitting = [];
|
sponsorTimesSubmitting = [];
|
||||||
updateSponsorTimesSubmitting();
|
updateSponsorTimesSubmitting();
|
||||||
|
|
||||||
|
tryShowingDeArrowPromotion().catch(logWarn);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMobileControlsMutations(): void {
|
function handleMobileControlsMutations(): void {
|
||||||
@@ -1112,7 +1079,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
|||||||
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;
|
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;
|
||||||
|
|
||||||
const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4) as VideoID & HashedValue;
|
const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4) as VideoID & HashedValue;
|
||||||
const response = await utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
|
const response = await asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
|
||||||
categories,
|
categories,
|
||||||
actionTypes: getEnabledActionTypes(),
|
actionTypes: getEnabledActionTypes(),
|
||||||
userAgent: `${chrome.runtime.id}`,
|
userAgent: `${chrome.runtime.id}`,
|
||||||
@@ -1252,7 +1219,7 @@ function getEnabledActionTypes(forceFullVideo = false): ActionType[] {
|
|||||||
|
|
||||||
async function lockedCategoriesLookup(): Promise<void> {
|
async function lockedCategoriesLookup(): Promise<void> {
|
||||||
const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4);
|
const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4);
|
||||||
const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix);
|
const response = await asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
try {
|
try {
|
||||||
@@ -1646,7 +1613,7 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped:
|
|||||||
counted = true;
|
counted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullSkip) utils.asyncRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + segment.UUID);
|
if (fullSkip) asyncRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + segment.UUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2282,7 +2249,7 @@ async function sendSubmitMessage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await utils.asyncRequestToServer("POST", "/api/skipSegments", {
|
const response = await asyncRequestToServer("POST", "/api/skipSegments", {
|
||||||
videoID: getVideoID(),
|
videoID: getVideoID(),
|
||||||
userID: Config.config.userID,
|
userID: Config.config.userID,
|
||||||
segments: sponsorTimesSubmitting,
|
segments: sponsorTimesSubmitting,
|
||||||
|
|||||||
71
src/dearrowPromotion.ts
Normal file
71
src/dearrowPromotion.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { waitFor } from "../maze-utils/src";
|
||||||
|
import { getYouTubeTitleNode } from "../maze-utils/src/elements";
|
||||||
|
import { getHash } from "../maze-utils/src/hash";
|
||||||
|
import { getVideoID, isOnInvidious, isOnMobileYouTube } from "../maze-utils/src/video";
|
||||||
|
import Config from "./config";
|
||||||
|
import { Tooltip } from "./render/Tooltip";
|
||||||
|
import { isDeArrowInstalled } from "./utils/crossExtension";
|
||||||
|
import { isVisible } from "./utils/pageUtils";
|
||||||
|
import { asyncRequestToServer } from "./utils/requests";
|
||||||
|
|
||||||
|
let tooltip: Tooltip = null;
|
||||||
|
export async function tryShowingDeArrowPromotion() {
|
||||||
|
if (Config.config.showDeArrowPromotion
|
||||||
|
&& !isOnMobileYouTube()
|
||||||
|
&& !isOnInvidious()
|
||||||
|
&& document.URL.includes("watch")
|
||||||
|
&& Config.config.showUpsells
|
||||||
|
&& Config.config.showNewFeaturePopups
|
||||||
|
&& (Config.config.skipCount > 30 || !Config.config.trackViewCount)) {
|
||||||
|
|
||||||
|
if (!await isDeArrowInstalled()) {
|
||||||
|
try {
|
||||||
|
const element = await waitFor(() => getYouTubeTitleNode(), 5000, 500, (e) => isVisible(e)) as HTMLElement;
|
||||||
|
if (element && element.innerText && badTitle(element.innerText)) {
|
||||||
|
const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4);
|
||||||
|
const deArrowData = await asyncRequestToServer("GET", "/api/branding/" + hashPrefix);
|
||||||
|
if (!deArrowData.ok) return;
|
||||||
|
|
||||||
|
const deArrowDataJson = JSON.parse(deArrowData.responseText);
|
||||||
|
const title = deArrowDataJson?.[getVideoID()]?.titles?.[0];
|
||||||
|
if (title && title.title && (title.locked || title.votes > 0)) {
|
||||||
|
Config.config.showDeArrowPromotion = false;
|
||||||
|
|
||||||
|
tooltip = new Tooltip({
|
||||||
|
text: chrome.i18n.getMessage("DeArrowTitleReplacementSuggestion") + "\n\n" + title.title,
|
||||||
|
linkOnClick: () => {
|
||||||
|
window.open("https://dearrow.ajay.app");
|
||||||
|
Config.config.shownDeArrowPromotion = true;
|
||||||
|
},
|
||||||
|
referenceNode: element,
|
||||||
|
prependElement: element.firstElementChild as HTMLElement,
|
||||||
|
timeout: 15000,
|
||||||
|
positionRealtive: false,
|
||||||
|
containerAbsolute: true,
|
||||||
|
bottomOffset: "inherit",
|
||||||
|
topOffset: "55px",
|
||||||
|
leftOffset: "0",
|
||||||
|
rightOffset: "0",
|
||||||
|
topTriangle: true,
|
||||||
|
center: true,
|
||||||
|
opacity: 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { } // eslint-disable-line no-empty
|
||||||
|
} else {
|
||||||
|
Config.config.showDeArrowPromotion = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Two upper case words (at least 2 letters long)
|
||||||
|
*/
|
||||||
|
function badTitle(title: string): boolean {
|
||||||
|
return !!title.match(/\p{Lu}{2,} \p{Lu}{2,}[.!? ]/u);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hideDeArrowPromotion(): void {
|
||||||
|
if (tooltip) tooltip.close();
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import { StorageChangesObject } from "../maze-utils/src/config";
|
|||||||
import { getHash } from "../maze-utils/src/hash";
|
import { getHash } from "../maze-utils/src/hash";
|
||||||
import { isFirefoxOrSafari } from "../maze-utils/src";
|
import { isFirefoxOrSafari } from "../maze-utils/src";
|
||||||
import { isDeArrowInstalled } from "./utils/crossExtension";
|
import { isDeArrowInstalled } from "./utils/crossExtension";
|
||||||
|
import { asyncRequestToServer } from "./utils/requests";
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
let embed = false;
|
let embed = false;
|
||||||
|
|
||||||
@@ -567,7 +568,7 @@ function activatePrivateTextChange(element: HTMLElement) {
|
|||||||
switch (option) {
|
switch (option) {
|
||||||
case "userID":
|
case "userID":
|
||||||
if (Config.config[option]) {
|
if (Config.config[option]) {
|
||||||
utils.asyncRequestToServer("GET", "/api/userInfo", {
|
asyncRequestToServer("GET", "/api/userInfo", {
|
||||||
publicUserID: getHash(Config.config[option]),
|
publicUserID: getHash(Config.config[option]),
|
||||||
values: ["warnings", "banned"]
|
values: ["warnings", "banned"]
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import GenericNotice from "./render/GenericNotice";
|
|||||||
import { getErrorMessage, getFormattedTime } from "../maze-utils/src/formating";
|
import { getErrorMessage, getFormattedTime } from "../maze-utils/src/formating";
|
||||||
import { StorageChangesObject } from "../maze-utils/src/config";
|
import { StorageChangesObject } from "../maze-utils/src/config";
|
||||||
import { getHash } from "../maze-utils/src/hash";
|
import { getHash } from "../maze-utils/src/hash";
|
||||||
|
import { asyncRequestToServer, sendRequestToServer } from "./utils/requests";
|
||||||
|
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
|
|
||||||
@@ -295,7 +296,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
|
|
||||||
const values = ["userName", "viewCount", "minutesSaved", "vip", "permissions"];
|
const values = ["userName", "viewCount", "minutesSaved", "vip", "permissions"];
|
||||||
|
|
||||||
utils.asyncRequestToServer("GET", "/api/userInfo", {
|
asyncRequestToServer("GET", "/api/userInfo", {
|
||||||
publicUserID: await getHash(Config.config.userID),
|
publicUserID: await getHash(Config.config.userID),
|
||||||
values
|
values
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
@@ -818,7 +819,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
PageElements.setUsernameStatus.style.display = "unset";
|
PageElements.setUsernameStatus.style.display = "unset";
|
||||||
PageElements.setUsernameStatus.innerText = chrome.i18n.getMessage("Loading");
|
PageElements.setUsernameStatus.innerText = chrome.i18n.getMessage("Loading");
|
||||||
|
|
||||||
utils.sendRequestToServer("POST", "/api/setUsername?userID=" + Config.config.userID + "&username=" + PageElements.usernameInput.value, function (response) {
|
sendRequestToServer("POST", "/api/setUsername?userID=" + Config.config.userID + "&username=" + PageElements.usernameInput.value, function (response) {
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
//submitted
|
//submitted
|
||||||
PageElements.submitUsername.style.display = "none";
|
PageElements.submitUsername.style.display = "none";
|
||||||
|
|||||||
46
src/utils.ts
46
src/utils.ts
@@ -2,10 +2,8 @@ import Config, { VideoDownvotes } from "./config";
|
|||||||
import { CategorySelection, SponsorTime, BackgroundScriptContainer, Registration, VideoID, SponsorHideType, CategorySkipOption } from "./types";
|
import { CategorySelection, SponsorTime, BackgroundScriptContainer, Registration, VideoID, SponsorHideType, CategorySkipOption } from "./types";
|
||||||
|
|
||||||
import { getHash, HashedValue } from "../maze-utils/src/hash";
|
import { getHash, HashedValue } from "../maze-utils/src/hash";
|
||||||
import * as CompileConfig from "../config.json";
|
|
||||||
import { isFirefoxOrSafari, waitFor } from "../maze-utils/src";
|
import { isFirefoxOrSafari, waitFor } from "../maze-utils/src";
|
||||||
import { findValidElementFromSelector } from "../maze-utils/src/dom";
|
import { findValidElementFromSelector } from "../maze-utils/src/dom";
|
||||||
import { FetchResponse, sendRequestToCustomServer } from "../maze-utils/src/background-request-proxy"
|
|
||||||
import { isSafari } from "../maze-utils/src/config";
|
import { isSafari } from "../maze-utils/src/config";
|
||||||
|
|
||||||
export default class Utils {
|
export default class Utils {
|
||||||
@@ -240,50 +238,6 @@ export default class Utils {
|
|||||||
return permissionRegex;
|
return permissionRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a request to a custom server
|
|
||||||
*
|
|
||||||
* @param type The request type. "GET", "POST", etc.
|
|
||||||
* @param address The address to add to the SponsorBlock server address
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
asyncRequestToCustomServer(type: string, url: string, data = {}): Promise<FetchResponse> {
|
|
||||||
return sendRequestToCustomServer(type, url, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a request to the SponsorBlock server with address added as a query
|
|
||||||
*
|
|
||||||
* @param type The request type. "GET", "POST", etc.
|
|
||||||
* @param address The address to add to the SponsorBlock server address
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
async asyncRequestToServer(type: string, address: string, data = {}): Promise<FetchResponse> {
|
|
||||||
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
|
||||||
|
|
||||||
return await (this.asyncRequestToCustomServer(type, serverAddress + address, data));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a request to the SponsorBlock server with address added as a query
|
|
||||||
*
|
|
||||||
* @param type The request type. "GET", "POST", etc.
|
|
||||||
* @param address The address to add to the SponsorBlock server address
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
sendRequestToServer(type: string, address: string, callback?: (response: FetchResponse) => void): void {
|
|
||||||
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
|
||||||
|
|
||||||
// Ask the background script to do the work
|
|
||||||
chrome.runtime.sendMessage({
|
|
||||||
message: "sendRequest",
|
|
||||||
type,
|
|
||||||
url: serverAddress + address
|
|
||||||
}, (response) => {
|
|
||||||
callback(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
findReferenceNode(): HTMLElement {
|
findReferenceNode(): HTMLElement {
|
||||||
const selectors = [
|
const selectors = [
|
||||||
"#player-container-id", // Mobile YouTube
|
"#player-container-id", // Mobile YouTube
|
||||||
|
|||||||
47
src/utils/requests.ts
Normal file
47
src/utils/requests.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import Config from "../config";
|
||||||
|
import * as CompileConfig from "../../config.json";
|
||||||
|
import { FetchResponse, sendRequestToCustomServer } from "../../maze-utils/src/background-request-proxy";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a request to a custom server
|
||||||
|
*
|
||||||
|
* @param type The request type. "GET", "POST", etc.
|
||||||
|
* @param address The address to add to the SponsorBlock server address
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
export function asyncRequestToCustomServer(type: string, url: string, data = {}): Promise<FetchResponse> {
|
||||||
|
return sendRequestToCustomServer(type, url, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a request to the SponsorBlock server with address added as a query
|
||||||
|
*
|
||||||
|
* @param type The request type. "GET", "POST", etc.
|
||||||
|
* @param address The address to add to the SponsorBlock server address
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
export async function asyncRequestToServer(type: string, address: string, data = {}): Promise<FetchResponse> {
|
||||||
|
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
||||||
|
|
||||||
|
return await (asyncRequestToCustomServer(type, serverAddress + address, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a request to the SponsorBlock server with address added as a query
|
||||||
|
*
|
||||||
|
* @param type The request type. "GET", "POST", etc.
|
||||||
|
* @param address The address to add to the SponsorBlock server address
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
export function sendRequestToServer(type: string, address: string, callback?: (response: FetchResponse) => void): void {
|
||||||
|
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
||||||
|
|
||||||
|
// Ask the background script to do the work
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
message: "sendRequest",
|
||||||
|
type,
|
||||||
|
url: serverAddress + address
|
||||||
|
}, (response) => {
|
||||||
|
callback(response);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import { Category, CategorySkipOption, VideoID } from "../types";
|
|||||||
import { getHash } from "../../maze-utils/src/hash";
|
import { getHash } from "../../maze-utils/src/hash";
|
||||||
import Utils from "../utils";
|
import Utils from "../utils";
|
||||||
import { logWarn } from "./logger";
|
import { logWarn } from "./logger";
|
||||||
|
import { asyncRequestToServer } from "./requests";
|
||||||
|
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ async function getLabelHashBlock(hashPrefix: string): Promise<LabelCacheEntry |
|
|||||||
return cachedEntry;
|
return cachedEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await utils.asyncRequestToServer("GET", `/api/videoLabels/${hashPrefix}`);
|
const response = await asyncRequestToServer("GET", `/api/videoLabels/${hashPrefix}`);
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
// No video labels or server down
|
// No video labels or server down
|
||||||
labelCache[hashPrefix] = {
|
labelCache[hashPrefix] = {
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ import { getHash } from "../../maze-utils/src/hash";
|
|||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import GenericNotice, { NoticeOptions } from "../render/GenericNotice";
|
import GenericNotice, { NoticeOptions } from "../render/GenericNotice";
|
||||||
import { ContentContainer } from "../types";
|
import { ContentContainer } from "../types";
|
||||||
import Utils from "../utils";
|
import { asyncRequestToServer } from "./requests";
|
||||||
const utils = new Utils();
|
|
||||||
|
|
||||||
export interface ChatConfig {
|
export interface ChatConfig {
|
||||||
displayName: string;
|
displayName: string;
|
||||||
@@ -13,14 +12,14 @@ export interface ChatConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openWarningDialog(contentContainer: ContentContainer): Promise<void> {
|
export async function openWarningDialog(contentContainer: ContentContainer): Promise<void> {
|
||||||
const userInfo = await utils.asyncRequestToServer("GET", "/api/userInfo", {
|
const userInfo = await asyncRequestToServer("GET", "/api/userInfo", {
|
||||||
publicUserID: await getHash(Config.config.userID),
|
publicUserID: await getHash(Config.config.userID),
|
||||||
values: ["warningReason"]
|
values: ["warningReason"]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (userInfo.ok) {
|
if (userInfo.ok) {
|
||||||
const warningReason = JSON.parse(userInfo.responseText)?.warningReason;
|
const warningReason = JSON.parse(userInfo.responseText)?.warningReason;
|
||||||
const userNameData = await utils.asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
|
const userNameData = await asyncRequestToServer("GET", "/api/getUsername?userID=" + Config.config.userID);
|
||||||
const userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
|
const userName = userNameData.ok ? JSON.parse(userNameData.responseText).userName : "";
|
||||||
const publicUserID = await getHash(Config.config.userID);
|
const publicUserID = await getHash(Config.config.userID);
|
||||||
|
|
||||||
@@ -43,7 +42,7 @@ export async function openWarningDialog(contentContainer: ContentContainer): Pro
|
|||||||
{
|
{
|
||||||
name: chrome.i18n.getMessage("warningConfirmButton"),
|
name: chrome.i18n.getMessage("warningConfirmButton"),
|
||||||
listener: async () => {
|
listener: async () => {
|
||||||
const result = await utils.asyncRequestToServer("POST", "/api/warnUser", {
|
const result = await asyncRequestToServer("POST", "/api/warnUser", {
|
||||||
userID: Config.config.userID,
|
userID: Config.config.userID,
|
||||||
enabled: false
|
enabled: false
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user