Remove chapters payment checks

This commit is contained in:
Ajay
2023-03-18 21:27:26 -04:00
parent 9831c3393f
commit 2f68a66f13
11 changed files with 9 additions and 764 deletions

View File

@@ -38,9 +38,6 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
case "openHelp":
chrome.tabs.create({url: chrome.runtime.getURL('help/index.html')});
return false;
case "openUpsell":
chrome.tabs.create({url: chrome.runtime.getURL('upsell/index.html')});
return false;
case "openPage":
chrome.tabs.create({url: chrome.runtime.getURL(request.url)});
return false;

View File

@@ -6,7 +6,6 @@ import Utils from "../utils";
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
import { RectangleTooltip } from "../render/RectangleTooltip";
import SelectorComponent, { SelectorOption } from "./SelectorComponent";
import { noRefreshFetchingChaptersAllowed } from "../utils/licenseKey";
import { DEFAULT_CATEGORY } from "../utils/categoryUtils";
import { getFormattedTime, getFormattedTimeToSeconds } from "@ajayyy/maze-utils/lib/formating";
@@ -420,7 +419,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
// If permission not loaded, treat it like we have permission except chapter
const defaultBlockCategories = ["chapter"];
const permission = (Config.config.showCategoryWithoutPermission
|| Config.config.permissions[category as Category]) && (category !== "chapter" || noRefreshFetchingChaptersAllowed());
|| Config.config.permissions[category as Category]);
if ((defaultBlockCategories.includes(category)
|| (permission !== undefined && !Config.config.showCategoryWithoutPermission)) && !permission) continue;

View File

