From 44c467197787223822a2ca2aa8b034222847fa7c Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 12 Aug 2019 17:41:26 +0100 Subject: Added switch for chrome.runtime.onMessage --- background.js | 55 +++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) (limited to 'background.js') diff --git a/background.js b/background.js index a0e0c798..bf5c2136 100644 --- a/background.js +++ b/background.js @@ -5,38 +5,29 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { }); chrome.runtime.onMessage.addListener(function (request, sender, callback) { - if (request.message == "submitTimes") { - submitTimes(request.videoID, callback); - - //this allows the callback to be called later by the submitTimes function - return true; - } else if (request.message == "addSponsorTime") { - addSponsorTime(request.time, request.videoID, callback); - - //this allows the callback to be called later - return true; - } else if (request.message == "getSponsorTimes") { - getSponsorTimes(request.videoID, function(sponsorTimes) { - callback({ - sponsorTimes: sponsorTimes - }) - }); - - //this allows the callback to be called later - return true; - } else if (request.message == "submitVote") { - submitVote(request.type, request.UUID, callback); - - //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" - }); - } + switch(request.message) { + case "submitTimes": + submitTimes(request.videoID, callback); + return true; //this allows the callback to be called later by the submitTimes function + case "addSponsorTime": + addSponsorTime(request.time, request.videoID, callback); + return true; //this allows the callback to be called later + case "getSponsorTimes": + getSponsorTimes(request.videoID, function(sponsorTimes) { + callback({sponsorTimes: sponsorTimes}) + }); + return true; //this allows the callback to be called later + case "submitVote": + submitVote(request.type, request.UUID, callback); + return true; + case "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 -- cgit v1.2.3 From c8438b9d59683846938287da47978fd275c9cd02 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 13 Aug 2019 00:32:33 -0400 Subject: Updated formatting --- background.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'background.js') diff --git a/background.js b/background.js index bf5c2136..164b2e3a 100644 --- a/background.js +++ b/background.js @@ -8,17 +8,27 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { switch(request.message) { case "submitTimes": submitTimes(request.videoID, callback); - return true; //this allows the callback to be called later by the submitTimes function + + //this allows the callback to be called later by the submitTimes function + return true; case "addSponsorTime": addSponsorTime(request.time, request.videoID, callback); - return true; //this allows the callback to be called later + + //this allows the callback to be called later + return true; case "getSponsorTimes": getSponsorTimes(request.videoID, function(sponsorTimes) { - callback({sponsorTimes: sponsorTimes}) + callback({ + sponsorTimes: sponsorTimes + }) }); - return true; //this allows the callback to be called later + + //this allows the callback to be called later + return true; case "submitVote": submitVote(request.type, request.UUID, callback); + + //this allows the callback to be called later return true; case "alertPrevious": chrome.notifications.create("stillThere" + Math.random(), { -- cgit v1.2.3