Added switch for chrome.runtime.onMessage

This commit is contained in:
Official Noob
2019-08-12 17:41:26 +01:00
committed by GitHub
parent 29a8608f9d
commit 44c4671977

View File

@@ -5,38 +5,29 @@ 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
return true; case "addSponsorTime":
} else if (request.message == "addSponsorTime") { addSponsorTime(request.time, request.videoID, callback);
addSponsorTime(request.time, request.videoID, callback); return true; //this allows the callback to be called later
case "getSponsorTimes":
//this allows the callback to be called later getSponsorTimes(request.videoID, function(sponsorTimes) {
return true; callback({sponsorTimes: sponsorTimes})
} else if (request.message == "getSponsorTimes") { });
getSponsorTimes(request.videoID, function(sponsorTimes) { return true; //this allows the callback to be called later
callback({ case "submitVote":
sponsorTimes: sponsorTimes submitVote(request.type, request.UUID, callback);
}) return true;
}); case "alertPrevious":
chrome.notifications.create("stillThere" + Math.random(), {
//this allows the callback to be called later type: "basic",
return true; title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
} else if (request.message == "submitVote") { message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
submitVote(request.type, request.UUID, callback); iconUrl: "./icons/LogoSponsorBlocker256px.png"
});
//this allows the callback to be called later }
return true;
} else if (request.message == "alertPrevious") {
chrome.notifications.create("stillThere" + Math.random(), {
type: "basic",
title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
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