aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/content.ts
diff options
context:
space:
mode:
authorAjay <[email protected]>2023-11-08 16:07:59 -0500
committerAjay <[email protected]>2023-11-08 16:07:59 -0500
commite722ded58a928989bb583ae266acf765c129592c (patch)
tree28d2dea746c1b764737775564e65ce10b01ef3d4 /src/content.ts
parent6d37180d005f8f1c7691e0567ea4802425ca7569 (diff)
downloadSponsorBlock-e722ded58a928989bb583ae266acf765c129592c.tar.gz
SponsorBlock-e722ded58a928989bb583ae266acf765c129592c.zip
Add dearrow promo based on title and remove old one
Also refactor requests out to seperate file
Diffstat (limited to 'src/content.ts')
-rw-r--r--src/content.ts57
1 files changed, 12 insertions, 45 deletions
diff --git a/src/content.ts b/src/content.ts
index 9fbe4cb6..2804dc4c 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -28,7 +28,7 @@ import { getControls, getExistingChapters, getHashParams, isPlayingPlaylist, isV
import { CategoryPill } from "./render/CategoryPill";
import { AnimationUtils } from "./utils/animationUtils";
import { GenericUtils } from "./utils/genericUtils";
-import { logDebug } from "./utils/logger";
+import { logDebug, logWarn } from "./utils/logger";
import { importTimes } from "./utils/exporter";
import { ChapterVote } from "./render/ChapterVote";
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 { 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 { findValidElement, waitForElement } from "../maze-utils/src/dom"
+import { findValidElement } from "../maze-utils/src/dom"
import { getHash, HashedValue } from "../maze-utils/src/hash";
import { generateUserID } from "../maze-utils/src/setup";
import { updateAll } from "../maze-utils/src/thumbnailManagement";
import { setupThumbnailListener } from "./utils/thumbnails";
import * as documentScript from "../dist/js/document.js";
-import { Tooltip } from "./render/Tooltip";
-import { isDeArrowInstalled } from "./utils/crossExtension";
import { runCompatibilityChecks } from "./utils/compatibility";
import { cleanPage } from "./utils/pageCleaner";
import { addCleanupListener } from "../maze-utils/src/cleanup";
+import { hideDeArrowPromotion, tryShowingDeArrowPromotion } from "./dearrowPromotion";
+import { asyncRequestToServer } from "./utils/requests";
cleanPage();
@@ -57,43 +57,6 @@ utils.wait(() => Config.isReady(), 5000, 10).then(() => {
addCSS();
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();
});
@@ -440,6 +403,8 @@ function resetValues() {
for (let i = 0; i < skipNotices.length; i++) {
skipNotices.pop()?.close();
}
+
+ hideDeArrowPromotion();
}
function videoIDChange(): void {
@@ -480,6 +445,8 @@ function videoIDChange(): void {
// Clear unsubmitted segments from the previous video
sponsorTimesSubmitting = [];
updateSponsorTimesSubmitting();
+
+ tryShowingDeArrowPromotion().catch(logWarn);
}
function handleMobileControlsMutations(): void {
@@ -1112,7 +1079,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;
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,
actionTypes: getEnabledActionTypes(),
userAgent: `${chrome.runtime.id}`,
@@ -1252,7 +1219,7 @@ function getEnabledActionTypes(forceFullVideo = false): ActionType[] {
async function lockedCategoriesLookup(): Promise<void> {
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) {
try {
@@ -1646,7 +1613,7 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped:
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(),
userID: Config.config.userID,
segments: sponsorTimesSubmitting,