@@ -6,8 +6,6 @@ import { Category, CategorySkipOption } from "../../types";
import { getCategorySuffix } from "../../utils/categoryUtils";
import ToggleOptionComponent from "./ToggleOptionComponent";
import { fetchingChaptersAllowed } from "../../utils/licenseKey";
import LockSvg from "../../svg-icons/lock_svg";
export interface CategorySkipOptionsProps {
category: Category;
@@ -19,7 +17,6 @@ export interface CategorySkipOptionsProps {
export interface CategorySkipOptionsState {
color: string;
previewColor: string;
hideChapter: boolean;
}
export interface ToggleOption {
@@ -37,29 +34,11 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
// Setup state
this.state = {
color: props.defaultColor || Config.config.barTypes[this.props.category]?.color,
previewColor: props.defaultPreviewColor || Config.config.barTypes["preview-" + this.props.category]?.color,
hideChapter: true
previewColor: props.defaultPreviewColor || Config.config.barTypes["preview-" + this.props.category]?.color
};
fetchingChaptersAllowed().then((allowed) => {
this.setState({
hideChapter: !allowed
});
});
}
render(): React.ReactElement {
if (this.state.hideChapter) {
// Ensure force update refreshes this
fetchingChaptersAllowed().then((allowed) => {
if (allowed) {
this.setState({
hideChapter: !allowed
});
}
});
}
let defaultOption = "disable";
// Set the default opton properly
for (const categorySelection of Config.config.categorySelections) {
@@ -80,20 +59,10 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
}
}
let extraClasses = "";
const disabled = this.props.category === "chapter" && this.state.hideChapter;
if (disabled) {
extraClasses += " disabled";
if (!Config.config.showUpsells) {
return <></>;
}
}
return (
<>
<tr id={this.props.category + "OptionsRow"}
className={`categoryTableElement${extraClasses}`} >
className={`categoryTableElement`} >
<td id={this.props.category + "OptionName"}
className="categoryTableLabel">
{chrome.i18n.getMessage("category_" + this.props.category)}
@@ -104,14 +73,9 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
<select
className="optionsSelector"
defaultValue={defaultOption}
disabled={disabled}
onChange={this.skipOptionSelected.bind(this)}>
{this.getCategorySkipOptions()}
</select>
{disabled &&
<LockSvg className="upsellButton" onClick={() => chrome.tabs.create({url: chrome.runtime.getURL('upsell/index.html')})}/>
}
</td>
{this.props.category !== "chapter" &&
@@ -120,7 +84,6 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
<input
className="categoryColorTextBox option-text-box"
type="color"
disabled={disabled}
onChange={(event) => this.setColorState(event, false)}
value={this.state.color} />
</td>
@@ -140,7 +103,7 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
</tr>
<tr id={this.props.category + "DescriptionRow"}
className={`small-description categoryTableDescription${extraClasses}`}>
className={`small-description categoryTableDescription`}>
<td
colSpan={2}>
{chrome.i18n.getMessage("category_" + this.props.category + "_description")}
@@ -151,7 +114,7 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
</td>
</tr>
{this.getExtraOptionComponents(this.props.category, extraClasses, disabled)}
{this.getExtraOptionComponents(this.props.category)}
</>
);
@@ -235,16 +198,15 @@ class CategorySkipOptionsComponent extends React.Component<CategorySkipOptionsPr
}, 50);
}
getExtraOptionComponents(category: string, extraClasses: string, disabled: boolean): JSX.Element[] {
getExtraOptionComponents(category: string): JSX.Element[] {
const result = [];
for (const option of this.getExtraOptions(category)) {
result.push(
<tr key={option.configKey} className={extraClasses}>
<tr key={option.configKey}>
<td id={`${category}_${option.configKey}`} className="categoryExtraOptions">
<ToggleOptionComponent
configKey={option.configKey}
label={option.label}
disabled={!option.dontDisable && disabled}
style={{width: "inherit"}}
/>
</td>

View File

@@ -34,8 +34,6 @@ import { logDebug } from "./utils/logger";
import { importTimes } from "./utils/exporter";
import { ChapterVote } from "./render/ChapterVote";
import { openWarningDialog } from "./utils/warnings";
import { Tooltip } from "./render/Tooltip";
import { noRefreshFetchingChaptersAllowed } from "./utils/licenseKey";
import { waitFor } from "@ajayyy/maze-utils";
import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating";
import { setupVideoMutationListener, getChannelIDInfo, getVideo, refreshVideoAttachments, getIsAdPlaying, getIsLivePremiere, setIsAdPlaying, checkVideoIDChange, getVideoID, getYouTubeVideoID, setupVideoModule, checkIfNewVideoID, isOnInvidious, isOnMobileYouTube } from "@ajayyy/maze-utils/lib/video";
@@ -1002,14 +1000,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
setupVideoMutationListener();
const showChapterMessage = Config.config.showUpsells
&& Config.config.payments.lastCheck !== 0
&& !noRefreshFetchingChaptersAllowed()
&& Config.config.showChapterInfoMessage
&& Config.config.skipCount > 200;
const categories: string[] = Config.config.categorySelections.map((category) => category.name);
if (showChapterMessage && !categories.includes("chapter")) categories.push("chapter");
const extraRequestData: Record<string, unknown> = {};
const hashParams = getHashParams();
@@ -1018,7 +1009,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
const hashPrefix = (await getHash(getVideoID(), 1)).slice(0, 4) as VideoID & HashedValue;
const response = await utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
categories,
actionTypes: getEnabledActionTypes(showChapterMessage),
actionTypes: getEnabledActionTypes(),
userAgent: `${chrome.runtime.id}`,
...extraRequestData
});
@@ -1027,7 +1018,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
lastResponseStatus = response?.status;
if (response?.ok) {
let recievedSegments: SponsorTime[] = JSON.parse(response.responseText)
const recievedSegments: SponsorTime[] = JSON.parse(response.responseText)
?.filter((video) => video.videoID === getVideoID())
?.map((video) => video.segments)?.[0]
?.map((segment) => ({
@@ -1036,27 +1027,6 @@ async function sponsorsLookup(keepOldSubmissions = true) {
}))
?.sort((a, b) => a.segment[0] - b.segment[0]);
if (recievedSegments && recievedSegments.length) {
if (showChapterMessage) {
const chapterSegments = recievedSegments.filter((s) => s.actionType === ActionType.Chapter);
if (chapterSegments.length > 3) {
const prependElement = document.querySelector(".ytp-chrome-bottom") as HTMLElement;
if (prependElement) {
Config.config.showChapterInfoMessage = false;
new Tooltip({
text: `🟨${chrome.i18n.getMessage("chapterNewFeature")}${chapterSegments.slice(0, 3).map((s) => s.description).join(", ")}`,
linkOnClick: () => void chrome.runtime.sendMessage({ "message": "openUpsell" }),
referenceNode: prependElement.parentElement,
prependElement,
timeout: 1500,
leftOffset: "20px",
positionRealtive: false
});
}
}
recievedSegments = recievedSegments.filter((s) => s.actionType !== ActionType.Chapter);
}
sponsorDataFound = true;
// Check if any old submissions should be kept

View File

@@ -25,7 +25,6 @@ import { shortCategoryName } from "./utils/categoryUtils";
import { localizeHtmlPage } from "./utils/pageUtils";
import { exportTimes } from "./utils/exporter";
import GenericNotice from "./render/GenericNotice";
import { noRefreshFetchingChaptersAllowed } from "./utils/licenseKey";
import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating";
import { StorageChangesObject } from "@ajayyy/maze-utils/lib/config";
import { getHash } from "@ajayyy/maze-utils/lib/hash";
@@ -282,7 +281,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
}
const values = ["userName", "viewCount", "minutesSaved", "vip", "permissions"];
if (!Config.config.payments.freeAccess && !noRefreshFetchingChaptersAllowed()) values.push("freeChaptersAccess");
utils.asyncRequestToServer("GET", "/api/userInfo", {
publicUserID: await getHash(Config.config.userID),
@@ -317,13 +315,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
Config.config.isVip = userInfo.vip;
Config.config.permissions = userInfo.permissions;
if (userInfo.freeChaptersAccess) {
Config.config.payments.chaptersAllowed = userInfo.freeChaptersAccess;
Config.config.payments.freeAccess = userInfo.freeChaptersAccess;
Config.config.payments.lastCheck = Date.now();
Config.forceSyncUpdate("payments");
}
}
});

View File

@@ -1,83 +0,0 @@
import Config from "./config";
import { checkLicenseKey } from "./utils/licenseKey";
import { localizeHtmlPage } from "./utils/pageUtils";
import * as countries from "../public/res/countries.json";
import Utils from "./utils";
import { Category, CategorySkipOption } from "./types";
// This is needed, if Config is not imported before Utils, things break.
// Probably due to cyclic dependencies
Config.config;
const utils = new Utils();
window.addEventListener('DOMContentLoaded', init);
async function init() {
localizeHtmlPage();
const cantAfford = document.getElementById("cantAfford");
const cantAffordTexts = chrome.i18n.getMessage("cantAfford").split(/{|}/);
cantAfford.appendChild(document.createTextNode(cantAffordTexts[0]));
const discountButton = document.createElement("span");
discountButton.id = "discountButton";
discountButton.innerText = cantAffordTexts[1];
cantAfford.appendChild(discountButton);
cantAfford.appendChild(document.createTextNode(cantAffordTexts[2]));
const redeemButton = document.getElementById("redeemButton") as HTMLInputElement;
const redeemInput = document.getElementById("redeemCodeInput") as HTMLInputElement;
redeemButton.addEventListener("click", async () => {
const licenseKey = redeemInput.value;
if (await checkLicenseKey(licenseKey)) {
Config.config.payments.licenseKey = licenseKey;
Config.forceSyncUpdate("payments");
if (!utils.getCategorySelection("chapter")) {
Config.config.categorySelections.push({
name: "chapter" as Category,
option: CategorySkipOption.ShowOverlay
});
}
alert(chrome.i18n.getMessage("redeemSuccess"));
} else {
alert(chrome.i18n.getMessage("redeemFailed"));
}
});
discountButton.addEventListener("click", async () => {
const subsidizedSection = document.getElementById("subsidizedPrice");
subsidizedSection.classList.remove("hidden");
const oldSelector = document.getElementById("countrySelector");
if (oldSelector) oldSelector.remove();
const countrySelector = document.createElement("select");
countrySelector.id = "countrySelector";
countrySelector.className = "optionsSelector";
const defaultOption = document.createElement("option");
defaultOption.innerText = chrome.i18n.getMessage("chooseACountry");
countrySelector.appendChild(defaultOption);
for (const country of Object.keys(countries)) {
const option = document.createElement("option");
option.value = country;
option.innerText = country;
countrySelector.appendChild(option);
}
countrySelector.addEventListener("change", () => {
if (countries[countrySelector.value]?.allowed) {
document.getElementById("subsidizedLink").classList.remove("hidden");
document.getElementById("noSubsidizedLink").classList.add("hidden");
} else {
document.getElementById("subsidizedLink").classList.add("hidden");
document.getElementById("noSubsidizedLink").classList.remove("hidden");
}
});
subsidizedSection.appendChild(countrySelector);
});
}

View File

@@ -1,78 +0,0 @@
import Config from "../config";
import Utils from "../utils";
import * as CompileConfig from "../../config.json";
import { getHash } from "@ajayyy/maze-utils/lib/hash";
const utils = new Utils();
export async function checkLicenseKey(licenseKey: string): Promise<boolean> {
const result = await utils.asyncRequestToServer("GET", "/api/verifyToken", {
licenseKey
});
try {
if (result.ok && JSON.parse(result.responseText).allowed) {
Config.config.payments.chaptersAllowed = true;
Config.config.showChapterInfoMessage = false;
Config.config.payments.lastCheck = Date.now();
Config.forceSyncUpdate("payments");
return true;
}
} catch (e) { } //eslint-disable-line no-empty
return false
}
/**
* The other one also tried refreshing, so returns a promise
*/
export function noRefreshFetchingChaptersAllowed(): boolean {
return Config.config.payments.chaptersAllowed || CompileConfig["freeChapterAccess"];
}
export async function fetchingChaptersAllowed(): Promise<boolean> {
if (Config.config.payments.freeAccess || CompileConfig["freeChapterAccess"]) {
return true;
}
//more than 14 days
if (Config.config.payments.licenseKey && Date.now() - Config.config.payments.lastCheck > 14 * 24 * 60 * 60 * 1000) {
const licensePromise = checkLicenseKey(Config.config.payments.licenseKey);
if (!Config.config.payments.chaptersAllowed) {
return licensePromise;
}
}
if (Config.config.payments.chaptersAllowed) return true;
if (Config.config.payments.lastCheck === 0 && Date.now() - Config.config.payments.lastFreeCheck > 2 * 24 * 60 * 60 * 1000) {
Config.config.payments.lastFreeCheck = Date.now();
Config.forceSyncUpdate("payments");
// Check for free access if no license key, and it is the first time
const result = await utils.asyncRequestToServer("GET", "/api/userInfo", {
value: "freeChaptersAccess",
publicUserID: await getHash(Config.config.userID)
});
try {
if (result.ok) {
const userInfo = JSON.parse(result.responseText);
Config.config.payments.lastCheck = Date.now();
if (userInfo.freeChaptersAccess) {
Config.config.payments.freeAccess = true;
Config.config.payments.chaptersAllowed = true;
Config.config.showChapterInfoMessage = false;
Config.forceSyncUpdate("payments");
return true;
}
}
} catch (e) { } //eslint-disable-line no-empty
}
return false;
}