diff options
author | Ajay <[email protected]> | 2023-03-18 21:27:26 -0400 |
---|---|---|
committer | Ajay <[email protected]> | 2023-03-18 21:27:26 -0400 |
commit | 2f68a66f1369c8b876ad4e07ce7f4acf50f516c5 (patch) | |
tree | 44c46e7ea3ad71548a0572b70abb700405521747 | |
parent | 9831c3393f8ecb90d3b35f32b4b1a138c5e69259 (diff) | |
download | SponsorBlock-2f68a66f1369c8b876ad4e07ce7f4acf50f516c5.tar.gz SponsorBlock-2f68a66f1369c8b876ad4e07ce7f4acf50f516c5.zip |
Remove chapters payment checks
-rw-r--r-- | public/_locales/en/messages.json | 15 | ||||
-rw-r--r-- | public/upsell/index.html | 100 | ||||
-rw-r--r-- | public/upsell/styles.css | 397 | ||||
-rw-r--r-- | src/background.ts | 3 | ||||
-rw-r--r-- | src/components/SponsorTimeEditComponent.tsx | 3 | ||||
-rw-r--r-- | src/components/options/CategorySkipOptionsComponent.tsx | 50 | ||||
-rw-r--r-- | src/content.ts | 34 | ||||
-rw-r--r-- | src/popup.ts | 9 | ||||
-rw-r--r-- | src/upsell.ts | 83 | ||||
-rw-r--r-- | src/utils/licenseKey.ts | 78 | ||||
-rw-r--r-- | webpack/webpack.common.js | 1 |
11 files changed, 9 insertions, 764 deletions
diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index e5c8d69a..e6f0229f 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -1156,10 +1156,6 @@ "selectYourCountry": { "message": "Select your country" }, - "alreadyDonated": { - "message": "If you've donated any amount before now, you may redeem free access by emailing:", - "description": "After the colon is an email address" - }, "cantAfford": { "message": "If you can't afford to purchase a license, click {here} to see if you are eligible for a discount", "description": "Keep the curly braces. The word 'here' should be translated as well." @@ -1179,17 +1175,6 @@ "enterLicenseKey": { "message": "Enter License Key" }, - "chaptersPage1": { - "message": "SponsorBlock crowd-sourced chapters feature is only available to people who purchase a license, or for people who are granted access for free due their past contributions" - }, - "chaptersPage2": { - "message": "Note: Permission to submit chapters is still based on calculated reputation. Purchasing a license only allows you to view chapters submitted by others", - "description": "On the chapters page for getting access to the paid chapters feature" - }, - "chapterNewFeature": { - "message": "New Feature: Crowd-sourced custom chapters. These are custom-named sections in videos that can be stacked to get more and more precise. Purchase a license to view the chapters submitted on this video such as: ", - "description": "After the comma, a list of chapters for this video will appear" - }, "unsubmittedSegmentCounts": { "message": "You currently have {0} on {1}", "description": "Example: You currently have 12 unsubmitted segments on 5 videos" diff --git a/public/upsell/index.html b/public/upsell/index.html deleted file mode 100644 index 76f3644f..00000000 --- a/public/upsell/index.html +++ /dev/null @@ -1,100 +0,0 @@ -<!DOCTYPE html> - -<head> - <title>Upsell - SponsorBlock</title> - <meta charset="utf-8"> - - <link href="styles.css" rel="stylesheet" /> - - <script src="../js/upsell.js"></script> -</head> - -<body class="sponsorBlockPageBody"> - - <div id="title" class="titleBar"> - <img src="../icons/LogoSponsorBlocker256px.png" height="80" class="profilepic" /> - SponsorBlock - </div> - - <br /> - - <div class="center"> - <p> - __MSG_chaptersPage1__ - </p> - - <p class="smaller"> - __MSG_chaptersPage2__ - </p> - </div> - - <div class="center"> - <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/H_mP7bpbA_c?modestbranding=1&rel=0" title="Demo Video" - frameborder="0" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture" - allowfullscreen> - </iframe> - </div> - - - - <br /> - - <div class="center row-item"> - <a href="https://buy.ajay.app/l/sponsorblock" class="option-link side-by-side" target="_blank" rel="noreferrer"> - <div id="oneTimePurchase" class="option-button inline"> - __MSG_oneTimePurchase__ - </div> - </a> - - <a href="https://www.patreon.com/ajayyy" class="option-link side-by-side" target="_blank" rel="noreferrer"> - <div class="option-button side-by-side inline"> - __MSG_joinOnPatreon__ - </div> - </a> - </div> - - <div class="center row-item"> - <input id="redeemCodeInput" class="option-text-box" type="text" placeholder="__MSG_enterLicenseKey__"> - <div id="redeemButton" class="option-button inline"> - __MSG_redeem__ - </div> - </div> - - <div class="center row-item"> - <a href="https://www.patreon.com/oauth2/authorize?response_type=code&client_id=-W7ib8J-LB3jowb1fqE07A7RDUovy45_pOoWcjby6yr5upo6At8Jlg2BPhWDXO2k&redirect_uri=https%3A%2F%2Fsponsor.ajay.app%2Fapi%2FgenerateToken%2Fpatreon" - class="option-link" target="_blank" rel="noreferrer"> - <div class="option-button inline"> - __MSG_patreonSignIn__ - </div> - </a> - </div> - - <div class="center"> - <p id="cantAfford" class="smaller no-margin"> - </p> - </div> - - <div class="center"> - <p class="smaller no-margin"> - __MSG_alreadyDonated__ [email protected] - </p> - </div> - - <div id="subsidizedPrice" class="center hidden"> - __MSG_selectYourCountry__ - </div> - - <div id="subsidizedLink" class="center hidden"> - <a href="https://buy.ajay.app/l/sponsorblock/purchasing-power" class="option-link" target="_blank" - rel="noreferrer"> - <div class="option-button inline"> - __MSG_discountLink__ - </div> - </a> - </div> - - <div id="noSubsidizedLink" class="center hidden"> - __MSG_noDiscount__ - </div> - -</body>
\ No newline at end of file diff --git a/public/upsell/styles.css b/public/upsell/styles.css deleted file mode 100644 index ea1407cd..00000000 --- a/public/upsell/styles.css +++ /dev/null @@ -1,397 +0,0 @@ -/* Based on options page CSS */ -html { - color-scheme: dark; -} - -body { - font-family: sans-serif; -} - -.center { - text-align: center; -} - -.center p { - margin: auto; -} - -.inline { - display: inline-block; -} - -.bold { - font-weight: bold; -} - -.hidden { - display: none !important; -} - -.row-item { - margin-top: 10px; - margin-bottom: 10px; -} - -.keybind-status { - display: inline; -} - -.small-description { - color: white; - font-size: 13px; -} - -.medium-description { - color: white; - font-size: 15px; -} - -.option-text-box { - width: 300px; -} - -.option-button { - cursor: pointer; - - background-color: #c00000; - padding: 10px; - color: white; - border-radius: 5px; - font-size: 14px; - - width: max-content; -} - -.option-link { - text-decoration: none; -} - -.option-link.side-by-side { - padding: 50px; -} - -.option-button:hover { - background-color: #fc0303; -} - -.option-button.disabled { - cursor: default; - - background-color: #520000; - color: grey; -} - -#options { - max-width: 60%; - text-align: left; - display: inline-block; -} - -.switch-container:after { - content: attr(label-name); - position: absolute; - padding: 4px; - width: max-content; - - font-size: 14px; - color: white; -} - -.text-label-container { - font-size: 14px; - color: white; -} - -.switch { - position: relative; - display: inline-block; - width: 40px; - height: 24px; -} - -.switch input { - opacity: 0; - width: 0; - height: 0; -} - -.slider { - position: absolute; - cursor: pointer; - top: 0; - left: 0; - right: 0; - bottom: 0; - background-color: #707070; -} - -.animated * { - -webkit-transition: .4s; - transition: .4s; -} - -.slider:before { - position: absolute; - content: ""; - height: 16px; - width: 16px; - left: 4px; - bottom: 4px; - background-color: white; -} - -.animated .slider:before { - -webkit-transition: .4s; - transition: .4s; -} - -input:checked + .slider { - background-color: #fc0303; -} - -input:checked + .slider:before { - -webkit-transform: translateX(16px); - -ms-transform: translateX(16px); - transform: translateX(16px); -} - -/* Rounded sliders */ -.slider.round { - border-radius: 34px; -} - -.slider.round:before { - border-radius: 50%; -} - - -/* Boilerplate CSS from https://ajay.app */ - -body { - background-color: #333333; -} - -.projectPreview { - position: relative; -} - -.projectPreviewImage { - position: absolute; - left: -90px; - width: 80px; - top: 50%; - transform: translateY(-50%); -} - -.projectPreviewImageLarge { - position: absolute; - left: -210px; - width: 200px; - top: 50%; - transform: translateY(-20%); -} - -.projectPreviewImageLargeRight { - position: absolute; - right: -210px; - width: 200px; - top: 50%; - transform: translateY(-50%); -} - -.createdBy { - font-size: 14px; - text-align: center; - padding-top: 0px; - padding-bottom: 0px; - - display: inline-block; -} - -#title { - background-color: #636363; - - text-align: center; - vertical-align: middle; - - font-size: 50px; - color: #212121; - - padding: 20px; - - text-decoration: none; - - transition: font-size 1s; -} - -.subtitle { - font-size: 40px; - color: #dad8d8; - - padding-top: 10px; - - transition: font-size 0.4s; -} - -.subtitle:hover { - font-size: 45px; - - transition: font-size 0.4s; -} - -.profilepic { - background-color: #636363 !important; - vertical-align: middle; -} - -.profilepiccircle { - vertical-align: middle; - overflow: hidden; - border-radius: 50%; -} - -a { - text-decoration: underline; - color: inherit; -} - -.link { - padding: 20px; - - height: 80px; - - transition: height 0.2s; -} - -.link:hover { - height: 95px; - - transition: height 0.2s; -} - -#contact,.smalllink { - font-size: 25px; - color: #e8e8e8; - - text-align: center; - - padding: 10px; -} - -#contact { - text-decoration: none; -} - -p,li { - font-size: 20px; - color: #c4c4c4; - - padding: 10px; -} - -.smaller { - font-size: 12px; - text-align: center; -} - -.no-margin { - padding: 0; - margin: 0; -} - -p,li,code,a { - max-width: 60%; - text-align: left; - overflow-wrap: break-word; -} - -@media screen and (orientation:portrait) { - p,li,code,a { - max-width: 100%; - } - - .projectPreviewImage { - position: unset; - width: 130px; - display: block; - margin: auto; - transform: none; - } -} - -.previewImage { - max-height: 200px; -} - -img { - max-width: 100%; - - text-align: center; -} - -#recentPostTitle { - font-size: 30px; - color: #dad8d8; -} - -#recentPostDate { - font-size: 15px; - color: #dad8d8; -} - -h1,h2,h3,h4,h5,h6 { - color: #dad8d8; -} - -svg { - text-decoration: none; -} - -.number-container:before { - content: attr(label-name); - padding-right: 4px; - width: max-content; - - font-size: 14px; - color: white; -} - -/* React styles */ - -.categoryTableElement { - font-size: 16px; - - color: white; -} - -.categoryTableElement > * { - padding-right: 15px; - padding-bottom: 15px; -} - -.optionsSelector { - background-color: #c00000; - color: white; - - border: none; - font-size: 14px; - padding: 5px; - border-radius: 5px; -} - -.categoryColorTextBox { - width: 60px; - - background: none; - border: none; -} - -#subsidizedPrice { - margin-top: 5px; - margin-bottom: 5px; -} - -#discountButton { - text-decoration: underline; - cursor: pointer; -}
\ No newline at end of file diff --git a/src/background.ts b/src/background.ts index 382b3453..ad5fe807 100644 --- a/src/background.ts +++ b/src/background.ts @@ -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; diff --git a/src/components/SponsorTimeEditComponent.tsx b/src/components/SponsorTimeEditComponent.tsx index 2cd9f984..bfef57cc 100644 --- a/src/components/SponsorTimeEditComponent.tsx +++ b/src/components/SponsorTimeEditComponent.tsx @@ -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; diff --git a/src/components/options/CategorySkipOptionsComponent.tsx b/src/components/options/CategorySkipOptionsComponent.tsx index 486a43ed..b7b59c97 100644 --- a/src/components/options/CategorySkipOptionsComponent.tsx +++ b/src/components/options/CategorySkipOptionsComponent.tsx @@ -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> diff --git a/src/content.ts b/src/content.ts index d9c6a928..b795218e 100644 --- a/src/content.ts +++ b/src/content.ts @@ -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 diff --git a/src/popup.ts b/src/popup.ts index 2f988119..d361ef5e 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -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"); - } } }); diff --git a/src/upsell.ts b/src/upsell.ts deleted file mode 100644 index 1396d705..00000000 --- a/src/upsell.ts +++ /dev/null @@ -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); - }); -}
\ No newline at end of file diff --git a/src/utils/licenseKey.ts b/src/utils/licenseKey.ts deleted file mode 100644 index 67487faf..00000000 --- a/src/utils/licenseKey.ts +++ /dev/null @@ -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; -} diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 75583107..91e5ba53 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -101,7 +101,6 @@ module.exports = env => { options: path.join(__dirname, srcDir + 'options.ts'), help: path.join(__dirname, srcDir + 'help.ts'), permissions: path.join(__dirname, srcDir + 'permissions.ts'), - upsell: path.join(__dirname, srcDir + 'upsell.ts') }, output: { path: path.join(__dirname, '../dist/js'), |