Compare commits

...

11 Commits

Author SHA1 Message Date
Ajay
52bd85b850 bump version 2023-11-08 18:24:51 -05:00
Ajay
09e7c41479 update translations 2023-11-08 18:24:44 -05:00
Ajay
bdcb2d05c7 Make submission and skip notices slightly larger 2023-11-08 18:23:37 -05:00
Ajay
a522e3065c Fix regex being treated as a range 2023-11-08 18:22:41 -05:00
Ajay
72c62d0fa4 Deduplicate different quotes when comparing chapter names 2023-11-08 18:19:28 -05:00
Ajay
133ea360d7 Fix error when submitting with required segments 2023-11-08 18:13:38 -05:00
Ajay
e722ded58a Add dearrow promo based on title and remove old one
Also refactor requests out to seperate file
2023-11-08 16:07:59 -05:00
Ajay
6d37180d00 Add option to hide clutter in popup 2023-11-07 21:05:39 -05:00
Ajay
14d50b9e70 Add dearrow link to install page and add close button 2023-11-07 20:49:25 -05:00
Ajay
cfe314742d Rename Preview/Recap to Preview/Recap/Hook 2023-11-07 15:34:53 -05:00
Ajay
9a71e8bb8c Disable dearrow promotion 2023-11-06 19:33:05 -05:00
23 changed files with 285 additions and 113 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "__MSG_fullName__", "name": "__MSG_fullName__",
"short_name": "SponsorBlock", "short_name": "SponsorBlock",
"version": "5.4.26", "version": "5.4.27",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_Description__", "description": "__MSG_Description__",
"homepage_url": "https://sponsor.ajay.app", "homepage_url": "https://sponsor.ajay.app",

View File

@@ -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;
} }

View File

@@ -34,6 +34,20 @@
Come contribute, make some suggestions and help out on <a href="https://discord.gg/SponsorBlock">Discord</a> or on <a href="https://matrix.to/#/#sponsor:ajay.app?via=ajay.app&via=matrix.org&via=mozilla.org">Matrix</a>. Come contribute, make some suggestions and help out on <a href="https://discord.gg/SponsorBlock">Discord</a> or on <a href="https://matrix.to/#/#sponsor:ajay.app?via=ajay.app&via=matrix.org&via=mozilla.org">Matrix</a>.
</p> </p>
<a href="https://dearrow.ajay.app"
target="_blank"
id="dearrow-link"
class="dearrow-link hidden"
rel="noreferrer">
<img src="/icons/dearrow.svg"/>
<span id="dearrow-link-text">
</span>
<img src="/icons/close.png" class="close-button"/>
</a>
<p style="margin-bottom: 0; margin-top: 0" class="bigText center">__MSG_helpPageReviewOptions__</p> <p style="margin-bottom: 0; margin-top: 0" class="bigText center">__MSG_helpPageReviewOptions__</p>
<p class="smallText"> <p class="smallText">

View File

@@ -323,3 +323,32 @@ svg {
background-color: var(--disabled); background-color: var(--disabled);
color: grey; color: grey;
} }
.dearrow-link {
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
font-size: 16px;
}
.dearrow-link img {
width: 35px;
padding: 10px
}
.dearrow-link .close-button {
opacity: 0;
width: 15px;
filter: invert(0.3);
transition: opacity 0.2s;
}
.dearrow-link:hover .close-button {
opacity: 1;
}
.hidden {
display: none;
}

View File

@@ -718,3 +718,15 @@ svg {
width: 40px; width: 40px;
margin-right: 4px; margin-right: 4px;
} }
.dearrow-link .close-button {
opacity: 0;
width: 15px;
filter: invert(0.3);
transition: opacity 0.2s;
margin-left: 10px;
}
.dearrow-link:hover .close-button {
opacity: 1;
}

View File

@@ -75,6 +75,8 @@
<span class="promotion-description"> <span class="promotion-description">
__MSG_DeArrowPromotionMessage__ __MSG_DeArrowPromotionMessage__
</span> </span>
<img src="/icons/close.png" class="close-button"/>
</a> </a>
</div> </div>
@@ -357,6 +359,18 @@
<div class="small-description">__MSG_showTimeWithSkipsDescription__</div> <div class="small-description">__MSG_showTimeWithSkipsDescription__</div>
</div> </div>
<div data-type="toggle" data-sync="cleanPopup" data-no-safari="true">
<div class="switch-container">
<label class="switch">
<input id="cleanPopup" type="checkbox" checked>
<span class="slider round"></span>
</label>
<label class="switch-label" for="cleanPopup">
__MSG_cleanPopup__
</label>
</div>
</div>
<div data-type="toggle" data-sync="darkMode"> <div data-type="toggle" data-sync="darkMode">
<div class="switch-container"> <div class="switch-container">
<label class="switch"> <label class="switch">

