mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Fixed some non converted sponsorTimes code
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
|
||||||
import { SponsorTime, CategorySkipOption, CategorySelection } from "./types";
|
import { SponsorTime, CategorySkipOption, CategorySelection, VideoID } from "./types";
|
||||||
|
|
||||||
import { ContentContainer } from "./types";
|
import { ContentContainer } from "./types";
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
@@ -18,11 +18,11 @@ utils.wait(() => Config.config !== null, 5000, 10).then(addCSS);
|
|||||||
|
|
||||||
//was sponsor data found when doing SponsorsLookup
|
//was sponsor data found when doing SponsorsLookup
|
||||||
var sponsorDataFound = false;
|
var sponsorDataFound = false;
|
||||||
var previousVideoID = null;
|
var previousVideoID: VideoID = null;
|
||||||
//the actual sponsorTimes if loaded and UUIDs associated with them
|
//the actual sponsorTimes if loaded and UUIDs associated with them
|
||||||
var sponsorTimes: SponsorTime[] = null;
|
var sponsorTimes: SponsorTime[] = null;
|
||||||
//what video id are these sponsors for
|
//what video id are these sponsors for
|
||||||
var sponsorVideoID = null;
|
var sponsorVideoID: VideoID = null;
|
||||||
|
|
||||||
// Skips are scheduled to ensure precision.
|
// Skips are scheduled to ensure precision.
|
||||||
// Skips are rescheduled every seeking event.
|
// Skips are rescheduled every seeking event.
|
||||||
@@ -637,15 +637,15 @@ function sponsorsLookup(id: string, channelIDPromise?) {
|
|||||||
// See if there are any starting sponsors
|
// See if there are any starting sponsors
|
||||||
let startingSponsor: number = -1;
|
let startingSponsor: number = -1;
|
||||||
for (const time of sponsorTimes) {
|
for (const time of sponsorTimes) {
|
||||||
if (time[0] <= video.currentTime && time[0] > startingSponsor && time[1] > video.currentTime) {
|
if (time[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) {
|
||||||
startingSponsor = time[0];
|
startingSponsor = time.segment[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!startingSponsor) {
|
if (!startingSponsor) {
|
||||||
for (const time of sponsorTimesSubmitting) {
|
for (const time of sponsorTimesSubmitting) {
|
||||||
if (time[0] <= video.currentTime && time[0] > startingSponsor && time[1] > video.currentTime) {
|
if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) {
|
||||||
startingSponsor = time[0];
|
startingSponsor = time.segment[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1324,7 +1324,7 @@ function vote(type, UUID, skipNotice?: SkipNoticeComponent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count this as a skip
|
// Count this as a skip
|
||||||
Config.config.minutesSaved = Config.config.minutesSaved + factor * (sponsorTimes[sponsorIndex][1] - sponsorTimes[sponsorIndex][0]) / 60;
|
Config.config.minutesSaved = Config.config.minutesSaved + factor * (sponsorTimes[sponsorIndex].segment[1] - sponsorTimes[sponsorIndex].segment[0]) / 60;
|
||||||
|
|
||||||
Config.config.skipCount = Config.config.skipCount + factor;
|
Config.config.skipCount = Config.config.skipCount + factor;
|
||||||
}
|
}
|
||||||
@@ -1396,28 +1396,6 @@ function submitSponsorTimes() {
|
|||||||
let currentVideoID = sponsorVideoID;
|
let currentVideoID = sponsorVideoID;
|
||||||
|
|
||||||
if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) {
|
if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) {
|
||||||
//check if a sponsor exceeds the duration of the video
|
|
||||||
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
|
||||||
if (sponsorTimesSubmitting[i].segment[1] > video.duration) {
|
|
||||||
sponsorTimesSubmitting[i].segment[1] = video.duration;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//update sponsorTimes
|
|
||||||
Config.config.sponsorTimes.set(currentVideoID, utils.getSegmentsFromSponsorTimes(sponsorTimesSubmitting));
|
|
||||||
|
|
||||||
// Check to see if any of the submissions are below the minimum duration set
|
|
||||||
if (Config.config.minDuration > 0) {
|
|
||||||
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
|
||||||
if (sponsorTimesSubmitting[i].segment[1] - sponsorTimesSubmitting[i].segment[0] < Config.config.minDuration) {
|
|
||||||
let confirmShort = chrome.i18n.getMessage("shortCheck") + "\n\n" +
|
|
||||||
getSegmentsMessage(utils.getSegmentsFromSponsorTimes(sponsorTimesSubmitting));
|
|
||||||
|
|
||||||
if(!confirm(confirmShort)) return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage);
|
submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1430,11 +1408,31 @@ function sendSubmitMessage(){
|
|||||||
(<HTMLImageElement> document.getElementById("submitImage")).src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
(<HTMLImageElement> document.getElementById("submitImage")).src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
|
||||||
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
|
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
|
||||||
|
|
||||||
let currentVideoID = sponsorVideoID;
|
//check if a sponsor exceeds the duration of the video
|
||||||
|
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
||||||
|
if (sponsorTimesSubmitting[i].segment[1] > video.duration) {
|
||||||
|
sponsorTimesSubmitting[i].segment[1] = video.duration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update sponsorTimes
|
||||||
|
Config.config.sponsorTimes.set(sponsorVideoID, utils.getSegmentsFromSponsorTimes(sponsorTimesSubmitting));
|
||||||
|
|
||||||
|
// Check to see if any of the submissions are below the minimum duration set
|
||||||
|
if (Config.config.minDuration > 0) {
|
||||||
|
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
||||||
|
if (sponsorTimesSubmitting[i].segment[1] - sponsorTimesSubmitting[i].segment[0] < Config.config.minDuration) {
|
||||||
|
let confirmShort = chrome.i18n.getMessage("shortCheck") + "\n\n" +
|
||||||
|
getSegmentsMessage(utils.getSegmentsFromSponsorTimes(sponsorTimesSubmitting));
|
||||||
|
|
||||||
|
if(!confirm(confirmShort)) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
message: "submitTimes",
|
message: "submitTimes",
|
||||||
videoID: currentVideoID
|
videoID: sponsorVideoID
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
if (response != undefined) {
|
if (response != undefined) {
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
@@ -1454,7 +1452,7 @@ function sendSubmitMessage(){
|
|||||||
submitButton.addEventListener("animationend", animationEndListener);
|
submitButton.addEventListener("animationend", animationEndListener);
|
||||||
|
|
||||||
//clear the sponsor times
|
//clear the sponsor times
|
||||||
Config.config.sponsorTimes.delete(currentVideoID);
|
Config.config.sponsorTimes.delete(sponsorVideoID);
|
||||||
|
|
||||||
//add submissions to current sponsors list
|
//add submissions to current sponsors list
|
||||||
if (sponsorTimes === null) sponsorTimes = [];
|
if (sponsorTimes === null) sponsorTimes = [];
|
||||||
|
|||||||
@@ -43,10 +43,13 @@ interface SponsorTime {
|
|||||||
category: string;
|
category: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VideoID = string;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
VideoDurationResponse,
|
VideoDurationResponse,
|
||||||
ContentContainer,
|
ContentContainer,
|
||||||
CategorySelection,
|
CategorySelection,
|
||||||
CategorySkipOption,
|
CategorySkipOption,
|
||||||
SponsorTime
|
SponsorTime,
|
||||||
|
VideoID
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user