Made it auto vote when a sponsor is skipped

This commit is contained in:
Ajay Ramachandran
2019-08-14 21:50:32 -04:00
parent 08b8b63678
commit a7f3701272

View File

@@ -517,6 +517,9 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
if (trackViewCount) { if (trackViewCount) {
sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID); sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
} }
//vote on this
vote(1, currentUUID, true);
} }
} }
@@ -1064,10 +1067,13 @@ function resetVoteButtonInfo(UUID) {
document.getElementById("sponsorTimesDownvoteButtonsContainer" + UUID).style.removeProperty("display"); document.getElementById("sponsorTimesDownvoteButtonsContainer" + UUID).style.removeProperty("display");
} }
function vote(type, UUID) { //if inTheBackground is true, then no UI methods will be called
//add loading info function vote(type, UUID, inTheBackground = false) {
addVoteButtonInfo("Loading...", UUID) if (!inTheBackground) {
resetNoticeInfoMessage(UUID); //add loading info
addVoteButtonInfo("Loading...", UUID)
resetNoticeInfoMessage(UUID);
}
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
message: "submitVote", message: "submitVote",
@@ -1076,23 +1082,25 @@ function vote(type, UUID) {
}, function(response) { }, function(response) {
if (response != undefined) { if (response != undefined) {
//see if it was a success or failure //see if it was a success or failure
if (response.successType == 1) { if (!inTheBackground) {
//success if (response.successType == 1) {
if (type == 0) { //success
afterDownvote(UUID); if (type == 0) {
} afterDownvote(UUID);
} else if (response.successType == 0) { }
//failure: duplicate vote } else if (response.successType == 0) {
addNoticeInfoMessage(chrome.i18n.getMessage("voteFAIL"), UUID) //failure: duplicate vote
resetVoteButtonInfo(UUID); addNoticeInfoMessage(chrome.i18n.getMessage("voteFAIL"), UUID)
} else if (response.successType == -1) {
if (response.statusCode == 502) {
addNoticeInfoMessage(chrome.i18n.getMessage("serverDown"), UUID)
resetVoteButtonInfo(UUID);
} else {
//failure: unknown error
addNoticeInfoMessage(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID);
resetVoteButtonInfo(UUID); resetVoteButtonInfo(UUID);
} else if (response.successType == -1) {
if (response.statusCode == 502) {
addNoticeInfoMessage(chrome.i18n.getMessage("serverDown"), UUID)
resetVoteButtonInfo(UUID);
} else {
//failure: unknown error
addNoticeInfoMessage(chrome.i18n.getMessage("connectionError") + response.statusCode, UUID);
resetVoteButtonInfo(UUID);
}
} }
} }
} }