mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-04-03 03:28:28 +03:00
more implementation
This commit is contained in:
@@ -32,7 +32,7 @@ chrome.tabs.onUpdated.addListener(function(tabId) {
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||
switch(request.message) {
|
||||
case "openConfig":
|
||||
chrome.tabs.create({url: chrome.runtime.getURL('options/options.html' + (request.hash ? '#' + request.hash : ''))});
|
||||
chrome.tabs.create({url: chrome.runtime.getURL('options/lock-options.html' + (request.hash ? '#' + request.hash : ''))});
|
||||
return;
|
||||
case "openHelp":
|
||||
chrome.tabs.create({url: chrome.runtime.getURL('help/index.html')});
|
||||
|
||||
@@ -152,12 +152,6 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
noticeStyle.transform = "scale(0.8) translate(10%, 10%)";
|
||||
}
|
||||
|
||||
// If it started out as smaller, always keep the
|
||||
// skip button there
|
||||
const firstColumn = this.props.smaller ? (
|
||||
this.getSkipButton()
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<NoticeComponent noticeTitle={this.state.noticeTitle}
|
||||
amountOfPreviousNotices={this.amountOfPreviousNotices}
|
||||
@@ -174,8 +168,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
closeListener={() => this.closeListener()}
|
||||
smaller={this.state.smaller}
|
||||
limitWidth={true}
|
||||
firstColumn={firstColumn}
|
||||
bottomRow={[...this.getMessageBoxes(), ...this.getBottomRow() ]}
|
||||
bottomRow={[...this.getMessageBoxes()]}
|
||||
onMouseEnter={() => this.onMouseEnter() } >
|
||||
</NoticeComponent>
|
||||
);
|
||||
@@ -388,11 +381,11 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||
}
|
||||
|
||||
onMouseEnter(): void {
|
||||
if (this.state.smaller) {
|
||||
this.setState({
|
||||
smaller: false
|
||||
});
|
||||
}
|
||||
// if (this.state.smaller) {
|
||||
// this.setState({
|
||||
// smaller: false
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
getMessageBoxes(): JSX.Element[] {
|
||||
|
||||
100
src/config.ts
100
src/config.ts
@@ -186,11 +186,11 @@ const Config: SBObject = {
|
||||
name: "sponsor" as Category,
|
||||
option: CategorySkipOption.AutoSkip
|
||||
}, {
|
||||
name: "poi_highlight" as Category,
|
||||
option: CategorySkipOption.ManualSkip
|
||||
name: "interaction" as Category,
|
||||
option: CategorySkipOption.AutoSkip
|
||||
}, {
|
||||
name: "exclusive_access" as Category,
|
||||
option: CategorySkipOption.ShowOverlay
|
||||
name: "selfpromo" as Category,
|
||||
option: CategorySkipOption.AutoSkip
|
||||
}],
|
||||
|
||||
colorPalette: {
|
||||
@@ -396,97 +396,7 @@ async function fetchConfig(): Promise<void> {
|
||||
}
|
||||
|
||||
function migrateOldSyncFormats(config: SBConfig) {
|
||||
if (config["segmentTimes"]) {
|
||||
const unsubmittedSegments = {};
|
||||
for (const item of config["segmentTimes"]) {
|
||||
unsubmittedSegments[item[0]] = item[1];
|
||||
}
|
||||
|
||||
chrome.storage.sync.remove("segmentTimes", () => config.unsubmittedSegments = unsubmittedSegments);
|
||||
}
|
||||
|
||||
if (!config["exclusive_accessCategoryAdded"] && !config.categorySelections.some((s) => s.name === "exclusive_access")) {
|
||||
config["exclusive_accessCategoryAdded"] = true;
|
||||
|
||||
config.categorySelections.push({
|
||||
name: "exclusive_access" as Category,
|
||||
option: CategorySkipOption.ShowOverlay
|
||||
});
|
||||
|
||||
config.categorySelections = config.categorySelections;
|
||||
}
|
||||
|
||||
if (config["fillerUpdate"] !== undefined) {
|
||||
chrome.storage.sync.remove("fillerUpdate");
|
||||
}
|
||||
if (config["highlightCategoryAdded"] !== undefined) {
|
||||
chrome.storage.sync.remove("highlightCategoryAdded");
|
||||
}
|
||||
if (config["highlightCategoryUpdate"] !== undefined) {
|
||||
chrome.storage.sync.remove("highlightCategoryUpdate");
|
||||
}
|
||||
|
||||
if (config["askAboutUnlistedVideos"]) {
|
||||
chrome.storage.sync.remove("askAboutUnlistedVideos");
|
||||
}
|
||||
|
||||
if (!config["autoSkipOnMusicVideosUpdate"]) {
|
||||
config["autoSkipOnMusicVideosUpdate"] = true;
|
||||
for (const selection of config.categorySelections) {
|
||||
if (selection.name === "music_offtopic"
|
||||
&& selection.option === CategorySkipOption.AutoSkip) {
|
||||
|
||||
config.autoSkipOnMusicVideos = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config["disableAutoSkip"]) {
|
||||
for (const selection of config.categorySelections) {
|
||||
if (selection.name === "sponsor") {
|
||||
selection.option = CategorySkipOption.ManualSkip;
|
||||
|
||||
chrome.storage.sync.remove("disableAutoSkip");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof config["skipKeybind"] == "string") {
|
||||
config["skipKeybind"] = {key: config["skipKeybind"]};
|
||||
}
|
||||
|
||||
if (typeof config["startSponsorKeybind"] == "string") {
|
||||
config["startSponsorKeybind"] = {key: config["startSponsorKeybind"]};
|
||||
}
|
||||
|
||||
if (typeof config["submitKeybind"] == "string") {
|
||||
config["submitKeybind"] = {key: config["submitKeybind"]};
|
||||
}
|
||||
|
||||
// Unbind key if it matches a previous one set by the user (should be ordered oldest to newest)
|
||||
const keybinds = ["skipKeybind", "startSponsorKeybind", "submitKeybind"];
|
||||
for (let i = keybinds.length-1; i >= 0; i--) {
|
||||
for (let j = 0; j < keybinds.length; j++) {
|
||||
if (i == j)
|
||||
continue;
|
||||
if (keybindEquals(config[keybinds[i]], config[keybinds[j]]))
|
||||
config[keybinds[i]] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove some old unused options
|
||||
if (config["sponsorVideoID"] !== undefined) {
|
||||
chrome.storage.sync.remove("sponsorVideoID");
|
||||
}
|
||||
if (config["previousVideoID"] !== undefined) {
|
||||
chrome.storage.sync.remove("previousVideoID");
|
||||
}
|
||||
|
||||
// populate invidiousInstances with new instances if 3p support is **DISABLED**
|
||||
if (!config["supportInvidious"] && config["invidiousInstances"].length !== invidiousList.length) {
|
||||
config["invidiousInstances"] = invidiousList;
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
async function setupConfig() {
|
||||
|
||||
@@ -442,7 +442,7 @@ function cancelSponsorSchedule(): void {
|
||||
/**
|
||||
* @param currentTime Optional if you don't want to use the actual current time
|
||||
*/
|
||||
function startSponsorSchedule(includeIntersectingSegments = false, currentTime?: number, includeNonIntersectingSegments = true): void {
|
||||
function startSponsorSchedule(includeIntersectingSegments = true, currentTime?: number, includeNonIntersectingSegments = true): void {
|
||||
cancelSponsorSchedule();
|
||||
|
||||
// Don't skip if advert playing and reset last checked time
|
||||
@@ -807,42 +807,20 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
|
||||
|
||||
cursor = Math.max(cursor, time.segment[1]);
|
||||
}
|
||||
|
||||
if (cursor < video.duration) {
|
||||
newTimes.push({
|
||||
segment: [cursor, video.duration],
|
||||
source: SponsorSourceType.Local,
|
||||
actionType: ActionType.Skip,
|
||||
category: "sponsor" as Category,
|
||||
UUID: null
|
||||
});
|
||||
}
|
||||
|
||||
sponsorTimes = newTimes;
|
||||
}
|
||||
|
||||
// Hide all submissions smaller than the minimum duration
|
||||
if (Config.config.minDuration !== 0) {
|
||||
for (const segment of sponsorTimes) {
|
||||
const duration = segment.segment[1] - segment.segment[0];
|
||||
if (duration > 0 && duration < Config.config.minDuration) {
|
||||
segment.hidden = SponsorHideType.MinimumDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (keepOldSubmissions) {
|
||||
for (const segment of oldSegments) {
|
||||
const otherSegment = sponsorTimes.find((other) => segment.UUID === other.UUID);
|
||||
if (otherSegment) {
|
||||
// If they downvoted it, or changed the category, keep it
|
||||
otherSegment.hidden = segment.hidden;
|
||||
otherSegment.category = segment.category;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// See if some segments should be hidden
|
||||
const downvotedData = Config.local.downvotedSegments[hashPrefix];
|
||||
if (downvotedData) {
|
||||
for (const segment of sponsorTimes) {
|
||||
const hashedUUID = await utils.getHash(segment.UUID, 1);
|
||||
const segmentDownvoteData = downvotedData.segments.find((downvote) => downvote.uuid === hashedUUID);
|
||||
if (segmentDownvoteData) {
|
||||
segment.hidden = segmentDownvoteData.hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startSkipScheduleCheckingForStartSponsors();
|
||||
|
||||
//update the preview bar
|
||||
@@ -860,14 +838,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
|
||||
}
|
||||
|
||||
function getEnabledActionTypes(): ActionType[] {
|
||||
const actionTypes = [ActionType.Skip, ActionType.Poi];
|
||||
if (Config.config.muteSegments) {
|
||||
actionTypes.push(ActionType.Mute);
|
||||
}
|
||||
if (Config.config.fullVideoSegments) {
|
||||
actionTypes.push(ActionType.Full);
|
||||
}
|
||||
|
||||
const actionTypes = [ActionType.Skip, ActionType.Mute];
|
||||
return actionTypes;
|
||||
}
|
||||
|
||||
@@ -1521,40 +1492,6 @@ async function updateVisibilityOfPlayerControlsButton(): Promise<void> {
|
||||
function updateEditButtonsOnPlayer(): void {
|
||||
// Don't try to update the buttons if we aren't on a YouTube video page
|
||||
if (!sponsorVideoID || onMobileYouTube) return;
|
||||
|
||||
const buttonsEnabled = !Config.config.hideVideoPlayerControls && !onInvidious;
|
||||
|
||||
let creatingSegment = false;
|
||||
let submitButtonVisible = false;
|
||||
let deleteButtonVisible = false;
|
||||
|
||||
// Only check if buttons should be visible if they're enabled
|
||||
if (buttonsEnabled) {
|
||||
creatingSegment = isSegmentCreationInProgress();
|
||||
|
||||
// Show only if there are any segments to submit
|
||||
submitButtonVisible = sponsorTimesSubmitting.length > 0;
|
||||
|
||||
// Show only if there are any segments to delete
|
||||
deleteButtonVisible = sponsorTimesSubmitting.length > 1 || (sponsorTimesSubmitting.length > 0 && !creatingSegment);
|
||||
}
|
||||
|
||||
// Update the elements
|
||||
playerButtons.startSegment.button.style.display = buttonsEnabled ? "unset" : "none";
|
||||
playerButtons.cancelSegment.button.style.display = buttonsEnabled && creatingSegment ? "unset" : "none";
|
||||
|
||||
if (buttonsEnabled) {
|
||||
if (creatingSegment) {
|
||||
playerButtons.startSegment.image.src = chrome.extension.getURL("icons/PlayerStopIconSponsorBlocker.svg");
|
||||
playerButtons.startSegment.button.setAttribute("title", chrome.i18n.getMessage("sponsorEnd"));
|
||||
} else {
|
||||
playerButtons.startSegment.image.src = chrome.extension.getURL("icons/PlayerStartIconSponsorBlocker.svg");
|
||||
playerButtons.startSegment.button.setAttribute("title", chrome.i18n.getMessage("sponsorStart"));
|
||||
}
|
||||
}
|
||||
|
||||
playerButtons.submit.button.style.display = submitButtonVisible && !Config.config.hideUploadButtonPlayerControls ? "unset" : "none";
|
||||
playerButtons.delete.button.style.display = deleteButtonVisible && !Config.config.hideDeleteButtonPlayerControls ? "unset" : "none";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1900,9 +1837,9 @@ function submitSponsorTimes() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) {
|
||||
submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage);
|
||||
}
|
||||
// if (sponsorTimesSubmitting !== undefined && sponsorTimesSubmitting.length > 0) {
|
||||
// submissionNotice = new SubmissionNotice(skipNoticeContentContainer, sendSubmitMessage);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -114,12 +114,6 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
"sbCloseDonate"
|
||||
].forEach(id => PageElements[id] = document.getElementById(id));
|
||||
|
||||
// Hide donate button if wanted (Safari, or user choice)
|
||||
if (!showDonationLink()) {
|
||||
PageElements.sbDonate.style.display = "none";
|
||||
}
|
||||
PageElements.sbDonate.addEventListener("click", () => Config.config.donateClicked = Config.config.donateClicked + 1);
|
||||
|
||||
//setup click listeners
|
||||
PageElements.sponsorStart.addEventListener("click", sendSponsorStartMessage);
|
||||
PageElements.whitelistToggle.addEventListener("change", function () {
|
||||
@@ -297,7 +291,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
if (request != undefined) {
|
||||
//remove loading text
|
||||
PageElements.mainControls.style.display = "flex";
|
||||
if (request.onMobileYouTube) PageElements.mainControls.classList.add("hidden");
|
||||
PageElements.mainControls.classList.add("hidden");
|
||||
PageElements.whitelistButton.classList.remove("hidden");
|
||||
PageElements.loadingIndicator.style.display = "none";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user