Fix spamming user info on options page and improve popup values

This commit is contained in:
Ajay
2022-10-03 16:59:49 -04:00
parent f1498d51fa
commit 6166ab3006
3 changed files with 15 additions and 4 deletions

View File

@@ -88,6 +88,7 @@ interface SBConfig {
payments: { payments: {
licenseKey: string, licenseKey: string,
lastCheck: number, lastCheck: number,
lastFreeCheck: number,
freeAccess: boolean, freeAccess: boolean,
chaptersAllowed: boolean chaptersAllowed: boolean
} }
@@ -229,6 +230,7 @@ const Config: SBObject = {
payments: { payments: {
licenseKey: null, licenseKey: null,
lastCheck: 0, lastCheck: 0,
lastFreeCheck: 0,
freeAccess: false, freeAccess: false,
chaptersAllowed: false chaptersAllowed: false
}, },

View File

@@ -10,6 +10,7 @@ import { shortCategoryName } from "./utils/categoryUtils";
import { localizeHtmlPage } from "./utils/pageUtils"; import { localizeHtmlPage } from "./utils/pageUtils";
import { exportTimes } from "./utils/exporter"; import { exportTimes } from "./utils/exporter";
import GenericNotice from "./render/GenericNotice"; import GenericNotice from "./render/GenericNotice";
import { noRefreshFetchingChaptersAllowed } from "./utils/licenseKey";
const utils = new Utils(); const utils = new Utils();
interface MessageListener { interface MessageListener {
@@ -260,8 +261,13 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.showNoticeAgain.style.display = "unset"; PageElements.showNoticeAgain.style.display = "unset";
} }
utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&value=vip&value=permissions&value=freeChaptersAccess&userID=" const values = ["userName", "viewCount", "minutesSaved", "vip", "permissions"];
+ Config.config.userID, (res) => { 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) { if (res.status === 200) {
const userInfo = JSON.parse(res.responseText); const userInfo = JSON.parse(res.responseText);
PageElements.usernameValue.innerText = userInfo.userName; PageElements.usernameValue.innerText = userInfo.userName;

View File

@@ -46,7 +46,10 @@ export async function fetchingChaptersAllowed(): Promise<boolean> {
if (Config.config.payments.chaptersAllowed) return true; 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 // Check for free access if no license key, and it is the first time
const result = await utils.asyncRequestToServer("GET", "/api/userInfo", { const result = await utils.asyncRequestToServer("GET", "/api/userInfo", {
value: "freeChaptersAccess", value: "freeChaptersAccess",