From 62632792cc210311f5253361b90bd0ddcba165b6 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 13:28:50 +0100 Subject: [PATCH 01/35] Removed tabs permission --- manifest.json | 1 - 1 file changed, 1 deletion(-) diff --git a/manifest.json b/manifest.json index 1fe36a7c..0f48727c 100644 --- a/manifest.json +++ b/manifest.json @@ -37,7 +37,6 @@ "help/style.css" ], "permissions": [ - "tabs", "storage", "notifications", "https://sponsor.ajay.app/*" From 077efd2de3e3428b044785b93ffd97e4e65d33a9 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 14:02:06 +0100 Subject: [PATCH 02/35] Moving to content script --- content.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content.js b/content.js index 73348973..d124217b 100644 --- a/content.js +++ b/content.js @@ -80,8 +80,8 @@ chrome.runtime.onMessage.addListener(messageListener); function messageListener(request, sender, sendResponse) { //message from background script - if (request.message == "ytvideoid") { - videoIDChange(request.id); + if (request.message == "TabUpdate") { + if(id = getYouTubeVideoID(document.URL)) videoIDChange(id); } //messages from popup script @@ -1165,4 +1165,4 @@ function getYouTubeVideoStartTime(url) { } return startTime; -} \ No newline at end of file +} From 410f5fc138be744b06e38f322734b6e52221b6a7 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 14:03:13 +0100 Subject: [PATCH 03/35] Update background.js --- background.js | 60 +++++++-------------------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/background.js b/background.js index cbd45531..6a1d972b 100644 --- a/background.js +++ b/background.js @@ -10,24 +10,17 @@ var sponsorVideoID = null; chrome.tabs.onActivated.addListener( function(activeInfo) { chrome.tabs.get(activeInfo.tabId, function(tab) { - let id = getYouTubeVideoID(tab.url); - - //if this even is a YouTube tab - if (id) { - videoIDChange(id, activeInfo.tabId); - } + TabUpdate(activeInfo.tabId); }) } ); //when a tab changes URLs chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { - if (changeInfo != undefined && changeInfo.url != undefined) { - let id = getYouTubeVideoID(changeInfo.url); - - //if URL changed and is youtube video message contentScript the video id - if (changeInfo.url && id) { - videoIDChange(id, tabId); + if (changeInfo != undefined) { + //if URL changed + if (tabId) { + TabUpdate(tabId); } } }); @@ -176,42 +169,11 @@ function submitTimes(videoID, callback) { }); } -function videoIDChange(currentVideoID, tabId) { +function TabUpdate(tabId) { //send a message to the content script chrome.tabs.sendMessage(tabId, { - message: 'ytvideoid', - id: currentVideoID + message: 'update' }); - - //not a url change - if (sponsorVideoID == currentVideoID){ - return; - } - sponsorVideoID = currentVideoID; - - //warn them if they had unsubmitted times - if (previousVideoID != null) { - //get the sponsor times from storage - let sponsorTimeKey = 'sponsorTimes' + previousVideoID; - chrome.storage.sync.get([sponsorTimeKey], function(result) { - let sponsorTimes = result[sponsorTimeKey]; - - if (sponsorTimes != undefined && sponsorTimes.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: "./icons/LogoSponsorBlocker256px.png" - }); - } - - //set the previous video id to the currentID - previousVideoID = currentVideoID; - }); - } else { - previousVideoID = currentVideoID; - } } function getUserID(callback) { @@ -263,11 +225,5 @@ function sendRequestToServer(type, address, callback) { xmlhttp.send(); } -function getYouTubeVideoID(url) { // Return video id or false - var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; - var match = url.match(regExp); - return (match && match[7].length == 11) ? match[7] : false; -} - //uuid generator function from https://gist.github.com/jed/982883 -function generateUUID(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,generateUUID)} \ No newline at end of file +function generateUUID(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,generateUUID)} From 2067b1c78706012b4451a1168485abf3ea7ea42b Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 14:04:21 +0100 Subject: [PATCH 04/35] Removed unused lines --- background.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/background.js b/background.js index 6a1d972b..cc45246f 100644 --- a/background.js +++ b/background.js @@ -1,11 +1,6 @@ -var previousVideoID = null - //the id of this user, randomly generated once per install var userID = null; -//the last video id loaded, to make sure it is a video id change -var sponsorVideoID = null; - //when a new tab is highlighted chrome.tabs.onActivated.addListener( function(activeInfo) { From a9ea22f5050c205084685a586d91c800cfa11b93 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 14:43:15 +0100 Subject: [PATCH 05/35] Get ID from storage API --- popup.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/popup.js b/popup.js index 8368f274..8da7330d 100644 --- a/popup.js +++ b/popup.js @@ -221,16 +221,18 @@ function runThePopup() { } }); - chrome.tabs.query({ active: true, currentWindow: true }, loadTabData); + function OnTabs(tabs) { + chrome.storage.sync.get(['videoid'], function(result) { + loadTabData(tabs, result.videoid); + }); + } - function loadTabData(tabs) { - //set current videoID - currentVideoID = getYouTubeVideoID(tabs[0].url); + function loadTabData(tabs, currentVideoID) { if (!currentVideoID) { //this isn't a YouTube video then @@ -1143,4 +1145,4 @@ if (chrome.tabs != undefined) { //this means it is actually opened in the popup runThePopup(); -} \ No newline at end of file +} From 22e7c6a40d6af9a8523aabfa201380c65a8f1dc9 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 14:44:48 +0100 Subject: [PATCH 06/35] Sync Video ID with Storage API --- content.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/content.js b/content.js index d124217b..d1fdd32c 100644 --- a/content.js +++ b/content.js @@ -179,11 +179,12 @@ document.onkeydown = function(e){ } function videoIDChange(id) { - //not a url change - if (sponsorVideoID == id){ - return; - } + //not a url change + if (sponsorVideoID == id) return; + + chrome.storage.sync.set({videoid: id}); + //close popup closeInfoMenu(); From 4c12bb9c2f5863fbbbecdc988c072ed6e29e8900 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 16:45:23 +0100 Subject: [PATCH 07/35] camelCase --- background.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/background.js b/background.js index cc45246f..9640bec5 100644 --- a/background.js +++ b/background.js @@ -5,7 +5,7 @@ var userID = null; chrome.tabs.onActivated.addListener( function(activeInfo) { chrome.tabs.get(activeInfo.tabId, function(tab) { - TabUpdate(activeInfo.tabId); + tabUpdate(activeInfo.tabId); }) } ); @@ -15,7 +15,7 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { if (changeInfo != undefined) { //if URL changed if (tabId) { - TabUpdate(tabId); + tabUpdate(tabId); } } }); @@ -164,7 +164,7 @@ function submitTimes(videoID, callback) { }); } -function TabUpdate(tabId) { +function tabUpdate(tabId) { //send a message to the content script chrome.tabs.sendMessage(tabId, { message: 'update' From 2a64afe9dc978b5acdd8a4dc0831ff71eb32ef9f Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 16:48:00 +0100 Subject: [PATCH 08/35] camelCase --- popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/popup.js b/popup.js index 8da7330d..dda77b3a 100644 --- a/popup.js +++ b/popup.js @@ -226,7 +226,7 @@ function runThePopup() { currentWindow: true }, loadTabData); - function OnTabs(tabs) { + function onTabs(tabs) { chrome.storage.sync.get(['videoid'], function(result) { loadTabData(tabs, result.videoid); }); From 074f7c5456d56fd2a7b11bcc639bfaf876a772ba Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 16:50:33 +0100 Subject: [PATCH 09/35] Switched callback to onTabs --- popup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/popup.js b/popup.js index dda77b3a..e1a63818 100644 --- a/popup.js +++ b/popup.js @@ -224,11 +224,11 @@ function runThePopup() { chrome.tabs.query({ active: true, currentWindow: true - }, loadTabData); + }, onTabs); function onTabs(tabs) { chrome.storage.sync.get(['videoid'], function(result) { - loadTabData(tabs, result.videoid); + loadTabData(tabs, result.videoid); }); } From e1f1814748f8ca74ad7fe9d4e0e1547d2e206f37 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 17:03:58 +0100 Subject: [PATCH 10/35] Moved code from background.js --- content.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/content.js b/content.js index d1fdd32c..a21c3164 100644 --- a/content.js +++ b/content.js @@ -184,6 +184,30 @@ function videoIDChange(id) { if (sponsorVideoID == id) return; chrome.storage.sync.set({videoid: id}); + + //warn them if they had unsubmitted times + if (previousVideoID != null) { + //get the sponsor times from storage + let sponsorTimeKey = 'sponsorTimes' + previousVideoID; + chrome.storage.sync.get([sponsorTimeKey], function(result) { + let sponsorTimes = result[sponsorTimeKey]; + + if (sponsorTimes != undefined && sponsorTimes.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: "./icons/LogoSponsorBlocker256px.png" + }); + } + + //set the previous video id to the currentID + previousVideoID = id; + }); + } else { + previousVideoID = id; + } //close popup closeInfoMenu(); From 301e16b8f13bdf060e99acb9f60b9d65e33bc8de Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 19:25:29 +0100 Subject: [PATCH 11/35] Removed tabUpdate as detecting in contentscript --- background.js | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/background.js b/background.js index 9640bec5..adafe098 100644 --- a/background.js +++ b/background.js @@ -1,24 +1,8 @@ //the id of this user, randomly generated once per install var userID = null; -//when a new tab is highlighted -chrome.tabs.onActivated.addListener( - function(activeInfo) { - chrome.tabs.get(activeInfo.tabId, function(tab) { - tabUpdate(activeInfo.tabId); - }) - } -); - -//when a tab changes URLs -chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { - if (changeInfo != undefined) { - //if URL changed - if (tabId) { - tabUpdate(tabId); - } - } -}); +//the last video id loaded, to make sure it is a video id change +var sponsorVideoID = null; chrome.runtime.onMessage.addListener(function (request, sender, callback) { if (request.message == "submitTimes") { @@ -164,13 +148,6 @@ function submitTimes(videoID, callback) { }); } -function tabUpdate(tabId) { - //send a message to the content script - chrome.tabs.sendMessage(tabId, { - message: 'update' - }); -} - function getUserID(callback) { if (userID != null) { callback(userID); From 883871123a20b188b9ecc74e1bbee9bb4e889e33 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 19:26:26 +0100 Subject: [PATCH 12/35] Update content.js --- content.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/content.js b/content.js index a21c3164..48613b67 100644 --- a/content.js +++ b/content.js @@ -78,12 +78,11 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) { //get messages from the background script and the popup chrome.runtime.onMessage.addListener(messageListener); +window.addEventListener("hashchange", function(event){ + if(id = getYouTubeVideoID(document.URL)) videoIDChange(id); +}); + function messageListener(request, sender, sendResponse) { - //message from background script - if (request.message == "TabUpdate") { - if(id = getYouTubeVideoID(document.URL)) videoIDChange(id); - } - //messages from popup script if (request.message == "sponsorStart") { sponsorMessageStarted(sendResponse); From 6707d6df8d534799a3a47ebfcbd8f08b05e0c496 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 19:59:15 +0100 Subject: [PATCH 13/35] Added onUpdated back as did not work --- background.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/background.js b/background.js index adafe098..ac174a3e 100644 --- a/background.js +++ b/background.js @@ -4,6 +4,12 @@ var userID = null; //the last video id loaded, to make sure it is a video id change var sponsorVideoID = null; +chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { + chrome.runtime.sendMessage({ + message: "update", + }); +}); + chrome.runtime.onMessage.addListener(function (request, sender, callback) { if (request.message == "submitTimes") { submitTimes(request.videoID, callback); From 1b5d5f8a3a9f1a6ab8021239744b25f8f9d8c14d Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 20:15:23 +0100 Subject: [PATCH 14/35] Added tab update back --- content.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/content.js b/content.js index 48613b67..057e8eaf 100644 --- a/content.js +++ b/content.js @@ -84,6 +84,11 @@ window.addEventListener("hashchange", function(event){ function messageListener(request, sender, sendResponse) { //messages from popup script + + if (request.message == "update") { + if(id = getYouTubeVideoID(document.URL)) videoIDChange(id); + } + if (request.message == "sponsorStart") { sponsorMessageStarted(sendResponse); } From 02448307ab407bdfc1b3561a01329179251b9457 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 20:32:18 +0100 Subject: [PATCH 15/35] Update background.js --- background.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/background.js b/background.js index ac174a3e..da9a1d39 100644 --- a/background.js +++ b/background.js @@ -5,9 +5,9 @@ var userID = null; var sponsorVideoID = null; chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { - chrome.runtime.sendMessage({ - message: "update", - }); + chrome.tabs.sendMessage(tabId, { + message: 'update', + }); }); chrome.runtime.onMessage.addListener(function (request, sender, callback) { From 866cc33f0e7c52d996c50eb7684a927f99db5ab0 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Thu, 8 Aug 2019 20:33:05 +0100 Subject: [PATCH 16/35] Update content.js --- content.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/content.js b/content.js index 057e8eaf..41ea3f78 100644 --- a/content.js +++ b/content.js @@ -1,6 +1,6 @@ //was sponsor data found when doing SponsorsLookup var sponsorDataFound = false; - +var previousVideoID = null; //the actual sponsorTimes if loaded and UUIDs associated with them var sponsorTimes = null; var UUIDs = null; @@ -77,10 +77,6 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) { //get messages from the background script and the popup chrome.runtime.onMessage.addListener(messageListener); - -window.addEventListener("hashchange", function(event){ - if(id = getYouTubeVideoID(document.URL)) videoIDChange(id); -}); function messageListener(request, sender, sendResponse) { //messages from popup script From 1ab33375ecdac3da9648cebc5e47b6172733ab86 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 11 Aug 2019 13:51:59 +0100 Subject: [PATCH 17/35] Update background.js --- background.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/background.js b/background.js index c08ad16b..9e6f5259 100644 --- a/background.js +++ b/background.js @@ -1,3 +1,6 @@ +//the id of this user, randomly generated once per install +var userID = null; + chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { chrome.tabs.sendMessage(tabId, { message: 'update', From 2580577ce0b4251d095fe538ede34876a4c51907 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 11 Aug 2019 12:49:25 -0400 Subject: [PATCH 18/35] Added comments --- content.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content.js b/content.js index 5775abc1..bbfc0e11 100644 --- a/content.js +++ b/content.js @@ -206,6 +206,7 @@ function videoIDChange(id) { previousVideoID = id; }); } else { + //set the previous id now, don't wait for chrome.storage.get previousVideoID = id; } @@ -1190,4 +1191,4 @@ function getYouTubeVideoStartTime(url) { } return startTime; -} \ No newline at end of file +} From 1aab52edbe1453aa667774205d3f50b515ab870a Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 11 Aug 2019 19:27:38 +0100 Subject: [PATCH 19/35] Remove userID --- background.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/background.js b/background.js index 9e6f5259..c08ad16b 100644 --- a/background.js +++ b/background.js @@ -1,6 +1,3 @@ -//the id of this user, randomly generated once per install -var userID = null; - chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { chrome.tabs.sendMessage(tabId, { message: 'update', From 60242df3c9af20be766f19926d1ae04736a5c5bb Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 11 Aug 2019 19:29:38 +0100 Subject: [PATCH 20/35] Removed stuff thats in utils.js --- content.js | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/content.js b/content.js index bbfc0e11..55afecf4 100644 --- a/content.js +++ b/content.js @@ -1169,26 +1169,3 @@ function sendRequestToCustomServer(type, fullAddress, callback) { //submit this request xmlhttp.send(); } - -function getYouTubeVideoID(url) { // Returns with video id else returns false - var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; - var match = url.match(regExp); - var id = new URL(url).searchParams.get("v"); - if (url.includes("/embed/")) { - //it is an embed, don't search for v - id = match[7]; - } - - return (match && match[7].length == 11) ? id : false; -} - -//returns the start time of the video if there was one specified (ex. ?t=5s) -function getYouTubeVideoStartTime(url) { - let searchParams = new URL(url).searchParams; - var startTime = searchParams.get("t"); - if (startTime == null) { - startTime = searchParams.get("time_continue"); - } - - return startTime; -} From c7d03aa4238b3f0499a0c7cc077ef312e5600d22 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 11 Aug 2019 19:32:44 +0100 Subject: [PATCH 21/35] videoID --- popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/popup.js b/popup.js index 2e2ac15e..27a84b8f 100644 --- a/popup.js +++ b/popup.js @@ -207,7 +207,7 @@ function runThePopup() { }, onTabs); function onTabs(tabs) { - chrome.storage.sync.get(['videoid'], function(result) { + chrome.storage.sync.get(['videoID'], function(result) { loadTabData(tabs, result.videoid); }); } From 28322f19b583b2b51f3e9cff3b14d419528fca28 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 11 Aug 2019 19:36:52 +0100 Subject: [PATCH 22/35] videoID --- content.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content.js b/content.js index 55afecf4..e14a5d56 100644 --- a/content.js +++ b/content.js @@ -183,7 +183,7 @@ function videoIDChange(id) { //not a url change if (sponsorVideoID == id) return; - chrome.storage.sync.set({videoid: id}); + chrome.storage.sync.set({videoID: id}); //warn them if they had unsubmitted times if (previousVideoID != null) { From 19a1a5efda556c8ef6d0a187cc17a7ab31c426fe Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 11 Aug 2019 21:20:10 +0100 Subject: [PATCH 23/35] Added alertPrevious message --- background.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index c08ad16b..21a605d7 100644 --- a/background.js +++ b/background.js @@ -29,7 +29,14 @@ chrome.runtime.onMessage.addListener(function (request, sender, 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" + }); + } }); //add help page on install From f254a99d6f5cf1bfc90864154a6b565cbff0824f Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Sun, 11 Aug 2019 21:21:04 +0100 Subject: [PATCH 24/35] notifications --- content.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/content.js b/content.js index e14a5d56..75378e32 100644 --- a/content.js +++ b/content.js @@ -194,12 +194,10 @@ function videoIDChange(id) { if (sponsorTimes != undefined && sponsorTimes.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: "./icons/LogoSponsorBlocker256px.png" - }); + chrome.runtime.sendMessage({ + message: "alertPrevious", + previousVideoID: previousVideoID + }) } //set the previous video id to the currentID From a5d605f53980e3548f37f3729e211a1e16e2b365 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 12 Aug 2019 13:38:27 +0100 Subject: [PATCH 25/35] Removed videoID as now message active tab --- popup.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/popup.js b/popup.js index 27a84b8f..c7fc607c 100644 --- a/popup.js +++ b/popup.js @@ -207,9 +207,11 @@ function runThePopup() { }, onTabs); function onTabs(tabs) { - chrome.storage.sync.get(['videoID'], function(result) { - loadTabData(tabs, result.videoid); - }); + chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) { + if (result.videoID) { + loadTabData(tabs, result.videoid); + } + }); } function loadTabData(tabs, currentVideoID) { From 67c4acbc5ec73c92b259d13fbd53e846ac13cc25 Mon Sep 17 00:00:00 2001 From: Official Noob <31563761+OfficialNoob@users.noreply.github.com> Date: Mon, 12 Aug 2019 13:38:35 +0100 Subject: [PATCH 26/35] Removed videoID as now message active tab --- content.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/content.js b/content.js index 75378e32..c6e0fbdb 100644 --- a/content.js +++ b/content.js @@ -182,8 +182,6 @@ function videoIDChange(id) { //not a url change if (sponsorVideoID == id) return; - - chrome.storage.sync.set({videoID: id}); //warn them if they had unsubmitted times if (previousVideoID != null) { From 5adeeed6346a7d24ac6dce16370c8e685ff56cc7 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 11:42:39 -0400 Subject: [PATCH 27/35] Made editing not possible on unfinished sponsors. Resolved https://github.com/ajayyy/SponsorBlock/issues/77 --- popup.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/popup.js b/popup.js index c7fc607c..0a0d7ecc 100644 --- a/popup.js +++ b/popup.js @@ -492,7 +492,6 @@ function runThePopup() { } currentSponsorTimeContainer.innerText = currentSponsorTimeMessage; - currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index)); sponsorTimesContainer.appendChild(currentSponsorTimeContainer); sponsorTimesContainer.appendChild(deleteButton); @@ -500,6 +499,8 @@ function runThePopup() { //only if it is a complete sponsor time if (sponsorTimes[i].length > 1) { sponsorTimesContainer.appendChild(editButton); + + currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index)); } } From 43e3d03e9a1ab8e2c54269abe79d5fd8ca7a80d8 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 12:02:01 -0400 Subject: [PATCH 28/35] Added better error checking --- popup.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/popup.js b/popup.js index 0a0d7ecc..8c6a5f16 100644 --- a/popup.js +++ b/popup.js @@ -208,22 +208,24 @@ function runThePopup() { function onTabs(tabs) { chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) { - if (result.videoID) { - loadTabData(tabs, result.videoid); - } + if (result != undefined && result.videoID) { + loadTabData(tabs, result.videoID); + } else if (result == undefined && chrome.runtime.lastError) { + //this isn't a YouTube video then, or at least the content script is not loaded + displayNoVideo(); + } }); } - function loadTabData(tabs, currentVideoID) { - - if (!currentVideoID) { + function loadTabData(tabs, videoID) { + if (!videoID) { //this isn't a YouTube video then displayNoVideo(); return; } //load video times for this video - let sponsorTimeKey = "sponsorTimes" + currentVideoID; + let sponsorTimeKey = "sponsorTimes" + videoID; chrome.storage.sync.get([sponsorTimeKey], function(result) { let sponsorTimesStorage = result[sponsorTimeKey]; if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { @@ -499,7 +501,7 @@ function runThePopup() { //only if it is a complete sponsor time if (sponsorTimes[i].length > 1) { sponsorTimesContainer.appendChild(editButton); - + currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index)); } } From 012a36b931d1bcd9193dacaa66fe75166f5e2d8e Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 12:04:57 -0400 Subject: [PATCH 29/35] Increased button padding --- popup.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/popup.css b/popup.css index cb86b962..49a29ccc 100644 --- a/popup.css +++ b/popup.css @@ -80,8 +80,8 @@ h1.popupElement { .mediumLink.popupElement { font-size: 15px; - padding-left: 15px; - padding-right: 15px; + margin-left: 25px; + margin-right: 25px; text-decoration: underline; cursor: pointer; } From e281b90699bfa6e72fc052f9b1e902169511682c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 12:05:16 -0400 Subject: [PATCH 30/35] Fixed sponsor times not properly saving --- popup.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/popup.js b/popup.js index 8c6a5f16..71e1ef83 100644 --- a/popup.js +++ b/popup.js @@ -209,7 +209,9 @@ function runThePopup() { function onTabs(tabs) { chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) { if (result != undefined && result.videoID) { - loadTabData(tabs, result.videoID); + currentVideoID = result.videoID; + + loadTabData(tabs); } else if (result == undefined && chrome.runtime.lastError) { //this isn't a YouTube video then, or at least the content script is not loaded displayNoVideo(); @@ -217,15 +219,15 @@ function runThePopup() { }); } - function loadTabData(tabs, videoID) { - if (!videoID) { + function loadTabData(tabs) { + if (!currentVideoID) { //this isn't a YouTube video then displayNoVideo(); return; } //load video times for this video - let sponsorTimeKey = "sponsorTimes" + videoID; + let sponsorTimeKey = "sponsorTimes" + currentVideoID; chrome.storage.sync.get([sponsorTimeKey], function(result) { let sponsorTimesStorage = result[sponsorTimeKey]; if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) { From 3f815a18c4b507e6622824c371e7aabfc72b4f6d Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 12:21:20 -0400 Subject: [PATCH 31/35] Added a sponsor time preview. It skips 2 seconds before the start time so you can preview how it feels. Also increased the space between the times and the clear times button. Resolves https://github.com/ajayyy/SponsorBlock/issues/66 --- content.js | 4 ++++ popup.html | 2 ++ popup.js | 51 ++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/content.js b/content.js index 5a836c1d..1b4db72e 100644 --- a/content.js +++ b/content.js @@ -119,6 +119,10 @@ function messageListener(request, sender, sendResponse) { }) } + if (request.message == "skipToTime") { + v.currentTime = request.time; + } + if (request.message == "getChannelURL") { sendResponse({ channelURL: channelURL diff --git a/popup.html b/popup.html index 30195294..82c2d66c 100644 --- a/popup.html +++ b/popup.html @@ -93,6 +93,8 @@ + +
diff --git a/popup.js b/popup.js index 71e1ef83..3359413e 100644 --- a/popup.js +++ b/popup.js @@ -210,7 +210,7 @@ function runThePopup() { chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) { if (result != undefined && result.videoID) { currentVideoID = result.videoID; - + loadTabData(tabs); } else if (result == undefined && chrome.runtime.lastError) { //this isn't a YouTube video then, or at least the content script is not loaded @@ -473,8 +473,11 @@ function runThePopup() { let index = i; deleteButton.addEventListener("click", () => deleteSponsorTime(index)); - let spacer = document.createElement("span"); - spacer.innerText = " "; + let previewButton = document.createElement("span"); + previewButton.id = "sponsorTimePreviewButton" + i; + previewButton.innerText = "Preview"; + previewButton.className = "mediumLink popupElement"; + previewButton.addEventListener("click", () => previewSponsorTime(index)); let editButton = document.createElement("span"); editButton.id = "sponsorTimeEditButton" + i; @@ -502,6 +505,7 @@ function runThePopup() { //only if it is a complete sponsor time if (sponsorTimes[i].length > 1) { + sponsorTimesContainer.appendChild(previewButton); sponsorTimesContainer.appendChild(editButton); currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index)); @@ -510,6 +514,28 @@ function runThePopup() { return sponsorTimesContainer; } + + function previewSponsorTime(index) { + let skipTime = sponsorTimes[index][0]; + + if (document.getElementById("startTimeMinutes" + index) != null) { + //edit is currently open, use that time + + skipTime = getSponsorTimeEditTimes("startTime", index); + } + + chrome.tabs.query({ + active: true, + currentWindow: true + }, tabs => { + chrome.tabs.sendMessage( + tabs[0].id, { + message: "skipToTime", + time: skipTime - 2 + } + ); + }); + } function editSponsorTime(index) { if (document.getElementById("startTimeMinutes" + index) != null) { @@ -582,16 +608,19 @@ function runThePopup() { sponsorTimesContainer.replaceChild(saveButton, editButton); } + + //id start name is whether it is the startTime or endTime + //gives back the time in seconds + function getSponsorTimeEditTimes(idStartName, index) { + let minutes = document.getElementById(idStartName + "Minutes" + index); + let seconds = document.getElementById(idStartName + "Seconds" + index); + + return parseInt(minutes.value) * 60 + parseFloat(seconds.value); + } function saveSponsorTimeEdit(index) { - let startTimeMinutes = document.getElementById("startTimeMinutes" + index); - let startTimeSeconds = document.getElementById("startTimeSeconds" + index); - - let endTimeMinutes = document.getElementById("endTimeMinutes" + index); - let endTimeSeconds = document.getElementById("endTimeSeconds" + index); - - sponsorTimes[index][0] = parseInt(startTimeMinutes.value) * 60 + parseFloat(startTimeSeconds.value); - sponsorTimes[index][1] = parseInt(endTimeMinutes.value) * 60 + parseFloat(endTimeSeconds.value); + sponsorTimes[index][0] = getSponsorTimeEditTimes("startTime", index); + sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index); //save this let sponsorTimeKey = "sponsorTimes" + currentVideoID; From ac118173a50d47fa6ad6e69f0024e4cf07b162e3 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 12:26:52 -0400 Subject: [PATCH 32/35] Made preview also save the edit. --- popup.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/popup.js b/popup.js index 3359413e..0c62370e 100644 --- a/popup.js +++ b/popup.js @@ -522,6 +522,9 @@ function runThePopup() { //edit is currently open, use that time skipTime = getSponsorTimeEditTimes("startTime", index); + + //save the edit + saveSponsorTimeEdit(index, false); } chrome.tabs.query({ @@ -618,7 +621,7 @@ function runThePopup() { return parseInt(minutes.value) * 60 + parseFloat(seconds.value); } - function saveSponsorTimeEdit(index) { + function saveSponsorTimeEdit(index, closeEditMode = true) { sponsorTimes[index][0] = getSponsorTimeEditTimes("startTime", index); sponsorTimes[index][1] = getSponsorTimeEditTimes("endTime", index); @@ -636,9 +639,11 @@ function runThePopup() { }); }); - displaySponsorTimes(); + if (closeEditMode) { + displaySponsorTimes(); - showSubmitTimesIfNecessary(); + showSubmitTimesIfNecessary(); + } } //deletes the sponsor time submitted at an index From 6b3eb09198730cb6dbd44296b8da0fca41aa2bca Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 15:27:35 -0400 Subject: [PATCH 33/35] Added button to set edit to the current time. --- content.js | 6 ++++++ popup.css | 6 ++++++ popup.js | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/content.js b/content.js index 1b4db72e..3ee26aeb 100644 --- a/content.js +++ b/content.js @@ -123,6 +123,12 @@ function messageListener(request, sender, sendResponse) { v.currentTime = request.time; } + if (request.message == "getCurrentTime") { + sendResponse({ + currentTime: v.currentTime + }); + } + if (request.message == "getChannelURL") { sendResponse({ channelURL: channelURL diff --git a/popup.css b/popup.css index 49a29ccc..1d5dd91e 100644 --- a/popup.css +++ b/popup.css @@ -86,6 +86,12 @@ h1.popupElement { cursor: pointer; } +.tinyLink.popupElement { + font-size: 10px; + text-decoration: underline; + cursor: pointer; +} + .whitelistButton.popupElement { background-color:#3acc3a; -moz-border-radius:28px; diff --git a/popup.js b/popup.js index 0c62370e..71587889 100644 --- a/popup.js +++ b/popup.js @@ -551,6 +551,13 @@ function runThePopup() { let sponsorTimeContainer = document.getElementById("sponsorTimeContainer" + index); + //the button to set the current time + let startTimeNowButton = document.createElement("span"); + startTimeNowButton.id = "startTimeNowButton" + index; + startTimeNowButton.innerText = "(Now)"; + startTimeNowButton.className = "tinyLink popupElement"; + startTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("startTime", index)); + //get sponsor time minutes and seconds boxes let startTimeMinutes = document.createElement("input"); startTimeMinutes.id = "startTimeMinutes" + index; @@ -565,7 +572,7 @@ function runThePopup() { startTimeSeconds.type = "text"; startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][0]); startTimeSeconds.style.width = "60px"; - + let endTimeMinutes = document.createElement("input"); endTimeMinutes.id = "endTimeMinutes" + index; endTimeMinutes.className = "sponsorTime popupElement"; @@ -579,6 +586,13 @@ function runThePopup() { endTimeSeconds.type = "text"; endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index][1]); endTimeSeconds.style.width = "60px"; + + //the button to set the current time + let endTimeNowButton = document.createElement("span"); + endTimeNowButton.id = "endTimeNowButton" + index; + endTimeNowButton.innerText = "(Now)"; + endTimeNowButton.className = "tinyLink popupElement"; + endTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("endTime", index)); let colonText = document.createElement("span"); colonText.innerText = ":"; @@ -591,6 +605,7 @@ function runThePopup() { sponsorTimeContainer.removeChild(sponsorTimeContainer.firstChild); } + sponsorTimeContainer.appendChild(startTimeNowButton); sponsorTimeContainer.appendChild(startTimeMinutes); sponsorTimeContainer.appendChild(colonText); sponsorTimeContainer.appendChild(startTimeSeconds); @@ -598,6 +613,7 @@ function runThePopup() { sponsorTimeContainer.appendChild(endTimeMinutes); sponsorTimeContainer.appendChild(colonText); sponsorTimeContainer.appendChild(endTimeSeconds); + sponsorTimeContainer.appendChild(endTimeNowButton); //add save button and remove edit button let saveButton = document.createElement("span"); @@ -612,6 +628,24 @@ function runThePopup() { sponsorTimesContainer.replaceChild(saveButton, editButton); } + function setEditTimeToCurrentTime(idStartName, index) { + chrome.tabs.query({ + active: true, + currentWindow: true + }, tabs => { + chrome.tabs.sendMessage( + tabs[0].id, + {message: "getCurrentTime"}, + function (response) { + let minutes = document.getElementById(idStartName + "Minutes" + index); + let seconds = document.getElementById(idStartName + "Seconds" + index); + + minutes.value = getTimeInMinutes(response.currentTime); + seconds.value = getTimeInFormattedSeconds(response.currentTime); + }); + }); + } + //id start name is whether it is the startTime or endTime //gives back the time in seconds function getSponsorTimeEditTimes(idStartName, index) { From 41aa58e004655beb063e9bfd8d41275f1c150988 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 15:58:25 -0400 Subject: [PATCH 34/35] Fixed userIDs not being properly submitted. --- background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background.js b/background.js index a0e0c798..c8d7d593 100644 --- a/background.js +++ b/background.js @@ -141,7 +141,7 @@ function submitVote(type, UUID, callback) { function submitTimes(videoID, callback) { //get the video times from storage let sponsorTimeKey = 'sponsorTimes' + videoID; - chrome.storage.sync.get([sponsorTimeKey], function(result) { + chrome.storage.sync.get([sponsorTimeKey, "userID"], function(result) { let sponsorTimes = result[sponsorTimeKey]; let userID = result.userID; From 640ad58c65dd693b25b4e1fb5343fbf43eaee46c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 12 Aug 2019 15:59:06 -0400 Subject: [PATCH 35/35] Updated version number --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 0b4020bd..23204e4b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "SponsorBlock for YouTube - Skip Sponsorships", "short_name": "SponsorBlock", - "version": "1.0.31", + "version": "1.0.33", "description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.", "content_scripts": [ {