mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-29 13:50:50 +03:00
Merge pull request #1704 from mini-bomba/darkreader-proofing-the-dynamic-css
Darkreader-proofing the dynamic CSS variables
This commit is contained in:
@@ -265,7 +265,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
|||||||
utils.addHiddenSegment(getVideoID(), request.UUID, request.type);
|
utils.addHiddenSegment(getVideoID(), request.UUID, request.type);
|
||||||
updatePreviewBar();
|
updatePreviewBar();
|
||||||
|
|
||||||
if (skipButtonControlBar?.isEnabled()
|
if (skipButtonControlBar?.isEnabled()
|
||||||
&& sponsorTimesSubmitting.every((s) => s.hidden !== SponsorHideType.Visible || s.actionType !== ActionType.Poi)) {
|
&& sponsorTimesSubmitting.every((s) => s.hidden !== SponsorHideType.Visible || s.actionType !== ActionType.Poi)) {
|
||||||
skipButtonControlBar.disable();
|
skipButtonControlBar.disable();
|
||||||
}
|
}
|
||||||
@@ -679,7 +679,7 @@ async function startSponsorSchedule(includeIntersectingSegments = false, current
|
|||||||
const startIntervalTime = forceStartIntervalTime || performance.now();
|
const startIntervalTime = forceStartIntervalTime || performance.now();
|
||||||
const startVideoTime = Math.max(currentTime, getVideo().currentTime);
|
const startVideoTime = Math.max(currentTime, getVideo().currentTime);
|
||||||
delayTime = (skipTime?.[0] - startVideoTime) * 1000 * (1 / getVideo().playbackRate);
|
delayTime = (skipTime?.[0] - startVideoTime) * 1000 * (1 / getVideo().playbackRate);
|
||||||
|
|
||||||
let startWaitingForReportedTimeToChange = true;
|
let startWaitingForReportedTimeToChange = true;
|
||||||
const reportedVideoTimeAtStart = getVideo().currentTime;
|
const reportedVideoTimeAtStart = getVideo().currentTime;
|
||||||
logDebug(`Starting setInterval skipping ${getVideo().currentTime} to skip at ${skipTime[0]}`);
|
logDebug(`Starting setInterval skipping ${getVideo().currentTime} to skip at ${skipTime[0]}`);
|
||||||
@@ -687,7 +687,7 @@ async function startSponsorSchedule(includeIntersectingSegments = false, current
|
|||||||
currentSkipInterval = setInterval(() => {
|
currentSkipInterval = setInterval(() => {
|
||||||
// Estimate delay, but only take the current time right after a change
|
// Estimate delay, but only take the current time right after a change
|
||||||
// Current time remains the same for many "frames" on Firefox
|
// Current time remains the same for many "frames" on Firefox
|
||||||
if (utils.isFirefox() && !lastKnownVideoTime.fromPause && startWaitingForReportedTimeToChange
|
if (utils.isFirefox() && !lastKnownVideoTime.fromPause && startWaitingForReportedTimeToChange
|
||||||
&& reportedVideoTimeAtStart !== getVideo().currentTime) {
|
&& reportedVideoTimeAtStart !== getVideo().currentTime) {
|
||||||
startWaitingForReportedTimeToChange = false;
|
startWaitingForReportedTimeToChange = false;
|
||||||
const delay = getVirtualTime() - getVideo().currentTime;
|
const delay = getVirtualTime() - getVideo().currentTime;
|
||||||
@@ -745,7 +745,7 @@ function getVirtualTime(): number {
|
|||||||
const virtualTime = lastTimeFromWaitingEvent ?? (lastKnownVideoTime.videoTime !== null ?
|
const virtualTime = lastTimeFromWaitingEvent ?? (lastKnownVideoTime.videoTime !== null ?
|
||||||
(performance.now() - lastKnownVideoTime.preciseTime) * getVideo().playbackRate / 1000 + lastKnownVideoTime.videoTime : null);
|
(performance.now() - lastKnownVideoTime.preciseTime) * getVideo().playbackRate / 1000 + lastKnownVideoTime.videoTime : null);
|
||||||
|
|
||||||
if (Config.config.useVirtualTime && !isSafari() && virtualTime
|
if (Config.config.useVirtualTime && !isSafari() && virtualTime
|
||||||
&& Math.abs(virtualTime - getVideo().currentTime) < 0.2 && getVideo().currentTime !== 0) {
|
&& Math.abs(virtualTime - getVideo().currentTime) < 0.2 && getVideo().currentTime !== 0) {
|
||||||
return Math.max(virtualTime, getVideo().currentTime);
|
return Math.max(virtualTime, getVideo().currentTime);
|
||||||
} else {
|
} else {
|
||||||
@@ -928,7 +928,7 @@ function updateVirtualTime() {
|
|||||||
const frameTime = performance.now() - lastPerformanceTime;
|
const frameTime = performance.now() - lastPerformanceTime;
|
||||||
if (lastTime !== getVideo().currentTime) {
|
if (lastTime !== getVideo().currentTime) {
|
||||||
rawCount++;
|
rawCount++;
|
||||||
|
|
||||||
// If there is lag, give it another shot at finding a good change time
|
// If there is lag, give it another shot at finding a good change time
|
||||||
if (frameTime < 20 || rawCount > 30) {
|
if (frameTime < 20 || rawCount > 30) {
|
||||||
count++;
|
count++;
|
||||||
@@ -937,12 +937,12 @@ function updateVirtualTime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
const delay = lastKnownVideoTime.fromPause && lastKnownVideoTime.approximateDelay ?
|
const delay = lastKnownVideoTime.fromPause && lastKnownVideoTime.approximateDelay ?
|
||||||
lastKnownVideoTime.approximateDelay : 0;
|
lastKnownVideoTime.approximateDelay : 0;
|
||||||
|
|
||||||
lastKnownVideoTime.videoTime = getVideo().currentTime + delay;
|
lastKnownVideoTime.videoTime = getVideo().currentTime + delay;
|
||||||
lastKnownVideoTime.preciseTime = performance.now();
|
lastKnownVideoTime.preciseTime = performance.now();
|
||||||
|
|
||||||
clearInterval(currentVirtualTimeInterval);
|
clearInterval(currentVirtualTimeInterval);
|
||||||
currentVirtualTimeInterval = null;
|
currentVirtualTimeInterval = null;
|
||||||
}
|
}
|
||||||
@@ -1028,7 +1028,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
|||||||
?.sort((a, b) => a.segment[0] - b.segment[0]);
|
?.sort((a, b) => a.segment[0] - b.segment[0]);
|
||||||
if (recievedSegments && recievedSegments.length) {
|
if (recievedSegments && recievedSegments.length) {
|
||||||
sponsorDataFound = true;
|
sponsorDataFound = true;
|
||||||
|
|
||||||
// Check if any old submissions should be kept
|
// Check if any old submissions should be kept
|
||||||
if (sponsorTimes !== null && keepOldSubmissions) {
|
if (sponsorTimes !== null && keepOldSubmissions) {
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
@@ -1038,11 +1038,11 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldSegments = sponsorTimes || [];
|
const oldSegments = sponsorTimes || [];
|
||||||
sponsorTimes = recievedSegments;
|
sponsorTimes = recievedSegments;
|
||||||
existingChaptersImported = false;
|
existingChaptersImported = false;
|
||||||
|
|
||||||
// Hide 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) {
|
||||||
for (const segment of sponsorTimes) {
|
for (const segment of sponsorTimes) {
|
||||||
@@ -1052,7 +1052,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keepOldSubmissions) {
|
if (keepOldSubmissions) {
|
||||||
for (const segment of oldSegments) {
|
for (const segment of oldSegments) {
|
||||||
const otherSegment = sponsorTimes.find((other) => segment.UUID === other.UUID);
|
const otherSegment = sponsorTimes.find((other) => segment.UUID === other.UUID);
|
||||||
@@ -1063,7 +1063,7 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if some segments should be hidden
|
// See if some segments should be hidden
|
||||||
const downvotedData = Config.local.downvotedSegments[hashPrefix];
|
const downvotedData = Config.local.downvotedSegments[hashPrefix];
|
||||||
if (downvotedData) {
|
if (downvotedData) {
|
||||||
@@ -1075,9 +1075,9 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
startSkipScheduleCheckingForStartSponsors();
|
startSkipScheduleCheckingForStartSponsors();
|
||||||
|
|
||||||
//update the preview bar
|
//update the preview bar
|
||||||
//leave the type blank for now until categories are added
|
//leave the type blank for now until categories are added
|
||||||
if (lastPreviewBarUpdate == getVideoID() || (lastPreviewBarUpdate == null && !isNaN(getVideo().duration))) {
|
if (lastPreviewBarUpdate == getVideoID() || (lastPreviewBarUpdate == null && !isNaN(getVideo().duration))) {
|
||||||
@@ -1212,7 +1212,7 @@ function startSkipScheduleCheckingForStartSponsors() {
|
|||||||
|
|
||||||
// For highlight category
|
// For highlight category
|
||||||
const poiSegments = sponsorTimes
|
const poiSegments = sponsorTimes
|
||||||
.filter((time) => time.segment[1] > getVideo().currentTime
|
.filter((time) => time.segment[1] > getVideo().currentTime
|
||||||
&& time.actionType === ActionType.Poi && time.hidden === SponsorHideType.Visible)
|
&& time.actionType === ActionType.Poi && time.hidden === SponsorHideType.Visible)
|
||||||
.sort((a, b) => b.segment[0] - a.segment[0]);
|
.sort((a, b) => b.segment[0] - a.segment[0]);
|
||||||
for (const time of poiSegments) {
|
for (const time of poiSegments) {
|
||||||
@@ -1461,7 +1461,7 @@ function getStartTimes(sponsorTimes: SponsorTime[], includeIntersectingSegments:
|
|||||||
|
|
||||||
const shouldIncludeTime = (segment: ScheduledTime ) => (minimum === undefined
|
const shouldIncludeTime = (segment: ScheduledTime ) => (minimum === undefined
|
||||||
|| ((includeNonIntersectingSegments && segment.scheduledTime >= minimum)
|
|| ((includeNonIntersectingSegments && segment.scheduledTime >= minimum)
|
||||||
|| (includeIntersectingSegments && segment.scheduledTime < minimum
|
|| (includeIntersectingSegments && segment.scheduledTime < minimum
|
||||||
&& segment.segment[1] > minimum && shouldSkip(segment)))) // Only include intersecting skippable segments
|
&& segment.segment[1] > minimum && shouldSkip(segment)))) // Only include intersecting skippable segments
|
||||||
&& (!hideHiddenSponsors || segment.hidden === SponsorHideType.Visible)
|
&& (!hideHiddenSponsors || segment.hidden === SponsorHideType.Visible)
|
||||||
&& segment.segment.length === 2
|
&& segment.segment.length === 2
|
||||||
@@ -1702,7 +1702,7 @@ function shouldSkip(segment: SponsorTime): boolean {
|
|||||||
return (segment.actionType !== ActionType.Full
|
return (segment.actionType !== ActionType.Full
|
||||||
&& segment.source !== SponsorSourceType.YouTube
|
&& segment.source !== SponsorSourceType.YouTube
|
||||||
&& utils.getCategorySelection(segment.category)?.option !== CategorySkipOption.ShowOverlay)
|
&& utils.getCategorySelection(segment.category)?.option !== CategorySkipOption.ShowOverlay)
|
||||||
|| (Config.config.autoSkipOnMusicVideos && sponsorTimes?.some((s) => s.category === "music_offtopic")
|
|| (Config.config.autoSkipOnMusicVideos && sponsorTimes?.some((s) => s.category === "music_offtopic")
|
||||||
&& segment.actionType === ActionType.Skip);
|
&& segment.actionType === ActionType.Skip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1834,7 +1834,7 @@ function startOrEndTimingNewSegment() {
|
|||||||
|
|
||||||
importExistingChapters(false);
|
importExistingChapters(false);
|
||||||
|
|
||||||
if (lastResponseStatus !== 200 && lastResponseStatus !== 404
|
if (lastResponseStatus !== 200 && lastResponseStatus !== 404
|
||||||
&& !shownSegmentFailedToFetchWarning && Config.config.showSegmentFailedToFetchWarning) {
|
&& !shownSegmentFailedToFetchWarning && Config.config.showSegmentFailedToFetchWarning) {
|
||||||
alert(chrome.i18n.getMessage("segmentFetchFailureWarning"));
|
alert(chrome.i18n.getMessage("segmentFetchFailureWarning"));
|
||||||
|
|
||||||
@@ -1937,7 +1937,7 @@ function openInfoMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parentNodeOptions = [{
|
const parentNodeOptions = [{
|
||||||
// YouTube
|
// YouTube
|
||||||
selector: "#secondary-inner",
|
selector: "#secondary-inner",
|
||||||
hasChildCheck: true
|
hasChildCheck: true
|
||||||
}, {
|
}, {
|
||||||
@@ -2445,11 +2445,13 @@ function setCategoryColorCSSVariables() {
|
|||||||
let css = ":root {"
|
let css = ":root {"
|
||||||
for (const [category, config] of Object.entries(Config.config.barTypes)) {
|
for (const [category, config] of Object.entries(Config.config.barTypes)) {
|
||||||
css += `--sb-category-${category}: ${config.color};`;
|
css += `--sb-category-${category}: ${config.color};`;
|
||||||
|
css += `--darkreader-bg--sb-category-${category}: ${config.color};`;
|
||||||
|
|
||||||
const luminance = GenericUtils.getLuminance(config.color);
|
const luminance = GenericUtils.getLuminance(config.color);
|
||||||
css += `--sb-category-text-${category}: ${luminance > 128 ? "black" : "white"};`;
|
css += `--sb-category-text-${category}: ${luminance > 128 ? "black" : "white"};`;
|
||||||
|
css += `--darkreader-text--sb-category-text-${category}: ${luminance > 128 ? "black" : "white"};`;
|
||||||
}
|
}
|
||||||
css += "}";
|
css += "}";
|
||||||
|
|
||||||
styleContainer.innerText = css;
|
styleContainer.innerText = css;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user