Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExp.exec() > String.match() #686

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/vot-cloudflare-min.user.js

Large diffs are not rendered by default.

66 changes: 32 additions & 34 deletions dist/vot-cloudflare.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,14 +1226,12 @@ const getVideoId = (service, video) => {
}

return (
url.pathname.match(/(?:watch|embed|shorts|live)\/([^/]+)/)?.[1] ||
/(?:watch|embed|shorts|live)\/([^/]+)/.exec(url.pathname)?.[1] ||
url.searchParams.get("v")
);
}
case "vk": {
const pathID = url.pathname.match(
/^\/(video|clip)-?[0-9]{8,9}_[0-9]{9}$/,
);
const pathID = /^\/(video|clip)-?[0-9]{8,9}_[0-9]{9}$/.exec(url.pathname);
const paramZ = url.searchParams.get("z");
const paramOID = url.searchParams.get("oid");
const paramID = url.searchParams.get("id");
Expand All @@ -1250,11 +1248,11 @@ const getVideoId = (service, video) => {
case "nine_gag":
case "9gag":
case "gag":
return url.pathname.match(/gag\/([^/]+)/)?.[1];
return /gag\/([^/]+)/.exec(url.pathname)?.[1];
case "twitch": {
const clipPath = url.pathname.match(/([^/]+)\/(?:clip)\/([^/]+)/);
const clipPath = /([^/]+)\/(?:clip)\/([^/]+)/.exec(url.pathname);
if (/^m\.twitch\.tv$/.test(url.hostname)) {
return url.href.match(/videos\/([^/]+)/)?.[0] || url.pathname.slice(1);
return /videos\/([^/]+)/.exec(url.href)?.[0] || url.pathname.slice(1);
} else if (/^player\.twitch\.tv$/.test(url.hostname)) {
return `videos/${url.searchParams.get("video")}`;
} else if (/^clips\.twitch\.tv$/.test(url.hostname)) {
Expand Down Expand Up @@ -1296,12 +1294,12 @@ const getVideoId = (service, video) => {
return clipPath[0];
}

return url.pathname.match(/(?:videos)\/([^/]+)/)?.[0];
return /(?:videos)\/([^/]+)/.exec(url.pathname)?.[0];
}
case "proxitok":
return url.pathname.match(/([^/]+)\/video\/([^/]+)/)?.[0];
return /([^/]+)\/video\/([^/]+)/.exec(url.pathname)?.[0];
case "tiktok": {
let id = url.pathname.match(/([^/]+)\/video\/([^/]+)/)?.[0];
let id = /([^/]+)\/video\/([^/]+)/.exec(url.pathname)?.[0];
if (!id) {
const playerEl = video.closest(".xgplayer-playing, .tiktok-web-player");
const itemEl = playerEl?.closest(
Expand All @@ -1323,29 +1321,29 @@ const getVideoId = (service, video) => {
case "vimeo": {
const appId = url.searchParams.get("app_id");
const videoId =
url.pathname.match(/[^/]+\/[^/]+$/)?.[0] ||
url.pathname.match(/[^/]+$/)?.[0];
/[^/]+\/[^/]+$/.exec(url.pathname)?.[0] ||
/[^/]+$/.exec(url.pathname)?.[0];

return appId ? `${videoId}?app_id=${appId}` : videoId;
}
case "xvideos":
return url.pathname.match(/[^/]+\/[^/]+$/)?.[0];
return /[^/]+\/[^/]+$/.exec(url.pathname)?.[0];
case "pornhub":
return (
url.searchParams.get("viewkey") ||
url.pathname.match(/embed\/([^/]+)/)?.[1]
/embed\/([^/]+)/.exec(url.pathname)?.[1]
);
case "twitter":
return url.pathname.match(/status\/([^/]+)/)?.[1];
return /status\/([^/]+)/.exec(url.pathname)?.[1];
case "udemy":
case "rumble":
case "facebook":
return url.pathname.slice(1);
case "rutube":
return url.pathname.match(/(?:video|embed)\/([^/]+)/)?.[1];
return /(?:video|embed)\/([^/]+)/.exec(url.pathname)?.[1];
case "coub":
return (
url.pathname.match(/(?:view|embed)\/([^/]+)/)?.[1] ||
/(?:view|embed)\/([^/]+)/.exec(url.pathname)?.[1] ||
document.querySelector(".coub.active")?.dataset?.permalink
);
case "bilibili": {
Expand All @@ -1354,7 +1352,7 @@ const getVideoId = (service, video) => {
return bvid;
}

let vid = url.pathname.match(/video\/([^/]+)/)?.[1];
let vid = /video\/([^/]+)/.exec(url.pathname)?.[1];
if (vid && url.searchParams.get("p") !== null) {
vid += `/?p=${url.searchParams.get("p")}`;
}
Expand All @@ -1367,7 +1365,7 @@ const getVideoId = (service, video) => {
return pathname.slice(1);
}

const videoId = pathname.match(/video\/embed\/([^/]+)/)?.[1];
const videoId = /video\/embed\/([^/]+)/.exec(pathname)?.[1];
if (!videoId) {
return null;
}
Expand All @@ -1380,16 +1378,16 @@ const getVideoId = (service, video) => {
return referer?.href.split("my.mail.ru")?.[1];
}
case "bitchute":
return url.pathname.match(/(video|embed)\/([^/]+)/)?.[2];
return /(video|embed)\/([^/]+)/.exec(url.pathname)?.[2];
case "coursera":
// ! LINK SHOULD BE LIKE THIS https://www.coursera.org/learn/learning-how-to-learn/lecture/75EsZ
// return url.pathname.match(/lecture\/([^/]+)\/([^/]+)/)?.[1]; // <--- COURSE PREVIEW
return url.pathname.match(/learn\/([^/]+)\/lecture\/([^/]+)/)?.[0]; // <--- COURSE PASSING (IF YOU LOGINED TO COURSERA)
return /learn\/([^/]+)\/lecture\/([^/]+)/.exec(url.pathname)?.[0]; // <--- COURSE PASSING (IF YOU LOGINED TO COURSERA)
case "eporner":
// ! LINK SHOULD BE LIKE THIS eporner.com/video-XXXXXXXXX/isdfsd-dfjsdfjsdf-dsfsdf-dsfsda-dsad-ddsd
return url.pathname.match(/video-([^/]+)\/([^/]+)/)?.[0];
return /video-([^/]+)\/([^/]+)/.exec(url.pathname)?.[0];
case "peertube":
return url.pathname.match(/\/w\/([^/]+)/)?.[0];
return /\/w\/([^/]+)/.exec(url.pathname)?.[0];
case "dailymotion": {
// we work in the context of the player
// geo.dailymotion.com
Expand All @@ -1398,7 +1396,7 @@ const getVideoId = (service, video) => {
).filter((s) => s.innerHTML.trim().includes(".m3u8"));
try {
let videoUrl = plainPlayerConfig[1].lastChild.src;
return videoUrl.match(/\/video\/(\w+)\.m3u8/)?.[1];
return /\/video\/(\w+)\.m3u8/.exec(videoUrl)?.[1];
} catch (e) {
console.error("[VOT]", e);
return false;
Expand All @@ -1410,46 +1408,46 @@ const getVideoId = (service, video) => {
return null;
}

const path = url.pathname.match(/([^/]+)\/([\d]+)/)?.[0];
const path = /([^/]+)\/([\d]+)/.exec(url.pathname)?.[0];
if (!path) {
return null;
}

return `${path}?vid=${vid}`;
}
case "yandexdisk":
return url.pathname.match(/\/i\/([^/]+)/)?.[1];
return /\/i\/([^/]+)/.exec(url.pathname)?.[1];
case "coursehunter": {
const courseId = url.pathname.match(/\/course\/([^/]+)/)?.[1];
const courseId = /\/course\/([^/]+)/.exec(url.pathname)?.[1];
return courseId ? courseId + url.search : false;
}
case "ok.ru": {
return url.pathname.match(/\/video\/(\d+)/)?.[1];
return /\/video\/(\d+)/.exec(url.pathname)?.[1];
}
case "googledrive":
return url.searchParams.get("docid");
case "bannedvideo":
return url.searchParams.get("id");
case "weverse":
return url.pathname.match(/([^/]+)\/(live|media)\/([^/]+)/)?.[0];
return /([^/]+)\/(live|media)\/([^/]+)/.exec(url.pathname)?.[0];
case "newgrounds":
return url.pathname.match(/([^/]+)\/(view)\/([^/]+)/)?.[0];
return /([^/]+)\/(view)\/([^/]+)/.exec(url.pathname)?.[0];
case "egghead":
return url.pathname.slice(1);
case "youku":
return url.pathname.match(/v_show\/id_[\w=]+/)?.[0];
return /v_show\/id_[\w=]+/.exec(url.pathname)?.[0];
case "archive":
return url.pathname.match(/(details|embed)\/([^/]+)/)?.[2];
return /(details|embed)\/([^/]+)/.exec(url.pathname)?.[2];
// case "sibnet": {
// const videoId = url.searchParams.get("videoid");
// if (videoId) {
// return `video${videoId}`;
// }

// return url.pathname.match(/video([^/]+)/)?.[0];
// return /video([^/]+)/.exec(url.pathname)?.[0];
// }
// case "patreon":
// return url.pathname.match(/posts\/([^/]+)/)?.[0];
// return /posts\/([^/]+)/.exec(url.pathname)?.[0];
case "directlink":
return url.pathname + url.search;
default:
Expand Down
2 changes: 1 addition & 1 deletion dist/vot-min.user.js

Large diffs are not rendered by default.

66 changes: 32 additions & 34 deletions dist/vot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1460,14 +1460,12 @@ const getVideoId = (service, video) => {
}

return (
url.pathname.match(/(?:watch|embed|shorts|live)\/([^/]+)/)?.[1] ||
/(?:watch|embed|shorts|live)\/([^/]+)/.exec(url.pathname)?.[1] ||
url.searchParams.get("v")
);
}
case "vk": {
const pathID = url.pathname.match(
/^\/(video|clip)-?[0-9]{8,9}_[0-9]{9}$/,
);
const pathID = /^\/(video|clip)-?[0-9]{8,9}_[0-9]{9}$/.exec(url.pathname);
const paramZ = url.searchParams.get("z");
const paramOID = url.searchParams.get("oid");
const paramID = url.searchParams.get("id");
Expand All @@ -1484,11 +1482,11 @@ const getVideoId = (service, video) => {
case "nine_gag":
case "9gag":
case "gag":
return url.pathname.match(/gag\/([^/]+)/)?.[1];
return /gag\/([^/]+)/.exec(url.pathname)?.[1];
case "twitch": {
const clipPath = url.pathname.match(/([^/]+)\/(?:clip)\/([^/]+)/);
const clipPath = /([^/]+)\/(?:clip)\/([^/]+)/.exec(url.pathname);
if (/^m\.twitch\.tv$/.test(url.hostname)) {
return url.href.match(/videos\/([^/]+)/)?.[0] || url.pathname.slice(1);
return /videos\/([^/]+)/.exec(url.href)?.[0] || url.pathname.slice(1);
} else if (/^player\.twitch\.tv$/.test(url.hostname)) {
return `videos/${url.searchParams.get("video")}`;
} else if (/^clips\.twitch\.tv$/.test(url.hostname)) {
Expand Down Expand Up @@ -1530,12 +1528,12 @@ const getVideoId = (service, video) => {
return clipPath[0];
}

return url.pathname.match(/(?:videos)\/([^/]+)/)?.[0];
return /(?:videos)\/([^/]+)/.exec(url.pathname)?.[0];
}
case "proxitok":
return url.pathname.match(/([^/]+)\/video\/([^/]+)/)?.[0];
return /([^/]+)\/video\/([^/]+)/.exec(url.pathname)?.[0];
case "tiktok": {
let id = url.pathname.match(/([^/]+)\/video\/([^/]+)/)?.[0];
let id = /([^/]+)\/video\/([^/]+)/.exec(url.pathname)?.[0];
if (!id) {
const playerEl = video.closest(".xgplayer-playing, .tiktok-web-player");
const itemEl = playerEl?.closest(
Expand All @@ -1557,29 +1555,29 @@ const getVideoId = (service, video) => {
case "vimeo": {
const appId = url.searchParams.get("app_id");
const videoId =
url.pathname.match(/[^/]+\/[^/]+$/)?.[0] ||
url.pathname.match(/[^/]+$/)?.[0];
/[^/]+\/[^/]+$/.exec(url.pathname)?.[0] ||
/[^/]+$/.exec(url.pathname)?.[0];

return appId ? `${videoId}?app_id=${appId}` : videoId;
}
case "xvideos":
return url.pathname.match(/[^/]+\/[^/]+$/)?.[0];
return /[^/]+\/[^/]+$/.exec(url.pathname)?.[0];
case "pornhub":
return (
url.searchParams.get("viewkey") ||
url.pathname.match(/embed\/([^/]+)/)?.[1]
/embed\/([^/]+)/.exec(url.pathname)?.[1]
);
case "twitter":
return url.pathname.match(/status\/([^/]+)/)?.[1];
return /status\/([^/]+)/.exec(url.pathname)?.[1];
case "udemy":
case "rumble":
case "facebook":
return url.pathname.slice(1);
case "rutube":
return url.pathname.match(/(?:video|embed)\/([^/]+)/)?.[1];
return /(?:video|embed)\/([^/]+)/.exec(url.pathname)?.[1];
case "coub":
return (
url.pathname.match(/(?:view|embed)\/([^/]+)/)?.[1] ||
/(?:view|embed)\/([^/]+)/.exec(url.pathname)?.[1] ||
document.querySelector(".coub.active")?.dataset?.permalink
);
case "bilibili": {
Expand All @@ -1588,7 +1586,7 @@ const getVideoId = (service, video) => {
return bvid;
}

let vid = url.pathname.match(/video\/([^/]+)/)?.[1];
let vid = /video\/([^/]+)/.exec(url.pathname)?.[1];
if (vid && url.searchParams.get("p") !== null) {
vid += `/?p=${url.searchParams.get("p")}`;
}
Expand All @@ -1601,7 +1599,7 @@ const getVideoId = (service, video) => {
return pathname.slice(1);
}

const videoId = pathname.match(/video\/embed\/([^/]+)/)?.[1];
const videoId = /video\/embed\/([^/]+)/.exec(pathname)?.[1];
if (!videoId) {
return null;
}
Expand All @@ -1614,16 +1612,16 @@ const getVideoId = (service, video) => {
return referer?.href.split("my.mail.ru")?.[1];
}
case "bitchute":
return url.pathname.match(/(video|embed)\/([^/]+)/)?.[2];
return /(video|embed)\/([^/]+)/.exec(url.pathname)?.[2];
case "coursera":
// ! LINK SHOULD BE LIKE THIS https://www.coursera.org/learn/learning-how-to-learn/lecture/75EsZ
// return url.pathname.match(/lecture\/([^/]+)\/([^/]+)/)?.[1]; // <--- COURSE PREVIEW
return url.pathname.match(/learn\/([^/]+)\/lecture\/([^/]+)/)?.[0]; // <--- COURSE PASSING (IF YOU LOGINED TO COURSERA)
return /learn\/([^/]+)\/lecture\/([^/]+)/.exec(url.pathname)?.[0]; // <--- COURSE PASSING (IF YOU LOGINED TO COURSERA)
case "eporner":
// ! LINK SHOULD BE LIKE THIS eporner.com/video-XXXXXXXXX/isdfsd-dfjsdfjsdf-dsfsdf-dsfsda-dsad-ddsd
return url.pathname.match(/video-([^/]+)\/([^/]+)/)?.[0];
return /video-([^/]+)\/([^/]+)/.exec(url.pathname)?.[0];
case "peertube":
return url.pathname.match(/\/w\/([^/]+)/)?.[0];
return /\/w\/([^/]+)/.exec(url.pathname)?.[0];
case "dailymotion": {
// we work in the context of the player
// geo.dailymotion.com
Expand All @@ -1632,7 +1630,7 @@ const getVideoId = (service, video) => {
).filter((s) => s.innerHTML.trim().includes(".m3u8"));
try {
let videoUrl = plainPlayerConfig[1].lastChild.src;
return videoUrl.match(/\/video\/(\w+)\.m3u8/)?.[1];
return /\/video\/(\w+)\.m3u8/.exec(videoUrl)?.[1];
} catch (e) {
console.error("[VOT]", e);
return false;
Expand All @@ -1644,46 +1642,46 @@ const getVideoId = (service, video) => {
return null;
}

const path = url.pathname.match(/([^/]+)\/([\d]+)/)?.[0];
const path = /([^/]+)\/([\d]+)/.exec(url.pathname)?.[0];
if (!path) {
return null;
}

return `${path}?vid=${vid}`;
}
case "yandexdisk":
return url.pathname.match(/\/i\/([^/]+)/)?.[1];
return /\/i\/([^/]+)/.exec(url.pathname)?.[1];
case "coursehunter": {
const courseId = url.pathname.match(/\/course\/([^/]+)/)?.[1];
const courseId = /\/course\/([^/]+)/.exec(url.pathname)?.[1];
return courseId ? courseId + url.search : false;
}
case "ok.ru": {
return url.pathname.match(/\/video\/(\d+)/)?.[1];
return /\/video\/(\d+)/.exec(url.pathname)?.[1];
}
case "googledrive":
return url.searchParams.get("docid");
case "bannedvideo":
return url.searchParams.get("id");
case "weverse":
return url.pathname.match(/([^/]+)\/(live|media)\/([^/]+)/)?.[0];
return /([^/]+)\/(live|media)\/([^/]+)/.exec(url.pathname)?.[0];
case "newgrounds":
return url.pathname.match(/([^/]+)\/(view)\/([^/]+)/)?.[0];
return /([^/]+)\/(view)\/([^/]+)/.exec(url.pathname)?.[0];
case "egghead":
return url.pathname.slice(1);
case "youku":
return url.pathname.match(/v_show\/id_[\w=]+/)?.[0];
return /v_show\/id_[\w=]+/.exec(url.pathname)?.[0];
case "archive":
return url.pathname.match(/(details|embed)\/([^/]+)/)?.[2];
return /(details|embed)\/([^/]+)/.exec(url.pathname)?.[2];
// case "sibnet": {
// const videoId = url.searchParams.get("videoid");
// if (videoId) {
// return `video${videoId}`;
// }

// return url.pathname.match(/video([^/]+)/)?.[0];
// return /video([^/]+)/.exec(url.pathname)?.[0];
// }
// case "patreon":
// return url.pathname.match(/posts\/([^/]+)/)?.[0];
// return /posts\/([^/]+)/.exec(url.pathname)?.[0];
case "directlink":
return url.pathname + url.search;
default:
Expand Down
Loading