Skip to content

Commit

Permalink
Merge pull request #642 from SashaXser/main
Browse files Browse the repository at this point in the history
Исправление ошибок для #640
  • Loading branch information
ilyhalight authored May 29, 2024
2 parents 3f3c52e + db307a7 commit e865c63
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 170 deletions.
2 changes: 1 addition & 1 deletion dist/vot-cloudflare-min.user.js

Large diffs are not rendered by default.

139 changes: 83 additions & 56 deletions dist/vot-cloudflare.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4352,8 +4352,6 @@ class VideoObserver {
constructor() {
this.onVideoAdded = new EventImpl();
this.onVideoRemoved = new EventImpl();
this.handleVideoAddedBound = this.handleVideoAdded.bind(this);
this.handleVideoRemovedBound = this.handleVideoRemoved.bind(this);
this.observer = new MutationObserver((mutationsList) => {
window.requestIdleCallback(
() => {
Expand All @@ -4363,40 +4361,44 @@ class VideoObserver {

const addedNodes = filterVideoNodes(mutation.addedNodes);
for (let j = 0; j < addedNodes.length; j++) {
this.handleVideoAddedBound(addedNodes[j]);
this.handleVideoAdded(addedNodes[j]);
}

const removedNodes = filterVideoNodes(mutation.removedNodes);
for (let k = 0; k < removedNodes.length; k++) {
this.handleVideoRemovedBound(removedNodes[k]);
this.handleVideoRemoved(removedNodes[k]);
}
}
},
{ timeout: 1000 },
);
});
}

enable() {
this.observer.observe(document, {
childList: true,
subtree: true,
});
const videos = document.querySelectorAll("video");
for (let i = 0; i < videos.length; i++) {
this.handleVideoAddedBound(videos[i]);
this.handleVideoAdded(videos[i]);
}
}

disable() {
this.observer.disconnect();
}
handleVideoAdded(video) {

handleVideoAdded = (video) => {
this.onVideoAdded.dispatch(video);
}
handleVideoRemoved(video) {
};

handleVideoRemoved = (video) => {
if (!document.contains(video)) {
this.onVideoRemoved.dispatch(video);
}
}
};
}

// EXTERNAL MODULE: ./src/utils/storage.js
Expand Down Expand Up @@ -5773,7 +5775,10 @@ class VideoHandler {
});

addExtraEventListener(this.video, "emptied", () => {
if ((0,utils/* getVideoId */.jI)(this.site.host, this.video) === this.videoData.videoId)
if (
this.video.src &&
(0,utils/* getVideoId */.jI)(this.site.host, this.video) === this.videoData.videoId
)
return;
debug/* default */.A.log("lipsync mode is emptied");
this.videoData = "";
Expand Down Expand Up @@ -6591,6 +6596,59 @@ function getSites() {

const videoObserver = new VideoObserver();
const videosWrappers = new WeakMap();
const adKeywords =
/advertise|promo|sponsor|banner|commercial|preroll|midroll|postroll|ad-container|sponsored/i;

function isAdVideo(video) {
if (adKeywords.test(video.className) || adKeywords.test(video.title)) {
return true;
}

let parent = video.parentElement;
while (parent) {
if (adKeywords.test(parent.className) || adKeywords.test(parent.id)) {
return true;
}
parent = parent.parentElement;
}

return false;
}

function findContainer(site, video) {
if (site.shadowRoot) {
let container = site.selector
? Array.from(document.querySelectorAll(site.selector)).find((e) =>
e.shadowRoot.contains(video),
)
: video.parentElement;
return container && container.shadowRoot
? container.parentElement
: container;
} else {
const browserVersion = browserInfo.browser.version.split(".")[0];
if (
site.selector?.includes(":not") &&
site.selector?.includes("*") &&
browserVersion &&
((browserInfo.browser.name === "Chrome" && Number(browserVersion) < 88) ||
(browserInfo.browser.name === "Firefox" && Number(browserVersion) < 84))
) {
const selector = site.selector.split(" *")[0];
return selector
? Array.from(document.querySelectorAll(selector)).find((e) =>
e.contains(video),
)
: video.parentElement;
} else {
return site.selector
? Array.from(document.querySelectorAll(site.selector)).find((e) =>
e.contains(video),
)
: video.parentElement;
}
}
}

async function src_main() {
debug/* default */.A.log("Loading extension...");
Expand All @@ -6609,59 +6667,27 @@ async function src_main() {
for (const site of getSites()) {
if (!site) continue;

let container;
if (site.shadowRoot) {
container = site.selector
? Object.values(document.querySelectorAll(site.selector)).find((e) =>
e.shadowRoot.contains(video),
)
: video.parentElement;
container =
container && container.shadowRoot
? container.parentElement
: container;
} else {
const browserVersion = browserInfo.browser.version.split(".")?.[0];

if (
site.selector?.includes(":not") &&
site.selector?.includes("*") &&
browserVersion &&
((browserInfo.browser.name === "Chrome" &&
Number(browserVersion) < 88) ||
(browserInfo.browser.name === "Firefox" &&
Number(browserVersion) < 84))
) {
const selector = site.selector?.split(" *")?.[0];
container = selector
? Object.values(document.querySelectorAll(selector)).find((e) =>
e.contains(video),
)
: video.parentElement;
} else {
container = site.selector
? Object.values(document.querySelectorAll(site.selector)).find(
(e) => e.contains(video),
)
: video.parentElement;
}
}
let container = findContainer(site, video);
if (!container) continue;
if (site.host === "rumble" && container.querySelector("vot-block")) {
// fix multiply translation buttons in rumble.com

if (isAdVideo(video)) {
debug/* default */.A.log("The promotional video was ignored", video);
continue;
}

if (
site.host === "youku" &&
!video.parentElement?.classList?.contains("video-layer")
) {
continue;
if (site.host === "rumble" && !video.style.display) {
continue; // fix multiply translation buttons in rumble.com
}

// if (
// site.host === "youku" &&
// !video.parentElement?.classList.contains("video-layer")
// ) {
// continue;
// }

if (["peertube", "directlink"].includes(site.host)) {
// we set the url of the current site, since peertube doesn't have a main server
site.url = window.location.origin;
site.url = window.location.origin; // set the url of the current site for peertube and directlink
}

if (!videosWrappers.has(video)) {
Expand All @@ -6670,6 +6696,7 @@ async function src_main() {
}
}
});

videoObserver.onVideoRemoved.addListener(async (video) => {
if (videosWrappers.has(video)) {
await videosWrappers.get(video).release();
Expand Down
2 changes: 1 addition & 1 deletion dist/vot-min.user.js

Large diffs are not rendered by default.

Loading

0 comments on commit e865c63

Please sign in to comment.