mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 05:27:03 +03:00
reuse userinfo for isVip and remove lastIsVipUpdate
This commit is contained in:
@@ -487,6 +487,10 @@ function migrateOldSyncFormats(config: SBConfig) {
|
|||||||
if (!config["supportInvidious"] && config["invidiousInstances"].length !== invidiousList.length) {
|
if (!config["supportInvidious"] && config["invidiousInstances"].length !== invidiousList.length) {
|
||||||
config["invidiousInstances"] = invidiousList;
|
config["invidiousInstances"] = invidiousList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config["lastIsVipUpdate"]) {
|
||||||
|
chrome.storage.sync.remove("lastIsVipUpdate");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupConfig() {
|
async function setupConfig() {
|
||||||
|
|||||||
@@ -844,7 +844,9 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
|
|||||||
retryFetch();
|
retryFetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
lookupVipInformation(id);
|
if (Config.config.isVip) {
|
||||||
|
lockedCategoriesLookup(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEnabledActionTypes(): ActionType[] {
|
function getEnabledActionTypes(): ActionType[] {
|
||||||
@@ -859,39 +861,6 @@ function getEnabledActionTypes(): ActionType[] {
|
|||||||
return actionTypes;
|
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> {
|
async function lockedCategoriesLookup(id: string): Promise<void> {
|
||||||
const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4);
|
const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4);
|
||||||
const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix);
|
const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix);
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ 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&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) {
|
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;
|
||||||
@@ -202,6 +202,8 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
|||||||
}
|
}
|
||||||
PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
|
PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Config.config.isVip = userInfo.vip;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user