diff options
author | Michael C <[email protected]> | 2022-04-19 18:41:06 -0400 |
---|---|---|
committer | Michael C <[email protected]> | 2022-04-19 18:41:06 -0400 |
commit | ac533c612c9b807e51820f141f095da3e3f33f2e (patch) | |
tree | f22a8bfe748e849f4ceed3e6bca3c1e8d40dc142 | |
parent | 8aa10605c53bc3b1b31b1926f0adaf9479a936cc (diff) | |
download | SponsorBlock-ac533c612c9b807e51820f141f095da3e3f33f2e.tar.gz SponsorBlock-ac533c612c9b807e51820f141f095da3e3f33f2e.zip |
reuse userinfo for isVip and remove lastIsVipUpdate
-rw-r--r-- | src/config.ts | 4 | ||||
-rw-r--r-- | src/content.ts | 37 | ||||
-rw-r--r-- | src/popup.ts | 4 |
3 files changed, 10 insertions, 35 deletions
diff --git a/src/config.ts b/src/config.ts index 5113460f..58ad753a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -487,6 +487,10 @@ function migrateOldSyncFormats(config: SBConfig) { if (!config["supportInvidious"] && config["invidiousInstances"].length !== invidiousList.length) { config["invidiousInstances"] = invidiousList; } + + if (config["lastIsVipUpdate"]) { + chrome.storage.sync.remove("lastIsVipUpdate"); + } } async function setupConfig() { diff --git a/src/content.ts b/src/content.ts index f725fa00..c5fc7dbc 100644 --- a/src/content.ts +++ b/src/content.ts @@ -844,7 +844,9 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { retryFetch(); } - lookupVipInformation(id); + if (Config.config.isVip) { + lockedCategoriesLookup(id); + } } function getEnabledActionTypes(): ActionType[] { @@ -859,39 +861,6 @@ function getEnabledActionTypes(): ActionType[] { return actionTypes; } -function lookupVipInformation(id: string): void { - updateVipInfo().then((isVip) => { - if (isVip) { - lockedCategoriesLookup(id); - } - }); -} - -async function updateVipInfo(): Promise<boolean> { - const currentTime = Date.now(); - const lastUpdate = Config.config.lastIsVipUpdate; - if (currentTime - lastUpdate > 1000 * 60 * 60 * 72) { // 72 hours - Config.config.lastIsVipUpdate = currentTime; - - const response = await utils.asyncRequestToServer("GET", "/api/isUserVIP", { userID: Config.config.userID}); - - if (response.ok) { - let isVip = false; - try { - const vipResponse = JSON.parse(response.responseText)?.vip; - if (typeof(vipResponse) === "boolean") { - isVip = vipResponse; - } - } catch (e) { } //eslint-disable-line no-empty - - Config.config.isVip = isVip; - return isVip; - } - } - - return Config.config.isVip; -} - async function lockedCategoriesLookup(id: string): Promise<void> { const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4); const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix); diff --git a/src/popup.ts b/src/popup.ts index e06db4d1..5957f651 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -175,7 +175,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { PageElements.showNoticeAgain.style.display = "unset"; } - utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&userID=" + Config.config.userID, (res) => { + utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&value=vip&userID=" + Config.config.userID, (res) => { if (res.status === 200) { const userInfo = JSON.parse(res.responseText); PageElements.usernameValue.innerText = userInfo.userName; @@ -202,6 +202,8 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { } PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved); } + + Config.config.isVip = userInfo.vip; } }); |