View File

@@ -130,6 +130,7 @@
top: 5px; top: 5px;
right: 5px; right: 5px;
opacity: 0.5; opacity: 0.5;
z-index: 1;
} }
.sbCloseButton:hover { .sbCloseButton:hover {

View File

@@ -20,7 +20,7 @@
__MSG_betaServerWarning__ __MSG_betaServerWarning__
</div> </div>
<header class="sbPopupLogo"> <header id="sbPopupLogo" class="sbPopupLogo">
<img src="icons/IconSponsorBlocker256px.png" alt="SponsorBlock" width="40" height="40" id="sponsorBlockPopupLogo"> <img src="icons/IconSponsorBlocker256px.png" alt="SponsorBlock" width="40" height="40" id="sponsorBlockPopupLogo">
<p class="u-mZ">SponsorBlock</p> <p class="u-mZ">SponsorBlock</p>
</header> </header>
@@ -111,7 +111,7 @@
</div> </div>
<!-- Your Work box --> <!-- Your Work box -->
<div class="sbYourWorkBox"> <div id="sbYourWorkBox" class="sbYourWorkBox">
<h1 class="sbHeader" style="padding: 8px 15px;"> <h1 class="sbHeader" style="padding: 8px 15px;">
__MSG_yourWork__ __MSG_yourWork__
</h1> </h1>

View File

@@ -14,7 +14,7 @@
} }
.sponsorSkipNoticeParent { .sponsorSkipNoticeParent {
min-width: 375px; min-width: 390px;
max-width: 50%; max-width: 50%;
} }

View File

@@ -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
}); });

View File

@@ -75,7 +75,10 @@ interface SBConfig {
allowScrollingToEdit: boolean; allowScrollingToEdit: boolean;
deArrowInstalled: boolean; deArrowInstalled: boolean;
showDeArrowPromotion: boolean; showDeArrowPromotion: boolean;
showDeArrowInSettings: boolean;
shownDeArrowPromotion: boolean;
showZoomToFillError2: boolean; showZoomToFillError2: boolean;
cleanPopup: boolean;
// Used to cache calculated text color info // Used to cache calculated text color info
categoryPillColors: { categoryPillColors: {
@@ -317,7 +320,10 @@ const syncDefaults = {
allowScrollingToEdit: true, allowScrollingToEdit: true,
deArrowInstalled: false, deArrowInstalled: false,
showDeArrowPromotion: true, showDeArrowPromotion: true,
showDeArrowInSettings: true,
shownDeArrowPromotion: false,
showZoomToFillError2: true, showZoomToFillError2: true,
cleanPopup: false,
categoryPillColors: {}, categoryPillColors: {},

View File

@@ -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 {
@@ -1386,7 +1353,7 @@ function updatePreviewBar(): void {
showLarger: segment.actionType === ActionType.Poi, showLarger: segment.actionType === ActionType.Poi,
description: segment.description, description: segment.description,
source: segment.source, source: segment.source,
requiredSegment: requiredSegment && (segment.UUID === requiredSegment || segment.UUID.startsWith(requiredSegment)), requiredSegment: requiredSegment && (segment.UUID === requiredSegment || segment.UUID?.startsWith(requiredSegment)),
selectedSegment: selectedSegment && segment.UUID === selectedSegment selectedSegment: selectedSegment && segment.UUID === selectedSegment
}); });
}); });
@@ -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
View 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();
}

View File

