Hide segments when voting from the popup

This commit is contained in:
Ajay
2022-02-06 14:04:54 -05:00
parent 4a8e769596
commit 32fa9c3398
4 changed files with 59 additions and 31 deletions

View File

@@ -203,6 +203,9 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
onMobileYouTube
}));
return true;
case "submitVote":
vote(request.type, request.UUID).then((response) => sendResponse(response));
return true;
}
}
@@ -1689,7 +1692,7 @@ function clearSponsorTimes() {
}
//if skipNotice is null, it will not affect the UI
async function vote(type: number, UUID: SegmentUUID, category?: Category, skipNotice?: SkipNoticeComponent): Promise<void> {
async function vote(type: number, UUID: SegmentUUID, category?: Category, skipNotice?: SkipNoticeComponent): Promise<VoteResponse> {
if (skipNotice !== null && skipNotice !== undefined) {
//add loading info
skipNotice.addVoteButtonInfo.bind(skipNotice)(chrome.i18n.getMessage("Loading"))
@@ -1717,6 +1720,8 @@ async function vote(type: number, UUID: SegmentUUID, category?: Category, skipNo
}
}
}
return response;
}
async function voteAsync(type: number, UUID: SegmentUUID, category?: Category): Promise<VoteResponse> {
@@ -1746,7 +1751,25 @@ async function voteAsync(type: number, UUID: SegmentUUID, category?: Category):
type: type,
UUID: UUID,
category: category
}, resolve);
}, (response) => {
if (response.successType === 1) {
// Change the sponsor locally
const segment = utils.getSponsorTimeFromUUID(sponsorTimes, UUID);
if (segment) {
if (type === 0) {
segment.hidden = SponsorHideType.Downvoted;
} else if (category) {
segment.category = category;
} else if (type === 1) {
segment.hidden = SponsorHideType.Visible;
}
updatePreviewBar();
}
}
resolve(response);
});
});
}