diff options
author | Ajay <[email protected]> | 2022-10-03 16:59:49 -0400 |
---|---|---|
committer | Ajay <[email protected]> | 2022-10-03 16:59:49 -0400 |
commit | 6166ab3006e907729ec606f6881ca3acd9a94377 (patch) | |
tree | 2f7662b496935ee077cdd015ae465902b86ee97a | |
parent | f1498d51fa725741a2f12c84e7286223fc854fa2 (diff) | |
download | SponsorBlock-6166ab3006e907729ec606f6881ca3acd9a94377.tar.gz SponsorBlock-6166ab3006e907729ec606f6881ca3acd9a94377.zip |
Fix spamming user info on options page and improve popup values
-rw-r--r-- | src/config.ts | 2 | ||||
-rw-r--r-- | src/popup.ts | 12 | ||||
-rw-r--r-- | src/utils/licenseKey.ts | 7 |
3 files changed, 16 insertions, 5 deletions
diff --git a/src/config.ts b/src/config.ts index bed908a1..3913c656 100644 --- a/src/config.ts +++ b/src/config.ts @@ -88,6 +88,7 @@ interface SBConfig { payments: { licenseKey: string, lastCheck: number, + lastFreeCheck: number, freeAccess: boolean, chaptersAllowed: boolean } @@ -229,6 +230,7 @@ const Config: SBObject = { payments: { licenseKey: null, lastCheck: 0, + lastFreeCheck: 0, freeAccess: false, chaptersAllowed: false }, diff --git a/src/popup.ts b/src/popup.ts index 0661e1b6..37f2b799 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -10,6 +10,7 @@ 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"; const utils = new Utils(); interface MessageListener { @@ -259,9 +260,14 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { if (dontShowNotice != undefined && dontShowNotice) { PageElements.showNoticeAgain.style.display = "unset"; } - - utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&value=vip&value=permissions&value=freeChaptersAccess&userID=" - + Config.config.userID, (res) => { + + const values = ["userName", "viewCount", "minutesSaved", "vip", "permissions"]; + if (!Config.config.payments.freeAccess && !noRefreshFetchingChaptersAllowed()) values.push("freeChaptersAccess"); + + utils.asyncRequestToServer("GET", "/api/userInfo", { + userID: Config.config.userID, + values + }).then((res) => { if (res.status === 200) { const userInfo = JSON.parse(res.responseText); PageElements.usernameValue.innerText = userInfo.userName; diff --git a/src/utils/licenseKey.ts b/src/utils/licenseKey.ts index 02a328ff..7ce41a8a 100644 --- a/src/utils/licenseKey.ts +++ b/src/utils/licenseKey.ts @@ -46,7 +46,10 @@ export async function fetchingChaptersAllowed(): Promise<boolean> { if (Config.config.payments.chaptersAllowed) return true; - if (Config.config.payments.lastCheck === 0) { + 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", @@ -56,7 +59,7 @@ export async function fetchingChaptersAllowed(): Promise<boolean> { try { if (result.ok) { const userInfo = JSON.parse(result.responseText); - + Config.config.payments.lastCheck = Date.now(); if (userInfo.freeChaptersAccess) { Config.config.payments.freeAccess = true; |