mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 20:17:05 +03:00
Redid hidden sponsor implementation + added info about being hid due to minimum duration
Fixes https://github.com/ajayyy/SponsorBlock/issues/326 and https://github.com/ajayyy/SponsorBlock/issues/325
This commit is contained in:
@@ -534,5 +534,11 @@
|
|||||||
},
|
},
|
||||||
"bracketEnd": {
|
"bracketEnd": {
|
||||||
"message": "(End)"
|
"message": "(End)"
|
||||||
|
},
|
||||||
|
"hiddenDueToDownvote": {
|
||||||
|
"message": "hidden: downvote"
|
||||||
|
},
|
||||||
|
"hiddenDueToDuration": {
|
||||||
|
"message": "hidden: too short"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import Config from "../config"
|
import Config from "../config"
|
||||||
import { ContentContainer } from "../types";
|
import { ContentContainer, SponsorHideType } from "../types";
|
||||||
|
|
||||||
import Utils from "../utils";
|
import Utils from "../utils";
|
||||||
var utils = new Utils();
|
var utils = new Utils();
|
||||||
@@ -269,7 +269,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
|||||||
//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
|
||||||
this.contentContainer().hiddenSponsorTimes.push(i);
|
this.contentContainer().sponsorTimes[i].hidden = SponsorHideType.Downvoted;
|
||||||
|
|
||||||
this.contentContainer().updatePreviewBar();
|
this.contentContainer().updatePreviewBar();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
|
||||||
import { SponsorTime, CategorySkipOption, CategorySelection, VideoID } from "./types";
|
import { SponsorTime, CategorySkipOption, CategorySelection, VideoID, SponsorHideType } from "./types";
|
||||||
|
|
||||||
import { ContentContainer } from "./types";
|
import { ContentContainer } from "./types";
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
@@ -30,9 +30,6 @@ var sponsorVideoID: VideoID = null;
|
|||||||
var currentSkipSchedule: NodeJS.Timeout = null;
|
var currentSkipSchedule: NodeJS.Timeout = null;
|
||||||
var seekListenerSetUp = false
|
var seekListenerSetUp = false
|
||||||
|
|
||||||
//these are sponsors that have been downvoted
|
|
||||||
var hiddenSponsorTimes: number[] = [];
|
|
||||||
|
|
||||||
/** @type {Array[boolean]} Has the sponsor been skipped */
|
/** @type {Array[boolean]} Has the sponsor been skipped */
|
||||||
var sponsorSkipped: boolean[] = [];
|
var sponsorSkipped: boolean[] = [];
|
||||||
|
|
||||||
@@ -110,7 +107,6 @@ var skipNoticeContentContainer: ContentContainer = () => ({
|
|||||||
unskipSponsorTime,
|
unskipSponsorTime,
|
||||||
sponsorTimes,
|
sponsorTimes,
|
||||||
sponsorTimesSubmitting,
|
sponsorTimesSubmitting,
|
||||||
hiddenSponsorTimes,
|
|
||||||
v: video,
|
v: video,
|
||||||
sponsorVideoID,
|
sponsorVideoID,
|
||||||
reskipSponsorTime,
|
reskipSponsorTime,
|
||||||
@@ -143,8 +139,7 @@ function messageListener(request: any, sender: any, sendResponse: (response: any
|
|||||||
//send the sponsor times along with if it's found
|
//send the sponsor times along with if it's found
|
||||||
sendResponse({
|
sendResponse({
|
||||||
found: sponsorDataFound,
|
found: sponsorDataFound,
|
||||||
sponsorTimes: sponsorTimes,
|
sponsorTimes: sponsorTimes
|
||||||
hiddenSponsorTimes: hiddenSponsorTimes
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
|
if (popupInitialised && document.getElementById("sponsorBlockPopupContainer") != null) {
|
||||||
@@ -287,9 +282,6 @@ async function videoIDChange(id) {
|
|||||||
//if the id has not changed return
|
//if the id has not changed return
|
||||||
if (sponsorVideoID === id) return;
|
if (sponsorVideoID === id) return;
|
||||||
|
|
||||||
// Reset hidden times (only do this when the ID has changed)
|
|
||||||
hiddenSponsorTimes = [];
|
|
||||||
|
|
||||||
//set the global videoID
|
//set the global videoID
|
||||||
sponsorVideoID = id;
|
sponsorVideoID = id;
|
||||||
|
|
||||||
@@ -640,17 +632,13 @@ function sponsorsLookup(id: string, channelIDPromise?) {
|
|||||||
|
|
||||||
sponsorTimes = recievedSegments;
|
sponsorTimes = recievedSegments;
|
||||||
|
|
||||||
// Remove all submissions smaller than the minimum duration
|
// Hide all submissions smaller than the minimum duration
|
||||||
if (Config.config.minDuration !== 0) {
|
if (Config.config.minDuration !== 0) {
|
||||||
let smallSegments: SponsorTime[] = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
if (sponsorTimes[i].segment[1] - sponsorTimes[i].segment[0] >= Config.config.minDuration) {
|
if (sponsorTimes[i].segment[1] - sponsorTimes[i].segment[0] < Config.config.minDuration) {
|
||||||
smallSegments.push(sponsorTimes[i]);
|
sponsorTimes[i].hidden = SponsorHideType.MinimumDuration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sponsorTimes = smallSegments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!switchingVideos) {
|
if (!switchingVideos) {
|
||||||
@@ -838,7 +826,7 @@ function updatePreviewBar() {
|
|||||||
//create an array of the sponsor types
|
//create an array of the sponsor types
|
||||||
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 (localSponsorTimes[i].hidden === SponsorHideType.Visible) {
|
||||||
types.push(localSponsorTimes[i].category);
|
types.push(localSponsorTimes[i].category);
|
||||||
} else {
|
} else {
|
||||||
// Don't show this sponsor
|
// Don't show this sponsor
|
||||||
@@ -927,7 +915,7 @@ function getLatestEndTimeIndex(sponsorTimes: SponsorTime[], index: number, hideH
|
|||||||
let latestEndTime = sponsorTimes[latestEndTimeIndex].segment[1];
|
let latestEndTime = sponsorTimes[latestEndTimeIndex].segment[1];
|
||||||
|
|
||||||
if (currentSegment[0] <= latestEndTime && currentSegment[1] > latestEndTime
|
if (currentSegment[0] <= latestEndTime && currentSegment[1] > latestEndTime
|
||||||
&& (!hideHiddenSponsors || !hiddenSponsorTimes.includes(i))
|
&& (!hideHiddenSponsors || sponsorTimes[i].hidden === SponsorHideType.Visible)
|
||||||
&& utils.getCategorySelection(sponsorTimes[i].category).option === CategorySkipOption.AutoSkip) {
|
&& utils.getCategorySelection(sponsorTimes[i].category).option === CategorySkipOption.AutoSkip) {
|
||||||
// Overlapping segment
|
// Overlapping segment
|
||||||
latestEndTimeIndex = i;
|
latestEndTimeIndex = i;
|
||||||
@@ -961,7 +949,7 @@ function getStartTimes(sponsorTimes: SponsorTime[], includeIntersectingSegments:
|
|||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
if ((minimum === undefined || (sponsorTimes[i].segment[0] >= minimum || (includeIntersectingSegments && sponsorTimes[i].segment[1] > minimum)))
|
if ((minimum === undefined || (sponsorTimes[i].segment[0] >= minimum || (includeIntersectingSegments && sponsorTimes[i].segment[1] > minimum)))
|
||||||
&& (!onlySkippableSponsors || utils.getCategorySelection(sponsorTimes[i].category).option !== CategorySkipOption.ShowOverlay)
|
&& (!onlySkippableSponsors || utils.getCategorySelection(sponsorTimes[i].category).option !== CategorySkipOption.ShowOverlay)
|
||||||
&& (!hideHiddenSponsors || !hiddenSponsorTimes.includes(i))) {
|
&& (!hideHiddenSponsors || sponsorTimes[i].hidden === SponsorHideType.Visible)) {
|
||||||
|
|
||||||
startTimes.push(sponsorTimes[i].segment[0]);
|
startTimes.push(sponsorTimes[i].segment[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/popup.ts
23
src/popup.ts
@@ -1,7 +1,7 @@
|
|||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
|
||||||
import Utils from "./utils";
|
import Utils from "./utils";
|
||||||
import { SponsorTime } from "./types";
|
import { SponsorTime, SponsorHideType } from "./types";
|
||||||
var utils = new Utils();
|
var utils = new Utils();
|
||||||
|
|
||||||
interface MessageListener {
|
interface MessageListener {
|
||||||
@@ -273,7 +273,7 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function infoFound(request: {found: boolean, sponsorTimes: SponsorTime[], hiddenSponsorTimes: number[]}) {
|
function infoFound(request: {found: boolean, sponsorTimes: SponsorTime[]}) {
|
||||||
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();
|
||||||
@@ -364,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: {found: boolean, sponsorTimes: SponsorTime[], hiddenSponsorTimes: number[]}) {
|
function displayDownloadedSponsorTimes(request: {found: boolean, sponsorTimes: SponsorTime[]}) {
|
||||||
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")) {
|
||||||
@@ -378,9 +378,12 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
sponsorTimeButton.className = "warningButton popupElement";
|
sponsorTimeButton.className = "warningButton popupElement";
|
||||||
|
|
||||||
let extraInfo = "";
|
let extraInfo = "";
|
||||||
if (request.hiddenSponsorTimes.includes(i)) {
|
if (request.sponsorTimes[i].hidden === SponsorHideType.Downvoted) {
|
||||||
//this one is hidden
|
//this one is downvoted
|
||||||
extraInfo = " (hidden)";
|
extraInfo = " (" + chrome.i18n.getMessage("hiddenDueToDownvote") + ")";
|
||||||
|
} else if (request.sponsorTimes[i].hidden === SponsorHideType.MinimumDuration) {
|
||||||
|
//this one is too short
|
||||||
|
extraInfo = " (" + chrome.i18n.getMessage("hiddenDueToDuration") + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
sponsorTimeButton.innerText = getFormattedTime(request.sponsorTimes[i].segment[0]) + " to " + getFormattedTime(request.sponsorTimes[i].segment[1]) + extraInfo;
|
sponsorTimeButton.innerText = getFormattedTime(request.sponsorTimes[i].segment[0]) + " to " + getFormattedTime(request.sponsorTimes[i].segment[1]) + extraInfo;
|
||||||
@@ -445,6 +448,14 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||||||
timeMessage = ", " + timeMessage;
|
timeMessage = ", " + timeMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sponsorTimes[i].hidden === SponsorHideType.Downvoted) {
|
||||||
|
//this one is downvoted
|
||||||
|
timeMessage += " (" + chrome.i18n.getMessage("hiddenDueToDownvote") + ")";
|
||||||
|
} else if (sponsorTimes[i].hidden === SponsorHideType.MinimumDuration) {
|
||||||
|
//this one is too short
|
||||||
|
timeMessage += " (" + chrome.i18n.getMessage("hiddenDueToDuration") + ")";
|
||||||
|
}
|
||||||
|
|
||||||
sponsorTimesMessage += timeMessage;
|
sponsorTimesMessage += timeMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/types.ts
12
src/types.ts
@@ -8,7 +8,6 @@ interface ContentContainer {
|
|||||||
unskipSponsorTime: (UUID: any) => void,
|
unskipSponsorTime: (UUID: any) => void,
|
||||||
sponsorTimes: SponsorTime[],
|
sponsorTimes: SponsorTime[],
|
||||||
sponsorTimesSubmitting: SponsorTime[],
|
sponsorTimesSubmitting: SponsorTime[],
|
||||||
hiddenSponsorTimes: number[],
|
|
||||||
v: HTMLVideoElement,
|
v: HTMLVideoElement,
|
||||||
sponsorVideoID,
|
sponsorVideoID,
|
||||||
reskipSponsorTime: (UUID: any) => void,
|
reskipSponsorTime: (UUID: any) => void,
|
||||||
@@ -36,11 +35,19 @@ interface CategorySelection {
|
|||||||
option: CategorySkipOption
|
option: CategorySkipOption
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SponsorHideType {
|
||||||
|
Visible = undefined,
|
||||||
|
Downvoted = 1,
|
||||||
|
MinimumDuration
|
||||||
|
}
|
||||||
|
|
||||||
interface SponsorTime {
|
interface SponsorTime {
|
||||||
segment: number[];
|
segment: number[];
|
||||||
UUID: string;
|
UUID: string;
|
||||||
|
|
||||||
category: string;
|
category: string;
|
||||||
|
|
||||||
|
hidden?: SponsorHideType;
|
||||||
}
|
}
|
||||||
|
|
||||||
type VideoID = string;
|
type VideoID = string;
|
||||||
@@ -51,5 +58,6 @@ export {
|
|||||||
CategorySelection,
|
CategorySelection,
|
||||||
CategorySkipOption,
|
CategorySkipOption,
|
||||||
SponsorTime,
|
SponsorTime,
|
||||||
VideoID
|
VideoID,
|
||||||
|
SponsorHideType
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user