From ab07478e25e5e707e6dd24d5c0552bd21ee5cecd Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 3 Dec 2019 17:01:34 -0500 Subject: [PATCH 1/4] Updated build number --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 6b8182e169..554b520afe 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "__MSG_Name__", - "version": "1.1.9.6", + "version": "1.1.9.7", "default_locale": "en", "description": "__MSG_Description__", "content_scripts": [ From b18f2ae60de818ca53225d75efd26ac93bf2afaf Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 4 Dec 2019 23:38:07 -0500 Subject: [PATCH 2/4] Made it show how much time you have saved yourself. --- _locales/en/messages.json | 22 +++++++++++++++-- content.js | 50 +++++++++++++++++++++++++++++++++++++-- popup.html | 32 ++++++++++++++++++------- popup.js | 36 ++++++++++++++++++++++++++++ utils/skipNotice.js | 2 ++ 5 files changed, 129 insertions(+), 13 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 72cf1bec4f..ed277dc846 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -214,10 +214,10 @@ "message": "This is the button that allows you to clear all sponsors on the YouTube player." }, "disableViewTracking": { - "message": "Disable Sponsor View Tracking" + "message": "Disable Sponsor Skip Count Tracking" }, "enableViewTracking": { - "message": "Enable Sponsor View Tracking" + "message": "Enable Sponsor Skip Count Tracking" }, "whatViewTracking": { "message": "This feature tracks which sponsors you have skipped to let users know how much their submission has helped others and\nused as a metric along with upvotes to ensure that spam doesn't get into the database. The extension sends a message\nto the server each time you skip a sponsor. Hopefully most people don't change this setting so that the view numbers are accurate. :)" @@ -290,5 +290,23 @@ }, "autoSkipDescription": { "message": "Auto skip will skip sponsors for you. If disabled, a notice will appear asking if you'd like to skip." + }, + "youHaveSkipped": { + "message": "You have skipped " + }, + "youHaveSaved": { + "message": "You have saved yourself " + }, + "minLower": { + "message": "minute" + }, + "minsLower": { + "message": "minutes" + }, + "hourLower": { + "message": "hour" + }, + "hoursLower": { + "message": "hours" } } diff --git a/content.js b/content.js index 5c90a96467..228172de88 100644 --- a/content.js +++ b/content.js @@ -10,6 +10,9 @@ var sponsorVideoID = null; //these are sponsors that have been downvoted var hiddenSponsorTimes = []; +/** @type {Array[boolean]} Has the sponsor been skipped */ +var sponsorSkipped = []; + //the video var v; @@ -418,6 +421,9 @@ function sponsorsLookup(id, channelIDPromise) { sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes; UUIDs = JSON.parse(xmlhttp.responseText).UUIDs; + // Reset skip save + sponsorSkipped = []; + //update the preview bar //leave the type blank for now until categories are added if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(v.duration))) { @@ -639,15 +645,31 @@ function skipToTime(v, index, sponsorTimes, openNotice) { } //auto-upvote this sponsor - if (trackViewCount) { + if (trackViewCount && !disableAutoSkip) { vote(1, currentUUID, null); } } } //send telemetry that a this sponsor was skipped happened - if (trackViewCount) { + if (trackViewCount && !sponsorSkipped[index]) { sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID); + + if (!disableAutoSkip) { + // Count this as a skip + chrome.storage.sync.get(["minutesSaved"], function(result) { + if (result.minutesSaved === undefined) result.minutesSaved = 0; + + chrome.storage.sync.set({"minutesSaved": result.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60 }); + }); + chrome.storage.sync.get(["skipCount"], function(result) { + if (result.skipCount === undefined) result.skipCount = 0; + + chrome.storage.sync.set({"skipCount": result.skipCount + 1 }); + }); + + sponsorSkipped[index] = true; + } } } @@ -916,6 +938,30 @@ function vote(type, UUID, skipNotice) { skipNotice.resetNoticeInfoMessage.bind(skipNotice)(); } + let sponsorIndex = UUIDs.indexOf(UUID); + + // See if the local time saved count and skip count should be reverted + if (type == 0 && sponsorSkipped[sponsorIndex] || type == 1 && !sponsorSkipped[sponsorIndex]) { + let factor = 1; + if (type == 0) { + factor = -1; + } + + // Count this as a skip + chrome.storage.sync.get(["minutesSaved"], function(result) { + if (result.minutesSaved === undefined) result.minutesSaved = 0; + + chrome.storage.sync.set({"minutesSaved": result.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60 }); + }); + chrome.storage.sync.get(["skipCount"], function(result) { + if (result.skipCount === undefined) result.skipCount = 0; + + chrome.storage.sync.set({"skipCount": result.skipCount + factor * 1 }); + }); + + sponsorSkipped[sponsorIndex] = !sponsorSkipped[sponsorIndex]; + } + chrome.runtime.sendMessage({ message: "submitVote", type: type, diff --git a/popup.html b/popup.html index c09000f0c1..e673eecbe5 100644 --- a/popup.html +++ b/popup.html @@ -114,25 +114,39 @@

__MSG_voteOnTime__

__MSG_yourWork__

-

