mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 20:17:05 +03:00
Listen for class changes for ytp-hover-progress-light and fix left
This commit is contained in:
@@ -243,20 +243,26 @@ class PreviewBar {
|
|||||||
const sectionWidthDecimal = parseFloat(section.getAttribute("decimal-width"));
|
const sectionWidthDecimal = parseFloat(section.getAttribute("decimal-width"));
|
||||||
|
|
||||||
for (const className in changes) {
|
for (const className in changes) {
|
||||||
const currentChangedElement = section.querySelector(`.${className}`) as HTMLElement;
|
const customChangedElement = section.querySelector(`.${className}`) as HTMLElement;
|
||||||
if (currentChangedElement) {
|
if (customChangedElement) {
|
||||||
const currentChange = changes[className];
|
|
||||||
const changedElement = changes[className].target as HTMLElement;
|
const changedElement = changes[className].target as HTMLElement;
|
||||||
|
|
||||||
const left = parseFloat(changedElement.style.left.replace("px", "")) / progressBar.clientWidth;
|
const left = parseFloat(changedElement.style.left.replace("px", "")) / progressBar.clientWidth;
|
||||||
if (currentChange.attributeName === "style") {
|
const calculatedLeft = Math.max(0, Math.min(1, (left - cursor) / sectionWidthDecimal));
|
||||||
|
if (!isNaN(left) && !isNaN(calculatedLeft)) {
|
||||||
|
customChangedElement.style.left = `${calculatedLeft * 100}%`;
|
||||||
|
customChangedElement.style.removeProperty("display");
|
||||||
|
}
|
||||||
|
|
||||||
const transformMatch = changedElement.style.transform.match(/scaleX\(([0-9.]+?)\)/);
|
const transformMatch = changedElement.style.transform.match(/scaleX\(([0-9.]+?)\)/);
|
||||||
if (transformMatch) {
|
if (transformMatch) {
|
||||||
const transformScale = parseFloat(transformMatch[1]) + left;
|
const transformScale = parseFloat(transformMatch[1]) + left;
|
||||||
currentChangedElement.style.transform = `scaleX(${Math.max(0, Math.min(1, (transformScale - cursor) / sectionWidthDecimal))}`;
|
customChangedElement.style.transform =
|
||||||
}
|
`scaleX(${Math.max(0, Math.min(1 - calculatedLeft,
|
||||||
} else if (currentChange.attributeName === "left") {
|
(transformScale - cursor) / sectionWidthDecimal - calculatedLeft))}`;
|
||||||
currentChangedElement.style.left = `${Math.max(0, Math.min(1, (left - cursor) / sectionWidthDecimal)) * 100}%`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
customChangedElement.className = changedElement.className;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +274,7 @@ class PreviewBar {
|
|||||||
observer.observe(chapterBar, {
|
observer.observe(chapterBar, {
|
||||||
subtree: true,
|
subtree: true,
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeFilter: ["style", "left"]
|
attributeFilter: ["style", "class"],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create it from cloning
|
// Create it from cloning
|
||||||
|
|||||||
Reference in New Issue
Block a user