@@ -3,6 +3,7 @@ import Config from "./config";
import { showDonationLink } from "./utils/configUtils"; import { showDonationLink } from "./utils/configUtils";
import { waitFor } from "../maze-utils/src"; import { waitFor } from "../maze-utils/src";
import { isDeArrowInstalled } from "./utils/crossExtension";
if (document.readyState === "complete") { if (document.readyState === "complete") {
init(); init();
@@ -10,6 +11,32 @@ if (document.readyState === "complete") {
document.addEventListener("DOMContentLoaded", init); document.addEventListener("DOMContentLoaded", init);
} }
// DeArrow promotion
waitFor(() => Config.isReady()).then(() => {
if (Config.config.showNewFeaturePopups && Config.config.showUpsells) {
isDeArrowInstalled().then((installed) => {
if (!installed) {
const deArrowPromotion = document.getElementById("dearrow-link");
deArrowPromotion.classList.remove("hidden");
deArrowPromotion.addEventListener("click", () => Config.config.showDeArrowPromotion = false);
const text = deArrowPromotion.querySelector("#dearrow-link-text");
text.textContent = `${chrome.i18n.getMessage("DeArrowPromotionMessage2").split("?")[0]}? ${chrome.i18n.getMessage("DeArrowPromotionMessage3")}`;
const closeButton = deArrowPromotion.querySelector(".close-button");
closeButton.addEventListener("click", (e) => {
e.preventDefault();
deArrowPromotion.classList.add("hidden");
Config.config.showDeArrowPromotion = false;
Config.config.showDeArrowInSettings = false;
});
}
});
}
});
async function init() { async function init() {
localizeHtmlPage(); localizeHtmlPage();

View File

@@ -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;
@@ -74,13 +75,22 @@ async function init() {
} }
// DeArrow promotion // DeArrow promotion
if (Config.config.showNewFeaturePopups && Config.config.showUpsells) { if (Config.config.showNewFeaturePopups && Config.config.showUpsells && Config.config.showDeArrowInSettings) {
isDeArrowInstalled().then((installed) => { isDeArrowInstalled().then((installed) => {
if (!installed) { if (!installed) {
const deArrowPromotion = document.getElementById("deArrowPromotion"); const deArrowPromotion = document.getElementById("deArrowPromotion");
deArrowPromotion.classList.remove("hidden"); deArrowPromotion.classList.remove("hidden");
deArrowPromotion.addEventListener("click", () => Config.config.showDeArrowPromotion = false); deArrowPromotion.addEventListener("click", () => Config.config.showDeArrowPromotion = false);
const closeButton = deArrowPromotion.querySelector(".close-button");
closeButton.addEventListener("click", (e) => {
e.preventDefault();
deArrowPromotion.classList.add("hidden");
Config.config.showDeArrowPromotion = false;
Config.config.showDeArrowInSettings = false;
});
} }
}); });
} }
@@ -558,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) => {

View File

@@ -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();
@@ -108,6 +109,10 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
const PageElements: PageElements = {}; const PageElements: PageElements = {};
[ [
"sbPopupLogo",
"sbYourWorkBox",
"videoInfo",
"sbFooter",
"sponsorBlockPopupBody", "sponsorBlockPopupBody",
"sponsorblockPopup", "sponsorblockPopup",
"sponsorStart", "sponsorStart",
@@ -198,6 +203,16 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
} }
PageElements.sbDonate.addEventListener("click", () => Config.config.donateClicked = Config.config.donateClicked + 1); PageElements.sbDonate.addEventListener("click", () => Config.config.donateClicked = Config.config.donateClicked + 1);
if (Config.config.cleanPopup) {
PageElements.sbPopupLogo.classList.add("hidden");
PageElements.sbYourWorkBox.classList.add("hidden");
PageElements.sbFooter.classList.add("hidden");
PageElements.sponsorTimesDonateContainer.classList.add("hidden");
PageElements.mainControls.classList.add("hidden");
PageElements.videoInfo.style.marginTop = "10px";
}
if (Config.config.testingServer) { if (Config.config.testingServer) {
PageElements.sbBetaServerWarning.classList.remove("hidden"); PageElements.sbBetaServerWarning.classList.remove("hidden");
PageElements.sbBetaServerWarning.addEventListener("click", function () { PageElements.sbBetaServerWarning.addEventListener("click", function () {
@@ -281,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) => {
@@ -804,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";

View File

@@ -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

View File

@@ -106,5 +106,5 @@ export function exportTimesAsHashParam(segments: SponsorTime[]): string {
export function normalizeChapterName(description: string): string { export function normalizeChapterName(description: string): string {
return description.toLowerCase().replace(/\.|:|-/g, "").replace(/\s+/g, " "); return description.toLowerCase().replace(/[.:'`"-]/ug, "").replace(/\s+/g, " ");
} }

47
src/utils/requests.ts Normal file
View 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);
});
}

View File

@@ -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] = {

View File

@@ -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
}); });