aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-12-04 23:53:26 -0500
committerGitHub <[email protected]>2019-12-04 23:53:26 -0500
commit3d01ffee1b9b02097870aad8c3cd2226607c2ef2 (patch)
treef2a35c97dcd23c7db8dabb4d7c62849a68d5ef54
parentd6aeec933ab2ddd987bb24e5b3dfaa919b4b177d (diff)
parent9c51df915933bf4a024e23a914ef06897522e2c7 (diff)
downloadSponsorBlock-3d01ffee1b9b02097870aad8c3cd2226607c2ef2.tar.gz
SponsorBlock-3d01ffee1b9b02097870aad8c3cd2226607c2ef2.zip
Merge pull request #179 from ajayyy/experimental-ajay11.9.8
Added better local stats.
-rw-r--r--_locales/en/messages.json28
-rw-r--r--content.js50
-rw-r--r--manifest.json2
-rw-r--r--popup.html42
-rw-r--r--popup.js69
-rw-r--r--utils/skipNotice.js2
6 files changed, 179 insertions, 14 deletions
diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 72cf1bec..f34542a7 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,29 @@
},
"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"
+ },
+ "youHaveSavedTime": {
+ "message": "You have saved people"
+ },
+ "youHaveSavedTimeEnd": {
+ "message": " of their lives."
}
}
diff --git a/content.js b/content.js
index 5c90a964..228172de 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/manifest.json b/manifest.json
index 6b8182e1..e186cd0f 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.8",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [
diff --git a/popup.html b/popup.html
index c09000f0..3e96de4d 100644
--- a/popup.html
+++ b/popup.html
@@ -114,25 +114,49 @@
<h2 class="recordingSubtitle popupElement">__MSG_yourWork__</h2>
<p class="popupElement">
- <span id=sponsorTimesContributionsContainer class="popupElement" style="display: none">
+ <span id="sponsorTimesContributionsContainer" class="popupElement" style="display: none">
__MSG_soFarUHSubmited__
<span id="sponsorTimesContributionsDisplay" class="popupElement">
0
</span>
- <span id="sponsorTimesContributionsDisplayEndWord" class="popupElement">
- __MSG_Sponsors__.
- </span>
+ <span id="sponsorTimesContributionsDisplayEndWord" class="popupElement">__MSG_Sponsors__</span>.
</span>
- <span id=sponsorTimesViewsContainer class="popupElement" style="display: none">
+ <span id="sponsorTimesViewsContainer" class="popupElement" style="display: none">
__MSG_savedPeopleFrom__
<span id="sponsorTimesViewsDisplay" class="popupElement">
0
</span>
- <span id="sponsorTimesViewsDisplayEndWord" class="popupElement">
- __MSG_Segments__.
- __MSG_savedPeopleFrom__
- </span>
+ <span id="sponsorTimesViewsDisplayEndWord" class="popupElement">__MSG_Segments__</span>.
+ </span>
+
+ <span id="sponsorTimesOthersTimeSavedContainer" class="popupElement" style="display: none">
+ __MSG_youHaveSavedTime__
+ <span id="sponsorTimesOthersTimeSavedDisplay" class="popupElement">
+ 0
+ </span>
+ <span id="sponsorTimesOthersTimeSavedEndWord" class="popupElement">__MSG_minsLower__</span>
+
+ <span class="popupElement">__MSG_youHaveSavedTimeEnd__</span>
+ </span>
+
+ <br/>
+ <br/>
+
+ <span id="sponsorTimesSkipsDoneContainer" class="popupElement" style="display: none">
+ __MSG_youHaveSkipped__
+ <span id="sponsorTimesSkipsDoneDisplay" class="popupElement">
+ 0
+ </span>
+ <span id="sponsorTimesSkipsDoneEndWord" class="popupElement">__MSG_Segments__</span> since December 5th.
+ </span>
+
+ <span id="sponsorTimeSavedContainer" class="popupElement" style="display: none">
+ __MSG_youHaveSaved__
+ <span id="sponsorTimeSavedDisplay" class="popupElement">
+ 0
+ </span>
+ <span id="sponsorTimeSavedEndWord" class="popupElement">__MSG_minsLower__</span> since December 5th.
</span>
<div class="popupElement">
diff --git a/popup.js b/popup.js
index eea0c7c0..d51fac4b 100644
--- a/popup.js
+++ b/popup.js
@@ -56,6 +56,18 @@ function runThePopup() {
"sponsorTimesViewsContainer",
"sponsorTimesViewsDisplay",
"sponsorTimesViewsDisplayEndWord",
+ // sponsorTimesOthersTimeSaved
+ "sponsorTimesOthersTimeSavedContainer",
+ "sponsorTimesOthersTimeSavedDisplay",
+ "sponsorTimesOthersTimeSavedEndWord",
+ // sponsorTimesSkipsDone
+ "sponsorTimesSkipsDoneContainer",
+ "sponsorTimesSkipsDoneDisplay",
+ "sponsorTimesSkipsDoneEndWord",
+ // sponsorTimeSaved
+ "sponsorTimeSavedContainer",
+ "sponsorTimeSavedDisplay",
+ "sponsorTimeSavedEndWord",
// discordButtons
"discordButtonContainer",
"hideDiscordButton",
@@ -236,10 +248,55 @@ 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";
+ }
+ }
+ });
}
});
}
});
+
+ //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 = getFormattedHours(result.minutesSaved);
+ SB.sponsorTimeSavedContainer.style.display = "unset";
+ }
+ });
chrome.tabs.query({
active: true,
@@ -1377,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
}
diff --git a/utils/skipNotice.js b/utils/skipNotice.js
index 1819aea8..c69e62d2 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);
}
}