mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-19 05:58:37 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlock into chapters
This commit is contained in:
@@ -80,8 +80,6 @@ chrome.runtime.onInstalled.addListener(function () {
|
||||
const newUserID = utils.generateUserID();
|
||||
//save this UUID
|
||||
Config.config.userID = newUserID;
|
||||
|
||||
Config.config.highlightCategoryUpdate = true;
|
||||
}
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from "react";
|
||||
import * as CompileConfig from "../../config.json";
|
||||
import Config from "../config"
|
||||
import { Category, ContentContainer, CategoryActionType, SponsorHideType, SponsorTime, NoticeVisbilityMode, ActionType } from "../types";
|
||||
import { Category, ContentContainer, CategoryActionType, SponsorHideType, SponsorTime, NoticeVisbilityMode, ActionType, SponsorSourceType, SegmentUUID } from "../types";
|
||||
import NoticeComponent from "./NoticeComponent";
|
||||
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
||||
import SubmissionNotice from "../render/SubmissionNotice";
|
||||
@@ -534,10 +534,10 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
const sponsorVideoID = this.props.contentContainer().sponsorVideoID;
|
||||
const sponsorTimesSubmitting : SponsorTime = {
|
||||
segment: this.segments[index].segment,
|
||||
UUID: null,
|
||||
UUID: utils.generateUserID() as SegmentUUID,
|
||||
category: this.segments[index].category,
|
||||
actionType: this.segments[index].actionType,
|
||||
source: 2
|
||||
source: SponsorSourceType.Local
|
||||
};
|
||||
|
||||
const segmentTimes = Config.config.segmentTimes.get(sponsorVideoID) || [];
|
||||
|
||||
@@ -123,7 +123,7 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
|
||||
const timeRef = React.createRef<SponsorTimeEditComponent>();
|
||||
|
||||
elements.push(
|
||||
<SponsorTimeEditComponent key={i}
|
||||
<SponsorTimeEditComponent key={sponsorTimes[i].UUID}
|
||||
idSuffix={this.state.idSuffix + i}
|
||||
index={i}
|
||||
contentContainer={this.props.contentContainer}
|
||||
|
||||
@@ -45,13 +45,13 @@ interface SBConfig {
|
||||
showDonationLink: boolean,
|
||||
autoHideInfoButton: boolean,
|
||||
autoSkipOnMusicVideos: boolean,
|
||||
highlightCategoryUpdate: boolean,
|
||||
colorPalette: {
|
||||
red: string,
|
||||
white: string,
|
||||
locked: string
|
||||
},
|
||||
scrollToEditTimeUpdate: boolean,
|
||||
fillerUpdate: boolean,
|
||||
|
||||
// What categories should be skipped
|
||||
categorySelections: CategorySelection[],
|
||||
@@ -75,6 +75,8 @@ interface SBConfig {
|
||||
"preview-music_offtopic": PreviewBarOption,
|
||||
"poi_highlight": PreviewBarOption,
|
||||
"preview-poi_highlight": PreviewBarOption,
|
||||
"filler": PreviewBarOption,
|
||||
"preview-filler": PreviewBarOption,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,12 +202,15 @@ const Config: SBObject = {
|
||||
showDonationLink: true,
|
||||
autoHideInfoButton: true,
|
||||
autoSkipOnMusicVideos: false,
|
||||
highlightCategoryUpdate: false, // TODO: Remove this once update is done
|
||||
scrollToEditTimeUpdate: false, // false means the tooltip will be shown
|
||||
fillerUpdate: false,
|
||||
|
||||
categorySelections: [{
|
||||
name: "sponsor" as Category,
|
||||
option: CategorySkipOption.AutoSkip
|
||||
}, {
|
||||
name: "poi_highlight" as Category,
|
||||
option: CategorySkipOption.ManualSkip
|
||||
}],
|
||||
|
||||
colorPalette: {
|
||||
@@ -283,6 +288,14 @@ const Config: SBObject = {
|
||||
"preview-poi_highlight": {
|
||||
color: "#9b044c",
|
||||
opacity: "0.7"
|
||||
},
|
||||
"filler": {
|
||||
color: "#7300FF",
|
||||
opacity: "0.9"
|
||||
},
|
||||
"preview-filler": {
|
||||
color: "#2E0066",
|
||||
opacity: "0.7"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -379,16 +392,11 @@ function fetchConfig(): Promise<void> {
|
||||
}
|
||||
|
||||
function migrateOldFormats(config: SBConfig) {
|
||||
// Should eventually move into defaults
|
||||
if (!config["highlightCategoryAdded"] && !config.categorySelections.some((s) => s.name === "poi_highlight")) {
|
||||
config["highlightCategoryAdded"] = true;
|
||||
|
||||
config.categorySelections.push({
|
||||
name: "poi_highlight" as Category,
|
||||
option: CategorySkipOption.ManualSkip
|
||||
});
|
||||
|
||||
config.categorySelections = config.categorySelections;
|
||||
if (config["highlightCategoryAdded"] !== undefined) {
|
||||
chrome.storage.sync.remove("highlightCategoryAdded");
|
||||
}
|
||||
if (config["highlightCategoryUpdate"] !== undefined) {
|
||||
chrome.storage.sync.remove("highlightCategoryUpdate");
|
||||
}
|
||||
|
||||
if (config["askAboutUnlistedVideos"]) {
|
||||
|
||||
@@ -338,6 +338,26 @@ async function videoIDChange(id) {
|
||||
// Clear unsubmitted segments from the previous video
|
||||
sponsorTimesSubmitting = [];
|
||||
updateSponsorTimesSubmitting();
|
||||
|
||||
// Filler update
|
||||
if (!Config.config.fillerUpdate) {
|
||||
Config.config.fillerUpdate = true;
|
||||
|
||||
utils.wait(getControls).then(() => {
|
||||
const playButton = document.querySelector(".ytp-play-button") as HTMLElement;
|
||||
const allCategories = ["sponsor", "intro", "outro", "selfpromo", "interaction"];
|
||||
if (playButton && allCategories.every((name) => Config.config.categorySelections.some((selection) => selection.name === name))
|
||||
&& utils.getCategorySelection("filler") === undefined) {
|
||||
new Tooltip({
|
||||
text: chrome.i18n.getMessage("fillerNewFeature"),
|
||||
link: "https://wiki.sponsor.ajay.app/w/Filler_Tangent",
|
||||
referenceNode: playButton.parentElement,
|
||||
prependElement: playButton,
|
||||
timeout: 10
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleMobileControlsMutations(): void {
|
||||
@@ -1216,6 +1236,9 @@ function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, u
|
||||
// for some reason you also can't skip to 1 second before the end
|
||||
if (v.loop && v.duration > 1 && skipTime[1] >= v.duration - 1) {
|
||||
v.currentTime = 0;
|
||||
} else if (navigator.vendor === "Apple Computer, Inc." && v.duration > 1 && skipTime[1] >= v.duration) {
|
||||
// MacOS will loop otherwise #1027
|
||||
v.currentTime = v.duration - 0.001;
|
||||
} else {
|
||||
v.currentTime = skipTime[1];
|
||||
}
|
||||
@@ -1236,21 +1259,9 @@ function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, u
|
||||
if (!autoSkip
|
||||
&& skippingSegments.length === 1
|
||||
&& getCategoryActionType(skippingSegments[0].category) === CategoryActionType.POI) {
|
||||
skipButtonControlBar.enable(skippingSegments[0], !Config.config.highlightCategoryUpdate ? 15 : 0);
|
||||
skipButtonControlBar.enable(skippingSegments[0]);
|
||||
if (onMobileYouTube) skipButtonControlBar.setShowKeybindHint(false);
|
||||
|
||||
if (!Config.config.highlightCategoryUpdate) {
|
||||
new Tooltip({
|
||||
text: chrome.i18n.getMessage("highlightNewFeature"),
|
||||
link: "https://blog.ajay.app/highlight-sponsorblock",
|
||||
referenceNode: skipButtonControlBar.getElement().parentElement,
|
||||
prependElement: skipButtonControlBar.getElement(),
|
||||
timeout: 15
|
||||
});
|
||||
|
||||
Config.config.highlightCategoryUpdate = true;
|
||||
}
|
||||
|
||||
activeSkipKeybindElement?.setShowKeybindHint(false);
|
||||
activeSkipKeybindElement = skipButtonControlBar;
|
||||
} else {
|
||||
@@ -1448,7 +1459,7 @@ function startOrEndTimingNewSegment() {
|
||||
if (!isSegmentCreationInProgress()) {
|
||||
sponsorTimesSubmitting.push({
|
||||
segment: [roundedTime],
|
||||
UUID: null,
|
||||
UUID: utils.generateUserID() as SegmentUUID,
|
||||
category: Config.config.defaultCategory,
|
||||
actionType: ActionType.Skip,
|
||||
source: SponsorSourceType.Local
|
||||
@@ -1655,7 +1666,7 @@ function vote(type: number, UUID: SegmentUUID, category?: Category, skipNotice?:
|
||||
const sponsorIndex = utils.getSponsorIndexFromUUID(sponsorTimes, UUID);
|
||||
|
||||
// Don't vote for preview sponsors
|
||||
if (sponsorIndex == -1 || sponsorTimes[sponsorIndex].UUID === null) return;
|
||||
if (sponsorIndex == -1 || sponsorTimes[sponsorIndex].source === SponsorSourceType.Local) return;
|
||||
|
||||
// See if the local time saved count and skip count should be saved
|
||||
if (type === 0 && sponsorSkipped[sponsorIndex] || type === 1 && !sponsorSkipped[sponsorIndex]) {
|
||||
@@ -1785,6 +1796,7 @@ async function sendSubmitMessage() {
|
||||
if (recievedNewSegments?.length === newSegments.length) {
|
||||
for (let i = 0; i < recievedNewSegments.length; i++) {
|
||||
newSegments[i].UUID = recievedNewSegments[i].UUID;
|
||||
newSegments[i].source = SponsorSourceType.Server;
|
||||
}
|
||||
}
|
||||
} catch(e) {} // eslint-disable-line no-empty
|
||||
|
||||
@@ -226,10 +226,10 @@ class PreviewBar {
|
||||
if (!this.onMobileYouTube) bar.style.opacity = Config.config.barTypes[fullCategoryName]?.opacity;
|
||||
|
||||
bar.style.position = "absolute";
|
||||
const duration = segment[1] - segment[0];
|
||||
if (segment[1] - segment[0] > 0) bar.style.width = `calc(${this.timeToPercentage(segment[1] - segment[0])}${this.chapterFilter(barSegment) ? ' - 2px' : ''})`;
|
||||
const duration = Math.min(segment[1], this.videoDuration) - segment[0];
|
||||
if (duration > 0) bar.style.width = `calc(${this.timeToPercentage(segment[1] - segment[0])}${this.chapterFilter(barSegment) ? ' - 2px' : ''})`;
|
||||
|
||||
const time = segment[1] ? Math.min(this.videoDuration - Math.max(0, duration), segment[0]) : segment[0];
|
||||
const time = segment[1] ? Math.min(this.videoDuration, segment[0]) : segment[0];
|
||||
bar.style.left = this.timeToPercentage(time);
|
||||
|
||||
return bar;
|
||||
|
||||
@@ -79,7 +79,7 @@ export class SkipButtonControlBar {
|
||||
mountingContainer.insertBefore(this.container, this.chapterText);
|
||||
}
|
||||
|
||||
if (Config.config.autoHideInfoButton && !this.onMobileYouTube) {
|
||||
if (!this.onMobileYouTube) {
|
||||
utils.setupAutoHideAnimation(this.skipIcon, mountingContainer, false, false);
|
||||
} else {
|
||||
const { hide, show } = utils.setupCustomHideAnimation(this.skipIcon, mountingContainer, false, false);
|
||||
|
||||
@@ -512,15 +512,17 @@ function activatePrivateTextChange(element: HTMLElement) {
|
||||
// See if anything extra must be done
|
||||
switch (option) {
|
||||
case "userID":
|
||||
utils.asyncRequestToServer("GET", "/api/userInfo", {
|
||||
userID: Config.config[option],
|
||||
values: ["warnings", "banned"]
|
||||
}).then((result) => {
|
||||
const userInfo = JSON.parse(result.responseText);
|
||||
if (userInfo.warnings > 0 || userInfo.banned) {
|
||||
setButton.classList.add("hidden");
|
||||
}
|
||||
});
|
||||
if (Config.config[option]) {
|
||||
utils.asyncRequestToServer("GET", "/api/userInfo", {
|
||||
userID: Config.config[option],
|
||||
values: ["warnings", "banned"]
|
||||
}).then((result) => {
|
||||
const userInfo = JSON.parse(result.responseText);
|
||||
if (userInfo.warnings > 0 || userInfo.banned) {
|
||||
setButton.classList.add("hidden");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
11
src/popup.ts
11
src/popup.ts
@@ -816,16 +816,17 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts time in hours to 5h 25.1
|
||||
* Converts time in minutes to 2d 5h 25.1
|
||||
* If less than 1 hour, just returns minutes
|
||||
*
|
||||
* @param {float} seconds
|
||||
* @param {float} minutes
|
||||
* @returns {string}
|
||||
*/
|
||||
function getFormattedHours(minutes) {
|
||||
minutes = Math.round(minutes * 10) / 10
|
||||
const hours = Math.floor(minutes / 60);
|
||||
return (hours > 0 ? hours + "h " : "") + (minutes % 60).toFixed(1);
|
||||
minutes = Math.round(minutes * 10) / 10;
|
||||
const days = Math.floor(minutes / 3600);
|
||||
const hours = Math.floor(minutes / 60) % 24;
|
||||
return (days > 0 ? days + chrome.i18n.getMessage("dayAbbreviation") + " " : "") + (hours > 0 ? hours + chrome.i18n.getMessage("hourAbbreviation") + " " : "") + (minutes % 60).toFixed(1);
|
||||
}
|
||||
|
||||
//end of function
|
||||
|
||||
Reference in New Issue
Block a user