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:
Ajay Ramachandran
2020-04-04 21:04:17 -04:00
parent ec9f1efd55
commit bac9029a28
9 changed files with 227 additions and 144 deletions

View File

@@ -7,7 +7,7 @@ import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
export interface SkipNoticeProps {
UUID: string;
manualSkip: boolean;
autoSkip: boolean;
// Contains functions and variables from the content script needed by the skip notice
contentContainer: ContentContainer;
}
@@ -27,7 +27,7 @@ export interface SkipNoticeState {
class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeState> {
UUID: string;
manualSkip: boolean;
autoSkip: boolean;
// Contains functions and variables from the content script needed by the skip notice
contentContainer: ContentContainer;
@@ -42,12 +42,12 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
this.noticeRef = React.createRef();
this.UUID = props.UUID;
this.manualSkip = props.manualSkip;
this.autoSkip = props.autoSkip;
this.contentContainer = props.contentContainer;
let noticeTitle = chrome.i18n.getMessage("noticeTitle");
if (this.manualSkip) {
if (!this.autoSkip) {
noticeTitle = chrome.i18n.getMessage("noticeTitleNotSkipped");
}
@@ -139,7 +139,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
</td>
{/* Never show button if manualSkip is disabled */}
{this.manualSkip ? "" :
{!this.autoSkip ? "" :
<td className="sponsorSkipNoticeRightSection">
<button className="sponsorSkipObject sponsorSkipNoticeButton sponsorSkipNoticeRightButton"
onClick={this.contentContainer().dontShowNoticeAgain}>
@@ -223,7 +223,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
});
// See if the title should be changed
if (this.manualSkip) {
if (!this.autoSkip) {
this.setState({
noticeTitle: chrome.i18n.getMessage("noticeTitle")
});
@@ -239,7 +239,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
//remove this sponsor from the sponsors looked up
//find which one it is
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
//add this as a hidden sponsorTime

View File

@@ -4,7 +4,7 @@ import Config from "../config";
import * as CompileConfig from "../../config.json";
import Utils from "../utils";
import { ContentContainer } from "../types";
import { ContentContainer, SponsorTime } from "../types";
import SubmissionNoticeComponent from "./SubmissionNoticeComponent";
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 */
getFormattedSponsorTimesEdits(sponsorTime: number[]): string[][] {
return [[String(utils.getFormattedMinutes(sponsorTime[0])), String(utils.getFormattedSeconds(sponsorTime[0]))],
[String(utils.getFormattedMinutes(sponsorTime[1])), String(utils.getFormattedSeconds(sponsorTime[1]))]];
getFormattedSponsorTimesEdits(sponsorTime: SponsorTime): string[][] {
return [[String(utils.getFormattedMinutes(sponsorTime.segment[0])), String(utils.getFormattedSeconds(sponsorTime.segment[0]))],
[String(utils.getFormattedMinutes(sponsorTime.segment[1])), String(utils.getFormattedSeconds(sponsorTime.segment[1]))]];
}
saveEditTimes() {
//TODO: Properly save categories and times
// Save sponsorTimes
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[1][0]), parseFloat(this.state.sponsorTimeEdits[1][1]))];
// 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[1][0]), parseFloat(this.state.sponsorTimeEdits[1][1]))];
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;
//if it is not a complete sponsor time
if (sponsorTimes[index].length < 2) {
if (sponsorTimes[index].segment.length < 2) {
//update video player
this.props.contentContainer().changeStartSponsorButton(true, false);
}

View File

@@ -11,7 +11,6 @@ interface SBConfig {
skipCount: number,
sponsorTimesContributed: number,
disableSkipping: boolean,
disableAutoSkip: boolean,
trackViewCount: boolean,
dontShowNotice: boolean,
hideVideoPlayerControls: boolean,
@@ -109,7 +108,6 @@ var Config: SBObject = {
skipCount: 0,
sponsorTimesContributed: 0,
disableSkipping: false,
disableAutoSkip: false,
trackViewCount: true,
dontShowNotice: false,
hideVideoPlayerControls: false,

View File

@@ -1,10 +1,11 @@
import Config from "./config";
import { SponsorTime, CategorySkipOption, CategorySelection } from "./types";
import { ContentContainer } from "./types";
import Utils from "./utils";
var utils = new Utils();
import runThePopup from "./popup";
import PreviewBar from "./js-components/previewBar";
@@ -19,8 +20,7 @@ utils.wait(() => Config.config !== null, 5000, 10).then(addCSS);
var sponsorDataFound = false;
var previousVideoID = null;
//the actual sponsorTimes if loaded and UUIDs associated with them
var sponsorTimes: number[][] = null;
var UUIDs = [];
var sponsorTimes: SponsorTime[] = null;
//what video id are these sponsors for
var sponsorVideoID = null;
@@ -31,7 +31,7 @@ var currentSkipSchedule: NodeJS.Timeout = null;
var seekListenerSetUp = false
//these are sponsors that have been downvoted
var hiddenSponsorTimes = [];
var hiddenSponsorTimes: number[] = [];
/** @type {Array[boolean]} Has the sponsor been skipped */
var sponsorSkipped = [];
@@ -87,15 +87,15 @@ var sponsorLookupRetries = 0;
//the last time in the video a sponsor was skipped
//used for the go back button
var lastSponsorTimeSkipped = null;
var lastSponsorTimeSkipped: number = null;
//used for ratings
var lastSponsorTimeSkippedUUID = null;
var lastSponsorTimeSkippedUUID: string = null;
//if showing the start sponsor button or the end sponsor button on the player
var showingStartSponsor = true;
//the sponsor times being prepared to be submitted
var sponsorTimesSubmitting = [];
var sponsorTimesSubmitting: SponsorTime[] = [];
//becomes true when isInfoFound is called
//this is used to close the popup on YouTube when the other popup opens
@@ -111,7 +111,6 @@ var skipNoticeContentContainer: ContentContainer = () => ({
sponsorTimes,
sponsorTimesSubmitting,
hiddenSponsorTimes,
UUIDs,
v: video,
sponsorVideoID,
reskipSponsorTime,
@@ -145,8 +144,7 @@ function messageListener(request: any, sender: any, sendResponse: (response: any
sendResponse({
found: sponsorDataFound,
sponsorTimes: sponsorTimes,
hiddenSponsorTimes: hiddenSponsorTimes,
UUIDs: UUIDs
hiddenSponsorTimes: hiddenSponsorTimes
});
if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
@@ -267,7 +265,6 @@ function resetValues() {
//reset sponsor times
sponsorTimes = null;
UUIDs = [];
sponsorLookupRetries = 0;
//empty the preview bar
@@ -357,36 +354,21 @@ async function videoIDChange(id) {
sponsorsLookup(id, channelIDPromise);
//make sure everything is properly added
updateVisibilityOfPlayerControlsButton();
//reset sponsor times submitting
sponsorTimesSubmitting = [];
updateVisibilityOfPlayerControlsButton().then(() => {
//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) {
let segments = Config.config.sponsorTimes.get(sponsorVideoID);
if (segments != null && segments.length > 0 && segments[segments.length - 1].length >= 2) {
changeStartSponsorButton(true, true);
} else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
} else if (segments != null && segments.length > 0 && segments[segments.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();
}
}
});
});
//reset sponsor times submitting
sponsorTimesSubmitting = [];
updateSponsorTimesSubmitting();
//see if video controls buttons should be added
if (!onInvidious) {
@@ -399,9 +381,9 @@ function handleMobileControlsMutations(): void {
updateVisibilityOfPlayerControlsButton().then((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);
} 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);
} else {
changeStartSponsorButton(true, false);
@@ -488,7 +470,8 @@ function startSponsorSchedule(currentTime?: number): void {
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 skippingFunction = () => {
@@ -501,7 +484,8 @@ function startSponsorSchedule(currentTime?: number): void {
if (currentVideoID == sponsorVideoID) {
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;
} else {
forcedSkipTime = skipTime[1];
@@ -608,35 +592,42 @@ function sponsorsLookup(id: string, channelIDPromise?) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
sponsorDataFound = true;
let recievedSponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
let recievedUUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
let recievedSegments: number[][] = JSON.parse(xmlhttp.responseText).sponsorTimes;
let recievedUUIDs: string[] = JSON.parse(xmlhttp.responseText).UUIDs;
// Check if any old submissions should be kept
for (let i = 0; i < UUIDs.length; i++) {
if (UUIDs[i] === null) {
if (sponsorTimes !== null) {
for (let i = 0; i < sponsorTimes.length; i++) {
if (sponsorTimes[i].UUID === null) {
// This is a user submission, keep it
recievedSponsorTimes.push(sponsorTimes[i]);
recievedUUIDs.push(UUIDs[i]);
recievedSegments.push(sponsorTimes[i].segment);
}
}
}
sponsorTimes = recievedSponsorTimes;
UUIDs = recievedUUIDs;
// Create formatted array
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
if (Config.config.minDuration !== 0) {
let smallSponsors = [];
let smallUUIDs = [];
let smallSegments: SponsorTime[] = [];
for (let i = 0; i < sponsorTimes.length; i++) {
if (sponsorTimes[i][1] - sponsorTimes[i][0] >= Config.config.minDuration) {
smallSponsors.push(sponsorTimes[i]);
smallUUIDs.push(UUIDs[i]);
if (sponsorTimes[i].segment[1] - sponsorTimes[i].segment[0] >= Config.config.minDuration) {
smallSegments.push(sponsorTimes[i]);
}
}
sponsorTimes = smallSponsors;
UUIDs = smallUUIDs;
sponsorTimes = smallSegments;
}
if (!switchingVideos) {
@@ -823,17 +814,23 @@ function updatePreviewBar() {
let types = [];
for (let i = 0; i < localSponsorTimes.length; i++) {
if (!hiddenSponsorTimes.includes(i)) {
types.push("sponsor");
types.push(localSponsorTimes[i].category);
} else {
// Don't show this sponsor
types.push(null);
}
}
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
lastPreviewBarUpdate = sponsorVideoID;
@@ -852,33 +849,73 @@ function whitelistCheck() {
/**
* 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 sponsorStartTimesAfterCurrentTime = getStartTimes(sponsorTimes, currentTime, true);
let minSponsorTimeIndex = sponsorStartTimes.indexOf(Math.min(...sponsorStartTimesAfterCurrentTime));
let endTimeIndex = getLatestEndTimeIndex(sponsorTimes, minSponsorTimeIndex);
let previewSponsorStartTimes = getStartTimes(sponsorTimesSubmitting);
let previewSponsorStartTimesAfterCurrentTime = getStartTimes(sponsorTimesSubmitting, currentTime, false);
let minPreviewSponsorTimeIndex = previewSponsorStartTimes.indexOf(Math.min(...previewSponsorStartTimesAfterCurrentTime));
let previewEndTimeIndex = getLatestEndTimeIndex(sponsorTimesSubmitting, minPreviewSponsorTimeIndex);
if ((minPreviewSponsorTimeIndex === -1 && minSponsorTimeIndex !== -1) ||
sponsorStartTimes[minSponsorTimeIndex] < previewSponsorStartTimes[minPreviewSponsorTimeIndex]) {
return {
array: sponsorTimes,
index: minSponsorTimeIndex,
endIndex: endTimeIndex,
openNotice: true
};
} else {
return {
array: sponsorTimesSubmitting,
index: minPreviewSponsorTimeIndex,
endIndex: previewEndTimeIndex,
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.
* Optionally specify a minimum
@@ -887,14 +924,14 @@ function getNextSkipIndex(currentTime: number): {array: number[][], index: numbe
* @param minimum
* @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 [];
let startTimes: number[] = [];
for (let i = 0; i < sponsorTimes.length; i++) {
if ((minimum === undefined || sponsorTimes[i][0] >= minimum) && (!hideHiddenSponsors || !hiddenSponsorTimes.includes(i))) {
startTimes.push(sponsorTimes[i][0]);
if ((minimum === undefined || sponsorTimes[i].segment[0] >= minimum) && (!hideHiddenSponsors || !hiddenSponsorTimes.includes(i))) {
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
function skipToTime(v, index, sponsorTimes, openNotice) {
if (!Config.config.disableAutoSkip || previewResetter !== null) {
v.currentTime = sponsorTimes[index][1];
function skipToTime(v: HTMLVideoElement, index: number, sponsorTimes: SponsorTime[], openNotice: boolean) {
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;
if (openNotice) {
//send out the message saying that a sponsor message was skipped
if (!Config.config.dontShowNotice) {
let skipNotice = new SkipNotice(currentUUID, Config.config.disableAutoSkip, skipNoticeContentContainer);
let skipNotice = new SkipNotice(currentUUID, autoSkip, skipNoticeContentContainer);
//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);
}
}
//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);
// 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;
sponsorSkipped[index] = true;
@@ -960,14 +1000,14 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
function unskipSponsorTime(UUID) {
if (sponsorTimes != null) {
//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) {
if (sponsorTimes != null) {
//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();
//send back current time with message
chrome.runtime.sendMessage({
message: "addSponsorTime",
time: video.currentTime,
videoID: sponsorVideoID
}, function(response) {
//see if the sponsorTimesSubmitting needs to be updated
updateSponsorTimesSubmitting();
//add to sponsorTimes
if (sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length < 2) {
//it is an end time
sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment[1] = video.currentTime;
} else {
//it is a start time
sponsorTimesSubmitting.push({
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() {
chrome.runtime.sendMessage({
message: "getSponsorTimes",
videoID: sponsorVideoID
}, function(response) {
if (response != undefined) {
let sponsorTimes = response.sponsorTimes;
function updateSponsorTimesSubmitting(getFromConfig: boolean = true) {
let segments = Config.config.sponsorTimes.get(sponsorVideoID);
//see if this data should be saved in the sponsorTimesSubmitting variable
if (sponsorTimes != undefined) {
sponsorTimesSubmitting = sponsorTimes;
if (getFromConfig && segments != undefined) {
sponsorTimesSubmitting = [];
for (const segment of segments) {
sponsorTimesSubmitting.push({
segment: segment,
UUID: null,
// Default to sponsor
category: "sponsor"
});
}
}
updatePreviewBar();
// Restart skipping schedule
startSponsorSchedule();
if (video !== null) startSponsorSchedule();
if (submissionNotice !== null) {
submissionNotice.update();
}
}
}
});
}
async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
@@ -1255,7 +1312,7 @@ function vote(type, UUID, skipNotice?: SkipNoticeComponent) {
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
if (type == 0 && sponsorSkipped[sponsorIndex] || type == 1 && !sponsorSkipped[sponsorIndex]) {
@@ -1406,10 +1463,6 @@ function sendSubmitMessage(){
if (sponsorTimes === null) sponsorTimes = [];
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
// Add placeholder IDs
UUIDs.push(null);
}
// Empty the submitting times
sponsorTimesSubmitting = [];

View File

@@ -14,7 +14,7 @@ let barTypes = {
color: "#00d400",
opacity: "0.5"
},
"previewSponsor": {
"preview-sponsor": {
color: "#0000d4",
opacity: "0.5"
}

View File

@@ -1,6 +1,7 @@
import Config from "./config";
import Utils from "./utils";
import { SponsorTime } from "./types";
var utils = new Utils();
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) {
//This page doesn't have the injected content script, or at least not yet
displayNoVideo();
@@ -363,7 +364,7 @@ async function runThePopup(messageListener?: MessageListener) {
}
//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) {
//set it to the message
if (PageElements.downloadedSponsorMessageTimes.innerText != chrome.i18n.getMessage("channelWhitelisted")) {
@@ -382,11 +383,11 @@ async function runThePopup(messageListener?: MessageListener) {
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 UUID = request.UUIDs[i];
let UUID = request.sponsorTimes[i].UUID;
//thumbs up and down buttons
let voteButtonsContainer = document.createElement("div");
@@ -430,12 +431,12 @@ async function runThePopup(messageListener?: MessageListener) {
}
//get the message that visually displays the video times
function getSponsorTimesMessage(sponsorTimes) {
function getSponsorTimesMessage(sponsorTimes: SponsorTime[]) {
let sponsorTimesMessage = "";
for (let i = 0; i < sponsorTimes.length; i++) {
for (let s = 0; s < sponsorTimes[i].length; s++) {
let timeMessage = getFormattedTime(sponsorTimes[i][s]);
for (let s = 0; s < sponsorTimes[i].segment.length; s++) {
let timeMessage = getFormattedTime(sponsorTimes[i].segment[s]);
//if this is an end time
if (s == 1) {
timeMessage = " to " + timeMessage;

View File

@@ -5,13 +5,13 @@ import SkipNoticeComponent from "../components/SkipNoticeComponent";
class SkipNotice {
UUID: string;
manualSkip: boolean;
autoSkip: boolean;
// Contains functions and variables from the content script needed by the skip notice
contentContainer: () => any;
constructor(UUID: string, manualSkip: boolean = false, contentContainer) {
constructor(UUID: string, autoSkip: boolean = false, contentContainer) {
this.UUID = UUID;
this.manualSkip = manualSkip;
this.autoSkip = autoSkip;
this.contentContainer = contentContainer;
//get reference node
@@ -41,7 +41,7 @@ class SkipNotice {
referenceNode.prepend(noticeElement);
ReactDOM.render(
<SkipNoticeComponent UUID={UUID} manualSkip={manualSkip} contentContainer={contentContainer} />,
<SkipNoticeComponent UUID={UUID} autoSkip={autoSkip} contentContainer={contentContainer} />,
noticeElement
);
}

View File

@@ -6,10 +6,9 @@ interface ContentContainer {
vote: (type: any, UUID: any, skipNotice?: SkipNoticeComponent) => void,
dontShowNoticeAgain: () => void,
unskipSponsorTime: (UUID: any) => void,
sponsorTimes: number[][],
sponsorTimesSubmitting: number[][],
hiddenSponsorTimes: any[],
UUIDs: any[],
sponsorTimes: SponsorTime[],
sponsorTimesSubmitting: SponsorTime[],
hiddenSponsorTimes: number[],
v: HTMLVideoElement,
sponsorVideoID,
reskipSponsorTime: (UUID: any) => void,
@@ -37,9 +36,17 @@ interface CategorySelection {
option: CategorySkipOption
}
interface SponsorTime {
segment: number[];
UUID: string;
category: string;
}
export {
VideoDurationResponse,
ContentContainer,
CategorySelection,
CategorySkipOption,
CategorySelection
SponsorTime
};

View File

@@ -1,4 +1,5 @@
import Config from "./config";
import { CategorySelection, SponsorTime } from "./types";
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() {
//Localize by replacing __MSG_***__ meta tags
var objects = document.getElementsByClassName("sponsorBlockPageBody")[0].children;