mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 04:57:09 +03:00
Switched skipping to use category settings.
Submission editing is now broken as well as clicking submit. Skipping through multiple submissions just treats it as skipping from one (no multiple vote options).
This commit is contained in:
@@ -7,7 +7,7 @@ import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
|||||||
|
|
||||||
export interface SkipNoticeProps {
|
export interface SkipNoticeProps {
|
||||||
UUID: string;
|
UUID: string;
|
||||||
manualSkip: boolean;
|
autoSkip: boolean;
|
||||||
// Contains functions and variables from the content script needed by the skip notice
|
// Contains functions and variables from the content script needed by the skip notice
|
||||||
contentContainer: ContentContainer;
|
contentContainer: ContentContainer;
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ export interface SkipNoticeState {
|
|||||||
|
|
||||||
class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeState> {
|
class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeState> {
|
||||||
UUID: string;
|
UUID: string;
|
||||||
manualSkip: boolean;
|
autoSkip: boolean;
|
||||||
// Contains functions and variables from the content script needed by the skip notice
|
// Contains functions and variables from the content script needed by the skip notice
|
||||||
contentContainer: ContentContainer;
|
contentContainer: ContentContainer;
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
this.noticeRef = React.createRef();
|
this.noticeRef = React.createRef();
|
||||||
|
|
||||||
this.UUID = props.UUID;
|
this.UUID = props.UUID;
|
||||||
this.manualSkip = props.manualSkip;
|
this.autoSkip = props.autoSkip;
|
||||||
this.contentContainer = props.contentContainer;
|
this.contentContainer = props.contentContainer;
|
||||||
|
|
||||||
let noticeTitle = chrome.i18n.getMessage("noticeTitle");
|
let noticeTitle = chrome.i18n.getMessage("noticeTitle");
|
||||||
|
|
||||||
if (this.manualSkip) {
|
if (!this.autoSkip) {
|
||||||
noticeTitle = chrome.i18n.getMessage("noticeTitleNotSkipped");
|
noticeTitle = chrome.i18n.getMessage("noticeTitleNotSkipped");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
{/* Never show button if manualSkip is disabled */}
|
{/* Never show button if manualSkip is disabled */}
|
||||||
{this.manualSkip ? "" :
|
{!this.autoSkip ? "" :
|
||||||
<td className="sponsorSkipNoticeRightSection">
|
<td className="sponsorSkipNoticeRightSection">
|
||||||
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
|
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
|
||||||
onClick={this.contentContainer().dontShowNoticeAgain}>
|
onClick={this.contentContainer().dontShowNoticeAgain}>
|
||||||
@@ -223,7 +223,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
});
|
});
|
||||||
|
|
||||||
// See if the title should be changed
|
// See if the title should be changed
|
||||||
if (this.manualSkip) {
|
if (!this.autoSkip) {
|
||||||
this.setState({
|
this.setState({
|
||||||
noticeTitle: chrome.i18n.getMessage("noticeTitle")
|
noticeTitle: chrome.i18n.getMessage("noticeTitle")
|
||||||
});
|
});
|
||||||
@@ -239,7 +239,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
//remove this sponsor from the sponsors looked up
|
//remove this sponsor from the sponsors looked up
|
||||||
//find which one it is
|
//find which one it is
|
||||||
for (let i = 0; i < this.contentContainer().sponsorTimes.length; i++) {
|
for (let i = 0; i < this.contentContainer().sponsorTimes.length; i++) {
|
||||||
if (this.contentContainer().UUIDs[i] == this.UUID) {
|
if (this.contentContainer().sponsorTimes[i].UUID == this.UUID) {
|
||||||
//this one is the one to hide
|
//this one is the one to hide
|
||||||
|
|
||||||
//add this as a hidden sponsorTime
|
//add this as a hidden sponsorTime
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import Config from "../config";
|
|||||||
import * as CompileConfig from "../../config.json";
|
import * as CompileConfig from "../../config.json";
|
||||||
|
|
||||||
import Utils from "../utils";
|
import Utils from "../utils";
|
||||||
import { ContentContainer } from "../types";
|
import { ContentContainer, SponsorTime } from "../types";
|
||||||
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
|
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
|
||||||
var utils = new Utils();
|
var utils = new Utils();
|
||||||
|
|
||||||
@@ -225,16 +225,17 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an array in the sponsorTimeEdits form (minutes and seconds) from a normal seconds sponsor time */
|
/** Returns an array in the sponsorTimeEdits form (minutes and seconds) from a normal seconds sponsor time */
|
||||||
getFormattedSponsorTimesEdits(sponsorTime: number[]): string[][] {
|
getFormattedSponsorTimesEdits(sponsorTime: SponsorTime): string[][] {
|
||||||
return [[String(utils.getFormattedMinutes(sponsorTime[0])), String(utils.getFormattedSeconds(sponsorTime[0]))],
|
return [[String(utils.getFormattedMinutes(sponsorTime.segment[0])), String(utils.getFormattedSeconds(sponsorTime.segment[0]))],
|
||||||
[String(utils.getFormattedMinutes(sponsorTime[1])), String(utils.getFormattedSeconds(sponsorTime[1]))]];
|
[String(utils.getFormattedMinutes(sponsorTime.segment[1])), String(utils.getFormattedSeconds(sponsorTime.segment[1]))]];
|
||||||
}
|
}
|
||||||
|
|
||||||
saveEditTimes() {
|
saveEditTimes() {
|
||||||
|
//TODO: Properly save categories and times
|
||||||
// Save sponsorTimes
|
// Save sponsorTimes
|
||||||
this.props.contentContainer().sponsorTimesSubmitting[this.props.index] =
|
// this.props.contentContainer().sponsorTimesSubmitting[this.props.index] =
|
||||||
[utils.getRawSeconds(parseFloat(this.state.sponsorTimeEdits[0][0]), parseFloat(this.state.sponsorTimeEdits[0][1])),
|
// [utils.getRawSeconds(parseFloat(this.state.sponsorTimeEdits[0][0]), parseFloat(this.state.sponsorTimeEdits[0][1])),
|
||||||
utils.getRawSeconds(parseFloat(this.state.sponsorTimeEdits[1][0]), parseFloat(this.state.sponsorTimeEdits[1][1]))];
|
// utils.getRawSeconds(parseFloat(this.state.sponsorTimeEdits[1][0]), parseFloat(this.state.sponsorTimeEdits[1][1]))];
|
||||||
|
|
||||||
Config.config.sponsorTimes.set(this.props.contentContainer().sponsorVideoID, this.props.contentContainer().sponsorTimesSubmitting);
|
Config.config.sponsorTimes.set(this.props.contentContainer().sponsorVideoID, this.props.contentContainer().sponsorTimesSubmitting);
|
||||||
|
|
||||||
@@ -260,7 +261,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
|||||||
let index = this.props.index;
|
let index = this.props.index;
|
||||||
|
|
||||||
//if it is not a complete sponsor time
|
//if it is not a complete sponsor time
|
||||||
if (sponsorTimes[index].length < 2) {
|
if (sponsorTimes[index].segment.length < 2) {
|
||||||
//update video player
|
//update video player
|
||||||
this.props.contentContainer().changeStartSponsorButton(true, false);
|
this.props.contentContainer().changeStartSponsorButton(true, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ interface SBConfig {
|
|||||||
skipCount: number,
|
skipCount: number,
|
||||||
sponsorTimesContributed: number,
|
sponsorTimesContributed: number,
|
||||||
disableSkipping: boolean,
|
disableSkipping: boolean,
|
||||||
disableAutoSkip: boolean,
|
|
||||||
trackViewCount: boolean,
|
trackViewCount: boolean,
|
||||||
dontShowNotice: boolean,
|
dontShowNotice: boolean,
|
||||||
hideVideoPlayerControls: boolean,
|
hideVideoPlayerControls: boolean,
|
||||||
@@ -109,7 +108,6 @@ var Config: SBObject = {
|
|||||||
skipCount: 0,
|
skipCount: 0,
|
||||||
sponsorTimesContributed: 0,
|
sponsorTimesContributed: 0,
|
||||||
disableSkipping: false,
|
disableSkipping: false,
|
||||||
disableAutoSkip: false,
|
|
||||||
trackViewCount: true,
|
trackViewCount: true,
|
||||||
dontShowNotice: false,
|
dontShowNotice: false,
|
||||||
hideVideoPlayerControls: false,
|
hideVideoPlayerControls: false,
|
||||||
|
|||||||
273
src/content.ts
273
src/content.ts
@@ -1,10 +1,11 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
|
||||||
|
import { SponsorTime, CategorySkipOption, CategorySelection } from "./types";
|
||||||
|
|
||||||
import { ContentContainer } from "./types";
|
import { ContentContainer } from "./types";
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
var utils = new Utils();
|
var utils = new Utils();
|
||||||
|
|
||||||
|
|
||||||
import runThePopup from "./popup";
|
import runThePopup from "./popup";
|
||||||
|
|
||||||
import PreviewBar from "./js-components/previewBar";
|
import PreviewBar from "./js-components/previewBar";
|
||||||
@@ -19,8 +20,7 @@ utils.wait(() => Config.config !== null, 5000, 10).then(addCSS);
|
|||||||
var sponsorDataFound = false;
|
var sponsorDataFound = false;
|
||||||
var previousVideoID = null;
|
var previousVideoID = null;
|
||||||
//the actual sponsorTimes if loaded and UUIDs associated with them
|
//the actual sponsorTimes if loaded and UUIDs associated with them
|
||||||
var sponsorTimes: number[][] = null;
|
var sponsorTimes: SponsorTime[] = null;
|
||||||
var UUIDs = [];
|
|
||||||
//what video id are these sponsors for
|
//what video id are these sponsors for
|
||||||
var sponsorVideoID = null;
|
var sponsorVideoID = null;
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ var currentSkipSchedule: NodeJS.Timeout = null;
|
|||||||
var seekListenerSetUp = false
|
var seekListenerSetUp = false
|
||||||
|
|
||||||
//these are sponsors that have been downvoted
|
//these are sponsors that have been downvoted
|
||||||
var hiddenSponsorTimes = [];
|
var hiddenSponsorTimes: number[] = [];
|
||||||
|
|
||||||
/** @type {Array[boolean]} Has the sponsor been skipped */
|
/** @type {Array[boolean]} Has the sponsor been skipped */
|
||||||
var sponsorSkipped = [];
|
var sponsorSkipped = [];
|
||||||
@@ -87,15 +87,15 @@ var sponsorLookupRetries = 0;
|
|||||||
|
|
||||||
//the last time in the video a sponsor was skipped
|
//the last time in the video a sponsor was skipped
|
||||||
//used for the go back button
|
//used for the go back button
|
||||||
var lastSponsorTimeSkipped = null;
|
var lastSponsorTimeSkipped: number = null;
|
||||||
//used for ratings
|
//used for ratings
|
||||||
var lastSponsorTimeSkippedUUID = null;
|
var lastSponsorTimeSkippedUUID: string = null;
|
||||||
|
|
||||||
//if showing the start sponsor button or the end sponsor button on the player
|
//if showing the start sponsor button or the end sponsor button on the player
|
||||||
var showingStartSponsor = true;
|
var showingStartSponsor = true;
|
||||||
|
|
||||||
//the sponsor times being prepared to be submitted
|
//the sponsor times being prepared to be submitted
|
||||||
var sponsorTimesSubmitting = [];
|
var sponsorTimesSubmitting: SponsorTime[] = [];
|
||||||
|
|
||||||
//becomes true when isInfoFound is called
|
//becomes true when isInfoFound is called
|
||||||
//this is used to close the popup on YouTube when the other popup opens
|
//this is used to close the popup on YouTube when the other popup opens
|
||||||
@@ -111,7 +111,6 @@ var skipNoticeContentContainer: ContentContainer = () => ({
|
|||||||
sponsorTimes,
|
sponsorTimes,
|
||||||
sponsorTimesSubmitting,
|
sponsorTimesSubmitting,
|
||||||
hiddenSponsorTimes,
|
hiddenSponsorTimes,
|
||||||
UUIDs,
|
|
||||||
v: video,
|
v: video,
|
||||||
sponsorVideoID,
|
sponsorVideoID,
|
||||||
reskipSponsorTime,
|
reskipSponsorTime,
|
||||||
@@ -145,8 +144,7 @@ function messageListener(request: any, sender: any, sendResponse: (response: any
|
|||||||
sendResponse({
|
sendResponse({
|
||||||
found: sponsorDataFound,
|
found: sponsorDataFound,
|
||||||
sponsorTimes: sponsorTimes,
|
sponsorTimes: sponsorTimes,
|
||||||
hiddenSponsorTimes: hiddenSponsorTimes,
|
hiddenSponsorTimes: hiddenSponsorTimes
|
||||||
UUIDs: UUIDs
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
|
if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
|
||||||
@@ -267,7 +265,6 @@ function resetValues() {
|
|||||||
|
|
||||||
//reset sponsor times
|
//reset sponsor times
|
||||||
sponsorTimes = null;
|
sponsorTimes = null;
|
||||||
UUIDs = [];
|
|
||||||
sponsorLookupRetries = 0;
|
sponsorLookupRetries = 0;
|
||||||
|
|
||||||
//empty the preview bar
|
//empty the preview bar
|
||||||
@@ -357,37 +354,22 @@ async function videoIDChange(id) {
|
|||||||
sponsorsLookup(id, channelIDPromise);
|
sponsorsLookup(id, channelIDPromise);
|
||||||
|
|
||||||
//make sure everything is properly added
|
//make sure everything is properly added
|
||||||
updateVisibilityOfPlayerControlsButton();
|
updateVisibilityOfPlayerControlsButton().then(() => {
|
||||||
|
//see if the onvideo control image needs to be changed
|
||||||
|
let segments = Config.config.sponsorTimes.get(sponsorVideoID);
|
||||||
|
if (segments != null && segments.length > 0 && segments[segments.length - 1].length >= 2) {
|
||||||
|
changeStartSponsorButton(true, true);
|
||||||
|
} else if (segments != null && segments.length > 0 && segments[segments.length - 1].length < 2) {
|
||||||
|
changeStartSponsorButton(false, true);
|
||||||
|
} else {
|
||||||
|
changeStartSponsorButton(true, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//reset sponsor times submitting
|
//reset sponsor times submitting
|
||||||
sponsorTimesSubmitting = [];
|
sponsorTimesSubmitting = [];
|
||||||
|
updateSponsorTimesSubmitting();
|
||||||
|
|
||||||
//see if the onvideo control image needs to be changed
|
|
||||||
utils.wait(getControls).then(result => {
|
|
||||||
chrome.runtime.sendMessage({
|
|
||||||
message: "getSponsorTimes",
|
|
||||||
videoID: id
|
|
||||||
}, function(response) {
|
|
||||||
if (response != undefined) {
|
|
||||||
let sponsorTimes = response.sponsorTimes;
|
|
||||||
if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length >= 2) {
|
|
||||||
changeStartSponsorButton(true, true);
|
|
||||||
} else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
|
||||||
changeStartSponsorButton(false, true);
|
|
||||||
} else {
|
|
||||||
changeStartSponsorButton(true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
//see if this data should be saved in the sponsorTimesSubmitting variable
|
|
||||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
|
||||||
sponsorTimesSubmitting = sponsorTimes;
|
|
||||||
|
|
||||||
updatePreviewBar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//see if video controls buttons should be added
|
//see if video controls buttons should be added
|
||||||
if (!onInvidious) {
|
if (!onInvidious) {
|
||||||
updateVisibilityOfPlayerControlsButton();
|
updateVisibilityOfPlayerControlsButton();
|
||||||
@@ -399,9 +381,9 @@ function handleMobileControlsMutations(): void {
|
|||||||
|
|
||||||
updateVisibilityOfPlayerControlsButton().then((createdButtons) => {
|
updateVisibilityOfPlayerControlsButton().then((createdButtons) => {
|
||||||
if (createdButtons) {
|
if (createdButtons) {
|
||||||
if (sponsorTimesSubmitting != null && sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].length >= 2) {
|
if (sponsorTimesSubmitting != null && sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length >= 2) {
|
||||||
changeStartSponsorButton(true, true);
|
changeStartSponsorButton(true, true);
|
||||||
} else if (sponsorTimesSubmitting != null && sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].length < 2) {
|
} else if (sponsorTimesSubmitting != null && sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length < 2) {
|
||||||
changeStartSponsorButton(false, true);
|
changeStartSponsorButton(false, true);
|
||||||
} else {
|
} else {
|
||||||
changeStartSponsorButton(true, false);
|
changeStartSponsorButton(true, false);
|
||||||
@@ -488,7 +470,8 @@ function startSponsorSchedule(currentTime?: number): void {
|
|||||||
|
|
||||||
if (skipInfo.index === -1) return;
|
if (skipInfo.index === -1) return;
|
||||||
|
|
||||||
let skipTime = skipInfo.array[skipInfo.index];
|
let currentSkip = skipInfo.array[skipInfo.index];
|
||||||
|
let skipTime = currentSkip.segment;
|
||||||
let timeUntilSponsor = skipTime[0] - currentTime;
|
let timeUntilSponsor = skipTime[0] - currentTime;
|
||||||
|
|
||||||
let skippingFunction = () => {
|
let skippingFunction = () => {
|
||||||
@@ -501,7 +484,8 @@ function startSponsorSchedule(currentTime?: number): void {
|
|||||||
if (currentVideoID == sponsorVideoID) {
|
if (currentVideoID == sponsorVideoID) {
|
||||||
skipToTime(video, skipInfo.index, skipInfo.array, skipInfo.openNotice);
|
skipToTime(video, skipInfo.index, skipInfo.array, skipInfo.openNotice);
|
||||||
|
|
||||||
if (Config.config.disableAutoSkip) {
|
// TODO: Know the autoSkip settings for ALL items being skipped
|
||||||
|
if (utils.getCategorySelection(currentSkip.category)) {
|
||||||
forcedSkipTime = skipTime[0] + 0.001;
|
forcedSkipTime = skipTime[0] + 0.001;
|
||||||
} else {
|
} else {
|
||||||
forcedSkipTime = skipTime[1];
|
forcedSkipTime = skipTime[1];
|
||||||
@@ -608,35 +592,42 @@ function sponsorsLookup(id: string, channelIDPromise?) {
|
|||||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
sponsorDataFound = true;
|
sponsorDataFound = true;
|
||||||
|
|
||||||
let recievedSponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
|
let recievedSegments: number[][] = JSON.parse(xmlhttp.responseText).sponsorTimes;
|
||||||
let recievedUUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
|
let recievedUUIDs: string[] = JSON.parse(xmlhttp.responseText).UUIDs;
|
||||||
|
|
||||||
// Check if any old submissions should be kept
|
// Check if any old submissions should be kept
|
||||||
for (let i = 0; i < UUIDs.length; i++) {
|
if (sponsorTimes !== null) {
|
||||||
if (UUIDs[i] === null) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
// This is a user submission, keep it
|
if (sponsorTimes[i].UUID === null) {
|
||||||
recievedSponsorTimes.push(sponsorTimes[i]);
|
// This is a user submission, keep it
|
||||||
recievedUUIDs.push(UUIDs[i]);
|
recievedSegments.push(sponsorTimes[i].segment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sponsorTimes = recievedSponsorTimes;
|
// Create formatted array
|
||||||
UUIDs = recievedUUIDs;
|
sponsorTimes = [];
|
||||||
|
for (let i = 0; i < recievedSegments.length; i++) {
|
||||||
|
sponsorTimes.push({
|
||||||
|
segment: recievedSegments[i],
|
||||||
|
UUID: recievedUUIDs[i],
|
||||||
|
// Force sponsor category for now
|
||||||
|
//TODO: Remove this
|
||||||
|
category: "sponsor"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Remove all submissions smaller than the minimum duration
|
// Remove all submissions smaller than the minimum duration
|
||||||
if (Config.config.minDuration !== 0) {
|
if (Config.config.minDuration !== 0) {
|
||||||
let smallSponsors = [];
|
let smallSegments: SponsorTime[] = [];
|
||||||
let smallUUIDs = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
if (sponsorTimes[i][1] - sponsorTimes[i][0] >= Config.config.minDuration) {
|
if (sponsorTimes[i].segment[1] - sponsorTimes[i].segment[0] >= Config.config.minDuration) {
|
||||||
smallSponsors.push(sponsorTimes[i]);
|
smallSegments.push(sponsorTimes[i]);
|
||||||
smallUUIDs.push(UUIDs[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sponsorTimes = smallSponsors;
|
sponsorTimes = smallSegments;
|
||||||
UUIDs = smallUUIDs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!switchingVideos) {
|
if (!switchingVideos) {
|
||||||
@@ -823,17 +814,23 @@ function updatePreviewBar() {
|
|||||||
let types = [];
|
let types = [];
|
||||||
for (let i = 0; i < localSponsorTimes.length; i++) {
|
for (let i = 0; i < localSponsorTimes.length; i++) {
|
||||||
if (!hiddenSponsorTimes.includes(i)) {
|
if (!hiddenSponsorTimes.includes(i)) {
|
||||||
types.push("sponsor");
|
types.push(localSponsorTimes[i].category);
|
||||||
} else {
|
} else {
|
||||||
// Don't show this sponsor
|
// Don't show this sponsor
|
||||||
types.push(null);
|
types.push(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
||||||
types.push("previewSponsor");
|
types.push("preview-" + sponsorTimesSubmitting[i].category);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.wait(() => previewBar !== null).then((result) => previewBar.set(allSponsorTimes, types, video.duration));
|
// Convert sponsorTimes into segments
|
||||||
|
let allSegments: number[][] = [];
|
||||||
|
for (const sponsorTime of allSponsorTimes) {
|
||||||
|
allSegments.push(sponsorTime.segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.wait(() => previewBar !== null).then((result) => previewBar.set(allSegments, types, video.duration));
|
||||||
|
|
||||||
//update last video id
|
//update last video id
|
||||||
lastPreviewBarUpdate = sponsorVideoID;
|
lastPreviewBarUpdate = sponsorVideoID;
|
||||||
@@ -852,33 +849,73 @@ function whitelistCheck() {
|
|||||||
/**
|
/**
|
||||||
* Returns info about the next upcoming sponsor skip
|
* Returns info about the next upcoming sponsor skip
|
||||||
*/
|
*/
|
||||||
function getNextSkipIndex(currentTime: number): {array: number[][], index: number, openNotice: boolean} {
|
function getNextSkipIndex(currentTime: number): {array: SponsorTime[], index: number, endIndex: number, openNotice: boolean} {
|
||||||
let sponsorStartTimes = getStartTimes(sponsorTimes);
|
let sponsorStartTimes = getStartTimes(sponsorTimes);
|
||||||
let sponsorStartTimesAfterCurrentTime = getStartTimes(sponsorTimes, currentTime, true);
|
let sponsorStartTimesAfterCurrentTime = getStartTimes(sponsorTimes, currentTime, true);
|
||||||
|
|
||||||
let minSponsorTimeIndex = sponsorStartTimes.indexOf(Math.min(...sponsorStartTimesAfterCurrentTime));
|
let minSponsorTimeIndex = sponsorStartTimes.indexOf(Math.min(...sponsorStartTimesAfterCurrentTime));
|
||||||
|
let endTimeIndex = getLatestEndTimeIndex(sponsorTimes, minSponsorTimeIndex);
|
||||||
|
|
||||||
let previewSponsorStartTimes = getStartTimes(sponsorTimesSubmitting);
|
let previewSponsorStartTimes = getStartTimes(sponsorTimesSubmitting);
|
||||||
let previewSponsorStartTimesAfterCurrentTime = getStartTimes(sponsorTimesSubmitting, currentTime, false);
|
let previewSponsorStartTimesAfterCurrentTime = getStartTimes(sponsorTimesSubmitting, currentTime, false);
|
||||||
|
|
||||||
let minPreviewSponsorTimeIndex = previewSponsorStartTimes.indexOf(Math.min(...previewSponsorStartTimesAfterCurrentTime));
|
let minPreviewSponsorTimeIndex = previewSponsorStartTimes.indexOf(Math.min(...previewSponsorStartTimesAfterCurrentTime));
|
||||||
|
let previewEndTimeIndex = getLatestEndTimeIndex(sponsorTimesSubmitting, minPreviewSponsorTimeIndex);
|
||||||
|
|
||||||
if ((minPreviewSponsorTimeIndex === -1 && minSponsorTimeIndex !== -1) ||
|
if ((minPreviewSponsorTimeIndex === -1 && minSponsorTimeIndex !== -1) ||
|
||||||
sponsorStartTimes[minSponsorTimeIndex] < previewSponsorStartTimes[minPreviewSponsorTimeIndex]) {
|
sponsorStartTimes[minSponsorTimeIndex] < previewSponsorStartTimes[minPreviewSponsorTimeIndex]) {
|
||||||
return {
|
return {
|
||||||
array: sponsorTimes,
|
array: sponsorTimes,
|
||||||
index: minSponsorTimeIndex,
|
index: minSponsorTimeIndex,
|
||||||
|
endIndex: endTimeIndex,
|
||||||
openNotice: true
|
openNotice: true
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
array: sponsorTimesSubmitting,
|
array: sponsorTimesSubmitting,
|
||||||
index: minPreviewSponsorTimeIndex,
|
index: minPreviewSponsorTimeIndex,
|
||||||
|
endIndex: previewEndTimeIndex,
|
||||||
openNotice: false
|
openNotice: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns index if the skip option is not AutoSkip
|
||||||
|
*
|
||||||
|
* Finds the last endTime that occurs in a segment that the given
|
||||||
|
* segment skips into that is part of an AutoSkip category.
|
||||||
|
*
|
||||||
|
* Used to find where a segment should truely skip to if there are intersecting submissions due to
|
||||||
|
* them having different categories.
|
||||||
|
*
|
||||||
|
* @param sponsorTimes
|
||||||
|
* @param index Index of the given sponsor
|
||||||
|
* @param hideHiddenSponsors
|
||||||
|
*/
|
||||||
|
function getLatestEndTimeIndex(sponsorTimes: SponsorTime[], index: number, hideHiddenSponsors: boolean = true): number {
|
||||||
|
// Only combine segments for AutoSkip
|
||||||
|
if (index == -1 ||
|
||||||
|
utils.getCategorySelection(sponsorTimes[index].category).option !== CategorySkipOption.AutoSkip) return index;
|
||||||
|
|
||||||
|
// Default to the normal endTime
|
||||||
|
let latestEndTimeIndex = index;
|
||||||
|
|
||||||
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
|
let currentSegment = sponsorTimes[i].segment;
|
||||||
|
let latestEndTime = sponsorTimes[latestEndTimeIndex].segment[1];
|
||||||
|
|
||||||
|
if (currentSegment[0] <= latestEndTime && currentSegment[1] > latestEndTime
|
||||||
|
&& (!hideHiddenSponsors || !hiddenSponsorTimes.includes(i))
|
||||||
|
&& utils.getCategorySelection(sponsorTimes[index].category).option === CategorySkipOption.AutoSkip) {
|
||||||
|
// Overlapping segment
|
||||||
|
latestEndTimeIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return latestEndTimeIndex;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets just the start times from a sponsor times array.
|
* Gets just the start times from a sponsor times array.
|
||||||
* Optionally specify a minimum
|
* Optionally specify a minimum
|
||||||
@@ -887,14 +924,14 @@ function getNextSkipIndex(currentTime: number): {array: number[][], index: numbe
|
|||||||
* @param minimum
|
* @param minimum
|
||||||
* @param hideHiddenSponsors
|
* @param hideHiddenSponsors
|
||||||
*/
|
*/
|
||||||
function getStartTimes(sponsorTimes: number[][], minimum?: number, hideHiddenSponsors: boolean = false): number[] {
|
function getStartTimes(sponsorTimes: SponsorTime[], minimum?: number, hideHiddenSponsors: boolean = false): number[] {
|
||||||
if (sponsorTimes === null) return [];
|
if (sponsorTimes === null) return [];
|
||||||
|
|
||||||
let startTimes: number[] = [];
|
let startTimes: number[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
if ((minimum === undefined || sponsorTimes[i][0] >= minimum) && (!hideHiddenSponsors || !hiddenSponsorTimes.includes(i))) {
|
if ((minimum === undefined || sponsorTimes[i].segment[0] >= minimum) && (!hideHiddenSponsors || !hiddenSponsorTimes.includes(i))) {
|
||||||
startTimes.push(sponsorTimes[i][0]);
|
startTimes.push(sponsorTimes[i].segment[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -923,33 +960,36 @@ function previewTime(time: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//skip from the start time to the end time for a certain index sponsor time
|
//skip from the start time to the end time for a certain index sponsor time
|
||||||
function skipToTime(v, index, sponsorTimes, openNotice) {
|
function skipToTime(v: HTMLVideoElement, index: number, sponsorTimes: SponsorTime[], openNotice: boolean) {
|
||||||
if (!Config.config.disableAutoSkip || previewResetter !== null) {
|
|
||||||
v.currentTime = sponsorTimes[index][1];
|
let autoSkip: boolean = utils.getCategorySelection(sponsorTimes[index].category).option === CategorySkipOption.AutoSkip;
|
||||||
|
|
||||||
|
if (autoSkip || previewResetter !== null) {
|
||||||
|
v.currentTime = sponsorTimes[index].segment[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSponsorTimeSkipped = sponsorTimes[index][0];
|
lastSponsorTimeSkipped = sponsorTimes[index].segment[0];
|
||||||
|
|
||||||
let currentUUID = UUIDs[index];
|
let currentUUID: string = sponsorTimes[index].UUID;
|
||||||
lastSponsorTimeSkippedUUID = currentUUID;
|
lastSponsorTimeSkippedUUID = currentUUID;
|
||||||
|
|
||||||
if (openNotice) {
|
if (openNotice) {
|
||||||
//send out the message saying that a sponsor message was skipped
|
//send out the message saying that a sponsor message was skipped
|
||||||
if (!Config.config.dontShowNotice) {
|
if (!Config.config.dontShowNotice) {
|
||||||
let skipNotice = new SkipNotice(currentUUID, Config.config.disableAutoSkip, skipNoticeContentContainer);
|
let skipNotice = new SkipNotice(currentUUID, autoSkip, skipNoticeContentContainer);
|
||||||
|
|
||||||
//auto-upvote this sponsor
|
//auto-upvote this sponsor
|
||||||
if (Config.config.trackViewCount && !Config.config.disableAutoSkip && Config.config.autoUpvote) {
|
if (Config.config.trackViewCount && autoSkip && Config.config.autoUpvote) {
|
||||||
vote(1, currentUUID, null);
|
vote(1, currentUUID, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//send telemetry that a this sponsor was skipped
|
//send telemetry that a this sponsor was skipped
|
||||||
if (Config.config.trackViewCount && !sponsorSkipped[index] && !Config.config.disableAutoSkip) {
|
if (Config.config.trackViewCount && !sponsorSkipped[index] && autoSkip) {
|
||||||
utils.sendRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
|
utils.sendRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
|
||||||
|
|
||||||
// Count this as a skip
|
// Count this as a skip
|
||||||
Config.config.minutesSaved = Config.config.minutesSaved + (sponsorTimes[index][1] - sponsorTimes[index][0]) / 60;
|
Config.config.minutesSaved = Config.config.minutesSaved + (sponsorTimes[index].segment[1] - sponsorTimes[index].segment[0]) / 60;
|
||||||
Config.config.skipCount = Config.config.skipCount + 1;
|
Config.config.skipCount = Config.config.skipCount + 1;
|
||||||
|
|
||||||
sponsorSkipped[index] = true;
|
sponsorSkipped[index] = true;
|
||||||
@@ -960,14 +1000,14 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
|
|||||||
function unskipSponsorTime(UUID) {
|
function unskipSponsorTime(UUID) {
|
||||||
if (sponsorTimes != null) {
|
if (sponsorTimes != null) {
|
||||||
//add a tiny bit of time to make sure it is not skipped again
|
//add a tiny bit of time to make sure it is not skipped again
|
||||||
video.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001;
|
video.currentTime = utils.getSponsorTimeFromUUID(sponsorTimes, UUID)[0] + 0.001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function reskipSponsorTime(UUID) {
|
function reskipSponsorTime(UUID) {
|
||||||
if (sponsorTimes != null) {
|
if (sponsorTimes != null) {
|
||||||
//add a tiny bit of time to make sure it is not skipped again
|
//add a tiny bit of time to make sure it is not skipped again
|
||||||
video.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][1];
|
video.currentTime = utils.getSponsorTimeFromUUID(sponsorTimes, UUID)[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1082,40 +1122,57 @@ function startSponsorClicked() {
|
|||||||
|
|
||||||
toggleStartSponsorButton();
|
toggleStartSponsorButton();
|
||||||
|
|
||||||
//send back current time with message
|
//add to sponsorTimes
|
||||||
chrome.runtime.sendMessage({
|
if (sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length < 2) {
|
||||||
message: "addSponsorTime",
|
//it is an end time
|
||||||
time: video.currentTime,
|
sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment[1] = video.currentTime;
|
||||||
videoID: sponsorVideoID
|
} else {
|
||||||
}, function(response) {
|
//it is a start time
|
||||||
//see if the sponsorTimesSubmitting needs to be updated
|
sponsorTimesSubmitting.push({
|
||||||
updateSponsorTimesSubmitting();
|
segment: [video.currentTime],
|
||||||
});
|
UUID: null,
|
||||||
|
// Default to sponsor
|
||||||
|
category: "sponsor"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create raw segment list
|
||||||
|
let segments: number[][] = [];
|
||||||
|
for (const sponsorTime of sponsorTimesSubmitting) {
|
||||||
|
segments.push(sponsorTime.segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
//save this info
|
||||||
|
Config.config.sponsorTimes.set(sponsorVideoID, segments);
|
||||||
|
|
||||||
|
updateSponsorTimesSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSponsorTimesSubmitting() {
|
function updateSponsorTimesSubmitting(getFromConfig: boolean = true) {
|
||||||
chrome.runtime.sendMessage({
|
let segments = Config.config.sponsorTimes.get(sponsorVideoID);
|
||||||
message: "getSponsorTimes",
|
|
||||||
videoID: sponsorVideoID
|
|
||||||
}, function(response) {
|
|
||||||
if (response != undefined) {
|
|
||||||
let sponsorTimes = response.sponsorTimes;
|
|
||||||
|
|
||||||
//see if this data should be saved in the sponsorTimesSubmitting variable
|
//see if this data should be saved in the sponsorTimesSubmitting variable
|
||||||
if (sponsorTimes != undefined) {
|
if (getFromConfig && segments != undefined) {
|
||||||
sponsorTimesSubmitting = sponsorTimes;
|
sponsorTimesSubmitting = [];
|
||||||
|
|
||||||
updatePreviewBar();
|
for (const segment of segments) {
|
||||||
|
sponsorTimesSubmitting.push({
|
||||||
// Restart skipping schedule
|
segment: segment,
|
||||||
startSponsorSchedule();
|
UUID: null,
|
||||||
|
// Default to sponsor
|
||||||
if (submissionNotice !== null) {
|
category: "sponsor"
|
||||||
submissionNotice.update();
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
updatePreviewBar();
|
||||||
|
|
||||||
|
// Restart skipping schedule
|
||||||
|
if (video !== null) startSponsorSchedule();
|
||||||
|
|
||||||
|
if (submissionNotice !== null) {
|
||||||
|
submissionNotice.update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
||||||
@@ -1255,7 +1312,7 @@ function vote(type, UUID, skipNotice?: SkipNoticeComponent) {
|
|||||||
skipNotice.setNoticeInfoMessage.bind(skipNotice)();
|
skipNotice.setNoticeInfoMessage.bind(skipNotice)();
|
||||||
}
|
}
|
||||||
|
|
||||||
let sponsorIndex = UUIDs.indexOf(UUID);
|
let sponsorIndex = utils.getSponsorIndexFromUUID(sponsorTimes, UUID);
|
||||||
|
|
||||||
// See if the local time saved count and skip count should be saved
|
// See if the local time saved count and skip count should be saved
|
||||||
if (type == 0 && sponsorSkipped[sponsorIndex] || type == 1 && !sponsorSkipped[sponsorIndex]) {
|
if (type == 0 && sponsorSkipped[sponsorIndex] || type == 1 && !sponsorSkipped[sponsorIndex]) {
|
||||||
@@ -1406,10 +1463,6 @@ function sendSubmitMessage(){
|
|||||||
if (sponsorTimes === null) sponsorTimes = [];
|
if (sponsorTimes === null) sponsorTimes = [];
|
||||||
|
|
||||||
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
|
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
|
||||||
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
|
|
||||||
// Add placeholder IDs
|
|
||||||
UUIDs.push(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Empty the submitting times
|
// Empty the submitting times
|
||||||
sponsorTimesSubmitting = [];
|
sponsorTimesSubmitting = [];
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ let barTypes = {
|
|||||||
color: "#00d400",
|
color: "#00d400",
|
||||||
opacity: "0.5"
|
opacity: "0.5"
|
||||||
},
|
},
|
||||||
"previewSponsor": {
|
"preview-sponsor": {
|
||||||
color: "#0000d4",
|
color: "#0000d4",
|
||||||
opacity: "0.5"
|
opacity: "0.5"
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/popup.ts
15
src/popup.ts
@@ -1,6 +1,7 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
|
import { SponsorTime } from "./types";
|
||||||
var utils = new Utils();
|
var utils = new Utils();
|
||||||
|
|
||||||
interface MessageListener {
|
interface MessageListener {
|
||||||
@@ -272,7 +273,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function infoFound(request) {
|
function infoFound(request: {found: boolean, sponsorTimes: SponsorTime[], hiddenSponsorTimes: number[]}) {
|
||||||
if(chrome.runtime.lastError) {
|
if(chrome.runtime.lastError) {
|
||||||
//This page doesn't have the injected content script, or at least not yet
|
//This page doesn't have the injected content script, or at least not yet
|
||||||
displayNoVideo();
|
displayNoVideo();
|
||||||
@@ -363,7 +364,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//display the video times from the array at the top, in a different section
|
//display the video times from the array at the top, in a different section
|
||||||
function displayDownloadedSponsorTimes(request) {
|
function displayDownloadedSponsorTimes(request: {found: boolean, sponsorTimes: SponsorTime[], hiddenSponsorTimes: number[]}) {
|
||||||
if (request.sponsorTimes != undefined) {
|
if (request.sponsorTimes != undefined) {
|
||||||
//set it to the message
|
//set it to the message
|
||||||
if (PageElements.downloadedSponsorMessageTimes.innerText != chrome.i18n.getMessage("channelWhitelisted")) {
|
if (PageElements.downloadedSponsorMessageTimes.innerText != chrome.i18n.getMessage("channelWhitelisted")) {
|
||||||
@@ -382,11 +383,11 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
extraInfo = " (hidden)";
|
extraInfo = " (hidden)";
|
||||||
}
|
}
|
||||||
|
|
||||||
sponsorTimeButton.innerText = getFormattedTime(request.sponsorTimes[i][0]) + " to " + getFormattedTime(request.sponsorTimes[i][1]) + extraInfo;
|
sponsorTimeButton.innerText = getFormattedTime(request.sponsorTimes[i].segment[0]) + " to " + getFormattedTime(request.sponsorTimes[i].segment[1]) + extraInfo;
|
||||||
|
|
||||||
let votingButtons = document.createElement("div");
|
let votingButtons = document.createElement("div");
|
||||||
|
|
||||||
let UUID = request.UUIDs[i];
|
let UUID = request.sponsorTimes[i].UUID;
|
||||||
|
|
||||||
//thumbs up and down buttons
|
//thumbs up and down buttons
|
||||||
let voteButtonsContainer = document.createElement("div");
|
let voteButtonsContainer = document.createElement("div");
|
||||||
@@ -430,12 +431,12 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//get the message that visually displays the video times
|
//get the message that visually displays the video times
|
||||||
function getSponsorTimesMessage(sponsorTimes) {
|
function getSponsorTimesMessage(sponsorTimes: SponsorTime[]) {
|
||||||
let sponsorTimesMessage = "";
|
let sponsorTimesMessage = "";
|
||||||
|
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
for (let s = 0; s < sponsorTimes[i].length; s++) {
|
for (let s = 0; s < sponsorTimes[i].segment.length; s++) {
|
||||||
let timeMessage = getFormattedTime(sponsorTimes[i][s]);
|
let timeMessage = getFormattedTime(sponsorTimes[i].segment[s]);
|
||||||
//if this is an end time
|
//if this is an end time
|
||||||
if (s == 1) {
|
if (s == 1) {
|
||||||
timeMessage = " to " + timeMessage;
|
timeMessage = " to " + timeMessage;
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import SkipNoticeComponent from "../components/SkipNoticeComponent";
|
|||||||
|
|
||||||
class SkipNotice {
|
class SkipNotice {
|
||||||
UUID: string;
|
UUID: string;
|
||||||
manualSkip: boolean;
|
autoSkip: boolean;
|
||||||
// Contains functions and variables from the content script needed by the skip notice
|
// Contains functions and variables from the content script needed by the skip notice
|
||||||
contentContainer: () => any;
|
contentContainer: () => any;
|
||||||
|
|
||||||
constructor(UUID: string, manualSkip: boolean = false, contentContainer) {
|
constructor(UUID: string, autoSkip: boolean = false, contentContainer) {
|
||||||
this.UUID = UUID;
|
this.UUID = UUID;
|
||||||
this.manualSkip = manualSkip;
|
this.autoSkip = autoSkip;
|
||||||
this.contentContainer = contentContainer;
|
this.contentContainer = contentContainer;
|
||||||
|
|
||||||
//get reference node
|
//get reference node
|
||||||
@@ -41,7 +41,7 @@ class SkipNotice {
|
|||||||
referenceNode.prepend(noticeElement);
|
referenceNode.prepend(noticeElement);
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<SkipNoticeComponent UUID={UUID} manualSkip={manualSkip} contentContainer={contentContainer} />,
|
<SkipNoticeComponent UUID={UUID} autoSkip={autoSkip} contentContainer={contentContainer} />,
|
||||||
noticeElement
|
noticeElement
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/types.ts
17
src/types.ts
@@ -6,10 +6,9 @@ interface ContentContainer {
|
|||||||
vote: (type: any, UUID: any, skipNotice?: SkipNoticeComponent) => void,
|
vote: (type: any, UUID: any, skipNotice?: SkipNoticeComponent) => void,
|
||||||
dontShowNoticeAgain: () => void,
|
dontShowNoticeAgain: () => void,
|
||||||
unskipSponsorTime: (UUID: any) => void,
|
unskipSponsorTime: (UUID: any) => void,
|
||||||
sponsorTimes: number[][],
|
sponsorTimes: SponsorTime[],
|
||||||
sponsorTimesSubmitting: number[][],
|
sponsorTimesSubmitting: SponsorTime[],
|
||||||
hiddenSponsorTimes: any[],
|
hiddenSponsorTimes: number[],
|
||||||
UUIDs: any[],
|
|
||||||
v: HTMLVideoElement,
|
v: HTMLVideoElement,
|
||||||
sponsorVideoID,
|
sponsorVideoID,
|
||||||
reskipSponsorTime: (UUID: any) => void,
|
reskipSponsorTime: (UUID: any) => void,
|
||||||
@@ -37,9 +36,17 @@ interface CategorySelection {
|
|||||||
option: CategorySkipOption
|
option: CategorySkipOption
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SponsorTime {
|
||||||
|
segment: number[];
|
||||||
|
UUID: string;
|
||||||
|
|
||||||
|
category: string;
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
VideoDurationResponse,
|
VideoDurationResponse,
|
||||||
ContentContainer,
|
ContentContainer,
|
||||||
|
CategorySelection,
|
||||||
CategorySkipOption,
|
CategorySkipOption,
|
||||||
CategorySelection
|
SponsorTime
|
||||||
};
|
};
|
||||||
23
src/utils.ts
23
src/utils.ts
@@ -1,4 +1,5 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
import { CategorySelection, SponsorTime } from "./types";
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
|
|
||||||
@@ -154,6 +155,28 @@ class Utils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSponsorIndexFromUUID(sponsorTimes: SponsorTime[], UUID: string): number {
|
||||||
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
|
if (sponsorTimes[i].UUID === UUID) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSponsorTimeFromUUID(sponsorTimes: SponsorTime[], UUID: string): SponsorTime {
|
||||||
|
return sponsorTimes[this.getSponsorIndexFromUUID(sponsorTimes, UUID)];
|
||||||
|
}
|
||||||
|
|
||||||
|
getCategorySelection(category: string): CategorySelection {
|
||||||
|
for (const selection of Config.config.categorySelections) {
|
||||||
|
if (selection.name === category) {
|
||||||
|
return selection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
localizeHtmlPage() {
|
localizeHtmlPage() {
|
||||||
//Localize by replacing __MSG_***__ meta tags
|
//Localize by replacing __MSG_***__ meta tags
|
||||||
var objects = document.getElementsByClassName("sponsorBlockPageBody")[0].children;
|
var objects = document.getElementsByClassName("sponsorBlockPageBody")[0].children;
|
||||||
|
|||||||
Reference in New Issue
Block a user