Skip to content

Commit

Permalink
Merge pull request #654 from SashaXser/main
Browse files Browse the repository at this point in the history
Небольшие правки
  • Loading branch information
ilyhalight authored Jun 8, 2024
2 parents f65a4c8 + 300c780 commit 096a212
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 152 deletions.
2 changes: 1 addition & 1 deletion dist/vot-cloudflare-min.user.js

Large diffs are not rendered by default.

97 changes: 47 additions & 50 deletions dist/vot-cloudflare.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,39 +1498,34 @@ function initHls() {
: undefined;
}

function cleanText(title, description) {
let cleanedDescription = "";

const deletefilter = [
/(?:https?|ftp):\/\/[\S]+/g,
/https?:\/\/\S+|www\.\S+/gm,
/\b\S+\.\S+/gm,
/#[^\s#]+/g,
/Auto-generated by YouTube/g,
/Provided to YouTube by/g,
/Released on/g,
/0x[a-fA-F0-9]{40}/g,
/[13][a-km-zA-HJ-NP-Z1-9]{25,34}/g,
/4[0-9AB][1-9A-HJ-NP-Za-km-z]{93}/g,
/Paypal/g,
];
const deletefilter = [
/(?:https?|ftp):\/\/[\S]+/g,
/https?:\/\/\S+|www\.\S+/gm,
/\b\S+\.\S+/gm,
/#[^\s#]+/g,
/Auto-generated by YouTube/g,
/Provided to YouTube by/g,
/Released on/g,
/0x[a-fA-F0-9]{40}/g,
/[13][a-km-zA-HJ-NP-Z1-9]{25,34}/g,
/4[0-9AB][1-9A-HJ-NP-Za-km-z]{93}/g,
/Paypal/g,
];

const combinedRegex = new RegExp(
deletefilter.map((regex) => regex.source).join("|"),
);
cleanedDescription = description
const combinedRegex = new RegExp(
deletefilter.map((regex) => regex.source).join("|"),
);

function cleanText(title, description) {
const cleanedDescription = description
? description
.split("\n")
.filter((line) => !combinedRegex.test(line))
.join("")
.join(" ")
: "";

return [title, cleanedDescription]
.join(" ")
.replace(/[^\p{L}\s]/gu, " ")
.trim()
.replace(/\s+/g, " ")
.slice(0, 450);
const fullText = `${title} ${cleanedDescription}`.slice(0, 450);
return fullText.replace(/[^\p{L}\s]+|\s+/gu, " ").trim();
}

async function GM_fetch(url, opt = {}) {
Expand Down Expand Up @@ -4482,6 +4477,7 @@ class EventImpl {




function filterVideoNodes(nodes) {
return Array.from(nodes).flatMap((node) => {
if (node instanceof HTMLVideoElement) {
Expand All @@ -4496,6 +4492,25 @@ function filterVideoNodes(nodes) {
});
}

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 isVideoReady(video) {
return video.readyState >= 3;
}
Expand Down Expand Up @@ -4578,6 +4593,10 @@ class VideoObserver {

handleIntersectingVideo(video) {
this.intersectionObserver.unobserve(video);
if (isAdVideo(video)) {
debug/* default */.A.log("The promotional video was ignored", video);
return;
}
waitForVideoReady(video, (readyVideo) => {
this.handleVideoAdded(readyVideo);
});
Expand All @@ -4589,6 +4608,7 @@ class VideoObserver {

handleVideoRemoved = (video) => {
if (!document.contains(video)) {
this.videoCache.delete(video);
this.onVideoRemoved.dispatch(video);
}
};
Expand Down Expand Up @@ -6806,24 +6826,6 @@ 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) {
Expand Down Expand Up @@ -6880,11 +6882,6 @@ async function src_main() {
let container = findContainer(site, video);
if (!container) continue;

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

if (site.host === "rumble" && !video.style.display) {
continue; // fix multiply translation buttons in rumble.com
}
Expand Down
2 changes: 1 addition & 1 deletion dist/vot-min.user.js

Large diffs are not rendered by default.

97 changes: 47 additions & 50 deletions dist/vot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1732,39 +1732,34 @@ function initHls() {
: undefined;
}

function cleanText(title, description) {
let cleanedDescription = "";

const deletefilter = [
/(?:https?|ftp):\/\/[\S]+/g,
/https?:\/\/\S+|www\.\S+/gm,
/\b\S+\.\S+/gm,
/#[^\s#]+/g,
/Auto-generated by YouTube/g,
/Provided to YouTube by/g,
/Released on/g,
/0x[a-fA-F0-9]{40}/g,
/[13][a-km-zA-HJ-NP-Z1-9]{25,34}/g,
/4[0-9AB][1-9A-HJ-NP-Za-km-z]{93}/g,
/Paypal/g,
];
const deletefilter = [
/(?:https?|ftp):\/\/[\S]+/g,
/https?:\/\/\S+|www\.\S+/gm,
/\b\S+\.\S+/gm,
/#[^\s#]+/g,
/Auto-generated by YouTube/g,
/Provided to YouTube by/g,
/Released on/g,
/0x[a-fA-F0-9]{40}/g,
/[13][a-km-zA-HJ-NP-Z1-9]{25,34}/g,
/4[0-9AB][1-9A-HJ-NP-Za-km-z]{93}/g,
/Paypal/g,
];

const combinedRegex = new RegExp(
deletefilter.map((regex) => regex.source).join("|"),
);
cleanedDescription = description
const combinedRegex = new RegExp(
deletefilter.map((regex) => regex.source).join("|"),
);

function cleanText(title, description) {
const cleanedDescription = description
? description
.split("\n")
.filter((line) => !combinedRegex.test(line))
.join("")
.join(" ")
: "";

return [title, cleanedDescription]
.join(" ")
.replace(/[^\p{L}\s]/gu, " ")
.trim()
.replace(/\s+/g, " ")
.slice(0, 450);
const fullText = `${title} ${cleanedDescription}`.slice(0, 450);
return fullText.replace(/[^\p{L}\s]+|\s+/gu, " ").trim();
}

async function GM_fetch(url, opt = {}) {
Expand Down Expand Up @@ -4381,6 +4376,7 @@ class EventImpl {




function filterVideoNodes(nodes) {
return Array.from(nodes).flatMap((node) => {
if (node instanceof HTMLVideoElement) {
Expand All @@ -4395,6 +4391,25 @@ function filterVideoNodes(nodes) {
});
}

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 isVideoReady(video) {
return video.readyState >= 3;
}
Expand Down Expand Up @@ -4477,6 +4492,10 @@ class VideoObserver {

handleIntersectingVideo(video) {
this.intersectionObserver.unobserve(video);
if (isAdVideo(video)) {
debug/* default */.A.log("The promotional video was ignored", video);
return;
}
waitForVideoReady(video, (readyVideo) => {
this.handleVideoAdded(readyVideo);
});
Expand All @@ -4488,6 +4507,7 @@ class VideoObserver {

handleVideoRemoved = (video) => {
if (!document.contains(video)) {
this.videoCache.delete(video);
this.onVideoRemoved.dispatch(video);
}
};
Expand Down Expand Up @@ -6686,24 +6706,6 @@ 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) {
Expand Down Expand Up @@ -6769,11 +6771,6 @@ async function src_main() {
let container = findContainer(site, video);
if (!container) continue;

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

if (site.host === "rumble" && !video.style.display) {
continue; // fix multiply translation buttons in rumble.com
}
Expand Down
23 changes: 0 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2233,24 +2233,6 @@ 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) {
Expand Down Expand Up @@ -2316,11 +2298,6 @@ async function main() {
let container = findContainer(site, video);
if (!container) continue;

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

if (site.host === "rumble" && !video.style.display) {
continue; // fix multiply translation buttons in rumble.com
}
Expand Down
25 changes: 25 additions & 0 deletions src/utils/VideoObserver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "requestidlecallback-polyfill";
import { EventImpl } from "./EventImpl.js";
import debug from "./debug.js";

function filterVideoNodes(nodes) {
return Array.from(nodes).flatMap((node) => {
Expand All @@ -15,6 +16,25 @@ function filterVideoNodes(nodes) {
});
}

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 isVideoReady(video) {
return video.readyState >= 3;
}
Expand Down Expand Up @@ -97,6 +117,10 @@ export class VideoObserver {

handleIntersectingVideo(video) {
this.intersectionObserver.unobserve(video);
if (isAdVideo(video)) {
debug.log("The promotional video was ignored", video);
return;
}
waitForVideoReady(video, (readyVideo) => {
this.handleVideoAdded(readyVideo);
});
Expand All @@ -108,6 +132,7 @@ export class VideoObserver {

handleVideoRemoved = (video) => {
if (!document.contains(video)) {
this.videoCache.delete(video);
this.onVideoRemoved.dispatch(video);
}
};
Expand Down
Loading

0 comments on commit 096a212

Please sign in to comment.