From a1f645ea0e5dd83b366d56f8d2a2e3348b0b84e4 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 9 Jul 2019 18:59:27 -0400 Subject: [PATCH] Added warning if you leave a page before submitting your sponsor times. --- background.js | 42 +++++++++++++++++++++++++++++++++++++++--- content.js | 6 ++++++ icon.png | Bin 0 -> 4554 bytes manifest.json | 3 ++- popup.js | 4 +++- 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 icon.png diff --git a/background.js b/background.js index 396cff91..bba98675 100644 --- a/background.js +++ b/background.js @@ -1,25 +1,34 @@ +var previousVideoID = null + chrome.tabs.onUpdated.addListener( // On tab update function(tabId, changeInfo, tab) { if (changeInfo != undefined && changeInfo.url != undefined) { let id = getYouTubeVideoID(changeInfo.url); if (changeInfo.url && id) { // If URL changed and is youtube video message contentScript the video id + videoIDChange(id); + chrome.tabs.sendMessage( tabId, { message: 'ytvideoid', id: id - }) + }); } } } ); + + chrome.runtime.onMessage.addListener(function (request, sender, callback) { - console.log(request.message) if (request.message == "submitTimes") { submitTimes(request.videoID); callback({ success: true }); + } else if(request.message == "ytvideoid") { + if (previousVideoID != request.videoID) { + videoIDChange(request.videoID); + } } }); @@ -29,7 +38,7 @@ function submitTimes(videoID) { chrome.storage.local.get([sponsorTimeKey], function(result) { let videoTimes = result[sponsorTimeKey]; - if (videoTimes != undefined && result.videoTimes != []) { + if (videoTimes != undefined && videoTimes != []) { //submit these times for (let i = 0; i < videoTimes.length; i++) { let xmlhttp = new XMLHttpRequest(); @@ -41,6 +50,33 @@ function submitTimes(videoID) { }); } +function videoIDChange(currentVideoID) { + //warn them if they had unsubmitted times + if (previousVideoID != null) { + //get the sponsor times from storage + let sponsorTimeKey = 'videoTimes' + previousVideoID; + chrome.storage.local.get([sponsorTimeKey], function(result) { + let videoTimes = result[sponsorTimeKey]; + + if (videoTimes != undefined && videoTimes.length > 0) { + //warn them that they have unsubmitted sponsor times + chrome.notifications.create("stillThere" + Math.random(), { + type: "basic", + title: "Do you want to submit the sponsor times for watch?v=" + previousVideoID + "?", + message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).", + iconUrl: "icon.png" + }); + } + + //set the previous video id to the currentID + previousVideoID = currentVideoID; + }); + } else { + console.log(currentVideoID) + previousVideoID = currentVideoID; + } +} + function getYouTubeVideoID(url) { // Return video id or false var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; var match = url.match(regExp); diff --git a/content.js b/content.js index 72b87fad..2a4c0718 100644 --- a/content.js +++ b/content.js @@ -2,6 +2,12 @@ if(id = getYouTubeVideoID(document.URL)){ // Direct Links //reset sponsor data found check sponsorDataFound = false; sponsorsLookup(id); + + //tell background.js about this + chrome.runtime.sendMessage({ + message: "ytvideoid", + videoID: id + }); } //was sponsor data found when doing SponsorsLookup diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..242daa29cf2a90304cea847d33023b45221509a2 GIT binary patch literal 4554 zcmV;*5jF0KP)W)*gnPXn>g3Tw zMt^TFEy*%2OK`9S-~dZbvHFY47CH$Mmq{GRmkWf+1wg_uZ;zWgymwcMD2hZ;L5`(- zVd*SOveAqzfEPr*v8BE3gO7Jr_4WlqW=pEScvvJ3c>^B!on_|8F=4+N;IDgm-qK#qS;p*BCwtaOvYsyqtVbLr%%~6n}D2NkR zFaS22jjKBRwRw7eZt5L3|D+<41cwTb{@%Xp$eC@G2WxZl3!VA-g>Fv8h*vfMP{Mt^ zz0~fV+tOHuQa}CZT{kc^Ma2jKSTMwkPdxL-uY?fqFP*p0X0fLFIhGQU6-;&<7@rGB z7$yio+~syM`a}aylgu!=L`lMfA%Qr0Xs@}`Zr5a{TazEUXU$>+!hkEt80Pl&2A}=i zma1;2w-K%k`b48IIoaT6C{lpXFViFe2|!BzJ|6|4vgLrRIDyM%lf_>$cadwN#3?=i zBn%4)0kC_=C#f2(n#oSJB-Nj5b$fjQ0h48g+{hR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eec69d12 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,8 @@ ], "permissions": [ "tabs", - "storage" + "storage", + "notifications" ], "browser_action": { "default_title": "SponsorBlock", diff --git a/popup.js b/popup.js index be457b72..decd0ea3 100644 --- a/popup.js +++ b/popup.js @@ -35,12 +35,14 @@ function loadTabData(tabs) { let videoTimeKey = "videoTimes" + currentVideoID; chrome.storage.local.get([videoTimeKey], function(result) { videoTimes = result[videoTimeKey]; - if (videoTimes != undefined && result.videoTimes != []) { + if (videoTimes != undefined && videoTimes != []) { if (videoTimes[videoTimes.length - 1]!= undefined && videoTimes[videoTimes.length - 1].length < 2) { startTimeChosen = true; } displayVideoTimes(); + } else { + videoTimes = [] } });