Merge pull request #103 from OfficialNoob/patch-20

Added switch for chrome.runtime.onMessage
This commit is contained in:
Ajay Ramachandran
2019-08-13 00:32:43 -04:00
committed by GitHub

View File

@@ -5,38 +5,39 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
}); });
chrome.runtime.onMessage.addListener(function (request, sender, callback) { chrome.runtime.onMessage.addListener(function (request, sender, callback) {
if (request.message == "submitTimes") { switch(request.message) {
submitTimes(request.videoID, callback); case "submitTimes":
submitTimes(request.videoID, callback);
//this allows the callback to be called later by the submitTimes function
return true; //this allows the callback to be called later by the submitTimes function
} else if (request.message == "addSponsorTime") { return true;
addSponsorTime(request.time, request.videoID, callback); case "addSponsorTime":
addSponsorTime(request.time, request.videoID, callback);
//this allows the callback to be called later
return true; //this allows the callback to be called later
} else if (request.message == "getSponsorTimes") { return true;
getSponsorTimes(request.videoID, function(sponsorTimes) { case "getSponsorTimes":
callback({ getSponsorTimes(request.videoID, function(sponsorTimes) {
sponsorTimes: sponsorTimes callback({
}) sponsorTimes: sponsorTimes
}); })
});
//this allows the callback to be called later
return true; //this allows the callback to be called later
} else if (request.message == "submitVote") { return true;
submitVote(request.type, request.UUID, callback); case "submitVote":
submitVote(request.type, request.UUID, callback);
//this allows the callback to be called later
return true; //this allows the callback to be called later
} else if (request.message == "alertPrevious") { return true;
chrome.notifications.create("stillThere" + Math.random(), { case "alertPrevious":
type: "basic", chrome.notifications.create("stillThere" + Math.random(), {
title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?", type: "basic",
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).", title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
iconUrl: "./icons/LogoSponsorBlocker256px.png" message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
}); iconUrl: "./icons/LogoSponsorBlocker256px.png"
} });
}
}); });
//add help page on install //add help page on install