mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-20 14:38:28 +03:00
Merge pull request #179 from ajayyy/experimental-ajay
Added better local stats.
This commit is contained in:
@@ -214,10 +214,10 @@
|
|||||||
"message": "This is the button that allows you to clear all sponsors on the YouTube player."
|
"message": "This is the button that allows you to clear all sponsors on the YouTube player."
|
||||||
},
|
},
|
||||||
"disableViewTracking": {
|
"disableViewTracking": {
|
||||||
"message": "Disable Sponsor View Tracking"
|
"message": "Disable Sponsor Skip Count Tracking"
|
||||||
},
|
},
|
||||||
"enableViewTracking": {
|
"enableViewTracking": {
|
||||||
"message": "Enable Sponsor View Tracking"
|
"message": "Enable Sponsor Skip Count Tracking"
|
||||||
},
|
},
|
||||||
"whatViewTracking": {
|
"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. :)"
|
"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": {
|
"autoSkipDescription": {
|
||||||
"message": "Auto skip will skip sponsors for you. If disabled, a notice will appear asking if you'd like to skip."
|
"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."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
50
content.js
50
content.js
@@ -10,6 +10,9 @@ var sponsorVideoID = null;
|
|||||||
//these are sponsors that have been downvoted
|
//these are sponsors that have been downvoted
|
||||||
var hiddenSponsorTimes = [];
|
var hiddenSponsorTimes = [];
|
||||||
|
|
||||||
|
/** @type {Array[boolean]} Has the sponsor been skipped */
|
||||||
|
var sponsorSkipped = [];
|
||||||
|
|
||||||
//the video
|
//the video
|
||||||
var v;
|
var v;
|
||||||
|
|
||||||
@@ -418,6 +421,9 @@ function sponsorsLookup(id, channelIDPromise) {
|
|||||||
sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
|
sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
|
||||||
UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
|
UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
|
||||||
|
|
||||||
|
// Reset skip save
|
||||||
|
sponsorSkipped = [];
|
||||||
|
|
||||||
//update the preview bar
|
//update the preview bar
|
||||||
//leave the type blank for now until categories are added
|
//leave the type blank for now until categories are added
|
||||||
if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(v.duration))) {
|
if (lastPreviewBarUpdate == id || (lastPreviewBarUpdate == null && !isNaN(v.duration))) {
|
||||||
@@ -639,15 +645,31 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//auto-upvote this sponsor
|
//auto-upvote this sponsor
|
||||||
if (trackViewCount) {
|
if (trackViewCount && !disableAutoSkip) {
|
||||||
vote(1, currentUUID, null);
|
vote(1, currentUUID, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//send telemetry that a this sponsor was skipped happened
|
//send telemetry that a this sponsor was skipped happened
|
||||||
if (trackViewCount) {
|
if (trackViewCount && !sponsorSkipped[index]) {
|
||||||
sendRequestToServer("GET", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
|
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)();
|
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({
|
chrome.runtime.sendMessage({
|
||||||
message: "submitVote",
|
message: "submitVote",
|
||||||
type: type,
|
type: type,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "__MSG_fullName__",
|
"name": "__MSG_fullName__",
|
||||||
"short_name": "__MSG_Name__",
|
"short_name": "__MSG_Name__",
|
||||||
"version": "1.1.9.6",
|
"version": "1.1.9.8",
|
||||||
"default_locale": "en",
|
"default_locale": "en",
|
||||||
"description": "__MSG_Description__",
|
"description": "__MSG_Description__",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|||||||
42
popup.html
42
popup.html
@@ -114,25 +114,49 @@
|
|||||||
<h2 class="recordingSubtitle popupElement">__MSG_yourWork__</h2>
|
<h2 class="recordingSubtitle popupElement">__MSG_yourWork__</h2>
|
||||||
|
|
||||||
<p class="popupElement">
|
<p class="popupElement">
|
||||||
<span id=sponsorTimesContributionsContainer class="popupElement" style="display: none">
|
<span id="sponsorTimesContributionsContainer" class="popupElement" style="display: none">
|
||||||
__MSG_soFarUHSubmited__
|
__MSG_soFarUHSubmited__
|
||||||
<span id="sponsorTimesContributionsDisplay" class="popupElement">
|
<span id="sponsorTimesContributionsDisplay" class="popupElement">
|
||||||
0
|
0
|
||||||
</span>
|
</span>
|
||||||
<span id="sponsorTimesContributionsDisplayEndWord" class="popupElement">
|
<span id="sponsorTimesContributionsDisplayEndWord" class="popupElement">__MSG_Sponsors__</span>.
|
||||||
__MSG_Sponsors__.
|
|
||||||
</span>
|
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span id=sponsorTimesViewsContainer class="popupElement" style="display: none">
|
<span id="sponsorTimesViewsContainer" class="popupElement" style="display: none">
|
||||||
__MSG_savedPeopleFrom__
|
__MSG_savedPeopleFrom__
|
||||||
<span id="sponsorTimesViewsDisplay" class="popupElement">
|
<span id="sponsorTimesViewsDisplay" class="popupElement">
|
||||||
0
|
0
|
||||||
</span>
|
</span>
|
||||||
<span id="sponsorTimesViewsDisplayEndWord" class="popupElement">
|
<span id="sponsorTimesViewsDisplayEndWord" class="popupElement">__MSG_Segments__</span>.
|
||||||
__MSG_Segments__.
|
</span>
|
||||||
__MSG_savedPeopleFrom__
|
|
||||||
</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>
|
</span>
|
||||||
|
|
||||||
<div class="popupElement">
|
<div class="popupElement">
|
||||||
|
|||||||
69
popup.js
69
popup.js
@@ -56,6 +56,18 @@ function runThePopup() {
|
|||||||
"sponsorTimesViewsContainer",
|
"sponsorTimesViewsContainer",
|
||||||
"sponsorTimesViewsDisplay",
|
"sponsorTimesViewsDisplay",
|
||||||
"sponsorTimesViewsDisplayEndWord",
|
"sponsorTimesViewsDisplayEndWord",
|
||||||
|
// sponsorTimesOthersTimeSaved
|
||||||
|
"sponsorTimesOthersTimeSavedContainer",
|
||||||
|
"sponsorTimesOthersTimeSavedDisplay",
|
||||||
|
"sponsorTimesOthersTimeSavedEndWord",
|
||||||
|
// sponsorTimesSkipsDone
|
||||||
|
"sponsorTimesSkipsDoneContainer",
|
||||||
|
"sponsorTimesSkipsDoneDisplay",
|
||||||
|
"sponsorTimesSkipsDoneEndWord",
|
||||||
|
// sponsorTimeSaved
|
||||||
|
"sponsorTimeSavedContainer",
|
||||||
|
"sponsorTimeSavedDisplay",
|
||||||
|
"sponsorTimeSavedEndWord",
|
||||||
// discordButtons
|
// discordButtons
|
||||||
"discordButtonContainer",
|
"discordButtonContainer",
|
||||||
"hideDiscordButton",
|
"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({
|
chrome.tabs.query({
|
||||||
active: true,
|
active: true,
|
||||||
@@ -1377,6 +1434,18 @@ function runThePopup() {
|
|||||||
//submit this request
|
//submit this request
|
||||||
xmlhttp.send();
|
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
|
//end of function
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,6 +292,8 @@ class SkipNotice {
|
|||||||
// See if the title should be changed
|
// See if the title should be changed
|
||||||
if (this.manualSkip) {
|
if (this.manualSkip) {
|
||||||
this.changeNoticeTitle(chrome.i18n.getMessage("noticeTitle"));
|
this.changeNoticeTitle(chrome.i18n.getMessage("noticeTitle"));
|
||||||
|
|
||||||
|
vote(1, this.UUID, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user