diff --git a/popup.js b/popup.js index eea0c7c071..476a09cb00 100644 --- a/popup.js +++ b/popup.js @@ -56,6 +56,14 @@ function runThePopup() { "sponsorTimesViewsContainer", "sponsorTimesViewsDisplay", "sponsorTimesViewsDisplayEndWord", + // sponsorTimesSkipsDone + "sponsorTimesSkipsDoneContainer", + "sponsorTimesSkipsDoneDisplay", + "sponsorTimesSkipsDoneEndWord", + // sponsorTimeSaved + "sponsorTimeSavedContainer", + "sponsorTimeSavedDisplay", + "sponsorTimeSavedEndWord", // discordButtons "discordButtonContainer", "hideDiscordButton", @@ -240,6 +248,34 @@ function runThePopup() { }); } }); + + //get the amount of times this user has skipped a sponsor + chrome.storage.sync.get(["skipCount"], function(result) { + if (result.skipCount != undefined) { + if (result.skipCount != 1) { + SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsors"); + } else { + SB.sponsorTimesSkipsDoneEndWord.innerText = chrome.i18n.getMessage("Sponsor"); + } + + SB.sponsorTimesSkipsDoneDisplay.innerText = result.skipCount; + SB.sponsorTimesSkipsDoneContainer.style.display = "unset"; + } + }); + + //get the amount of time this user has saved. + chrome.storage.sync.get(["minutesSaved"], function(result) { + if (result.minutesSaved != undefined) { + if (result.minutesSaved != 1) { + SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower"); + } else { + SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); + } + + SB.sponsorTimeSavedDisplay.innerText = result.minutesSaved.toFixed(2); + SB.sponsorTimeSavedContainer.style.display = "unset"; + } + }); chrome.tabs.query({ active: true, diff --git a/utils/skipNotice.js b/utils/skipNotice.js index 1819aea837..c69e62d2e2 100644 --- a/utils/skipNotice.js +++ b/utils/skipNotice.js @@ -292,6 +292,8 @@ class SkipNotice { // See if the title should be changed if (this.manualSkip) { this.changeNoticeTitle(chrome.i18n.getMessage("noticeTitle")); + + vote(1, this.UUID, this); } } From 3a29fcc3d8cfdd90135bbb26c15adff7c12f8fe6 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 4 Dec 2019 23:51:20 -0500 Subject: [PATCH 3/4] Added time the user saved others from plus better time formatting. --- _locales/en/messages.json | 6 ++++++ popup.html | 10 ++++++++++ popup.js | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index ed277dc846..f34542a78f 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -308,5 +308,11 @@ }, "hoursLower": { "message": "hours" + }, + "youHaveSavedTime": { + "message": "You have saved people" + }, + "youHaveSavedTimeEnd": { + "message": " of their lives." } } diff --git a/popup.html b/popup.html index e673eecbe5..3e96de4db6 100644 --- a/popup.html +++ b/popup.html @@ -130,6 +130,16 @@

__MSG_yourWork__

__MSG_Segments__. + +

diff --git a/popup.js b/popup.js index 476a09cb00..d51fac4bae 100644 --- a/popup.js +++ b/popup.js @@ -56,6 +56,10 @@ function runThePopup() { "sponsorTimesViewsContainer", "sponsorTimesViewsDisplay", "sponsorTimesViewsDisplayEndWord", + // sponsorTimesOthersTimeSaved + "sponsorTimesOthersTimeSavedContainer", + "sponsorTimesOthersTimeSavedDisplay", + "sponsorTimesOthersTimeSavedEndWord", // sponsorTimesSkipsDone "sponsorTimesSkipsDoneContainer", "sponsorTimesSkipsDoneDisplay", @@ -244,6 +248,23 @@ function runThePopup() { } } }); + + //get this time in minutes + sendRequestToServer("GET", "/api/getSavedTimeForUser?userID=" + userID, function(xmlhttp) { + if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { + let minutesSaved = JSON.parse(xmlhttp.responseText).timeSaved; + if (minutesSaved != 0) { + if (minutesSaved != 1) { + SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minsLower"); + } else { + SB.sponsorTimesOthersTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); + } + + SB.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved); + SB.sponsorTimesOthersTimeSavedContainer.style.display = "unset"; + } + } + }); } }); } @@ -272,7 +293,7 @@ function runThePopup() { SB.sponsorTimeSavedEndWord.innerText = chrome.i18n.getMessage("minLower"); } - SB.sponsorTimeSavedDisplay.innerText = result.minutesSaved.toFixed(2); + SB.sponsorTimeSavedDisplay.innerText = getFormattedHours(result.minutesSaved); SB.sponsorTimeSavedContainer.style.display = "unset"; } }); @@ -1413,6 +1434,18 @@ function runThePopup() { //submit this request xmlhttp.send(); } + + /** + * Converts time in hours to 5h 25.1 + * If less than 1 hour, just returns minutes + * + * @param {float} seconds + * @returns {string} + */ + function getFormattedHours(minues) { + let hours = Math.floor(minues / 60); + return (hours > 0 ? hours + "h " : "") + (minues % 60).toFixed(1); + } //end of function } From 9c51df915933bf4a024e23a914ef06897522e2c7 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 4 Dec 2019 23:51:47 -0500 Subject: [PATCH 4/4] Increased version number. --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 554b520afe..e186cd0f20 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "__MSG_Name__", - "version": "1.1.9.7", + "version": "1.1.9.8", "default_locale": "en", "description": "__MSG_Description__", "content_scripts": [