Skip to content

Commit 8e3264c

Browse files
committed
youtube thumbnail + captions
1 parent 609a82e commit 8e3264c

8 files changed

+181
-623
lines changed

popup/tabs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,9 @@ const tabs = [
498498
{
499499
...CATEGORY.youtube,
500500
scripts: [
501-
// s.youtube_localDownloader,
502501
s.youtube_downloadVideo,
502+
s.youtube_getVideoThumbnail,
503+
s.youtube_getVideoCaption,
503504
s.youtube_toggleLight,
504505
s.pictureInPicture,
505506
s.pip_fullWebsite,

scripts/_index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export { default as vuiz_createLogo } from "./vuiz_createLogo.js";
131131
export { default as vuiz_getLink } from "./vuiz_getLink.js";
132132
export { default as ggdrive_downloadPdf } from "./ggdrive_downloadPdf.js";
133133
export { default as ggdrive_downloadPresentation } from "./ggdrive_downloadPresentation.js";
134-
export { default as youtube_localDownloader } from "./youtube_localDownloader.js";
135134
export { default as twitter_downloadButton } from "./twitter_downloadButton.js";
136135
export { default as spotify_downloadButton } from "./spotify_downloadButton.js";
137136
export { default as ggdrive_downloadDoc } from "./ggdrive_downloadDoc.js";
@@ -168,3 +167,5 @@ export { default as showImageOnHoverLink } from "./showImageOnHoverLink.js";
168167
export { default as fb_allInOne } from "./fb_allInOne.js";
169168
export { default as fb_getPostReactionCount } from "./fb_getPostReactionCount.js";
170169
export { default as bypass_learnAnything } from "./bypass_learnAnything.js";
170+
export { default as youtube_getVideoThumbnail } from "./youtube_getVideoThumbnail.js";
171+
export { default as youtube_getVideoCaption } from "./youtube_getVideoCaption.js";

scripts/youtube_downloadVideo.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ export default {
1414

1515
contentScript: {
1616
onClick: function () {
17-
// https://stackoverflow.com/a/8260383/11898496
18-
function getIdFromYoutubeURL(url) {
19-
let regExp =
20-
/.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
21-
let match = url.match(regExp);
22-
return match && match[1].length == 11 ? match[1] : false;
23-
}
24-
2517
let options = [
2618
{
2719
name: "y2mate.com",
@@ -79,3 +71,10 @@ export default {
7971
},
8072
},
8173
};
74+
75+
// https://stackoverflow.com/a/8260383/11898496
76+
export function getIdFromYoutubeURL(url) {
77+
let regExp = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
78+
let match = url.match(regExp);
79+
return match && match[1].length == 11 ? match[1] : false;
80+
}

scripts/youtube_getVideoCaption.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { BADGES } from "./helpers/badge.js";
2+
3+
export default {
4+
icon: '<i class="fa-solid fa-closed-captioning fa-2x"></i>',
5+
name: {
6+
en: "Get Youtube video's captions",
7+
vi: "Lấy phụ đề video trên Youtube",
8+
},
9+
description: {
10+
en: "Get all captions of playing youtube video",
11+
vi: "Tải về tất cả phụ đề của video youtube đang xem",
12+
},
13+
badges: [BADGES.new],
14+
changeLogs: {
15+
"2024-07-04": "init",
16+
},
17+
18+
whiteList: ["https://*.youtube.com/*"],
19+
20+
pageScript: {
21+
onClick: () => {
22+
function renderCaptions(captions) {
23+
const id = "ufs_youtube_getVideoCaption";
24+
const exist = document.getElementById(id);
25+
if (exist) exist.remove();
26+
27+
const div = document.createElement("div");
28+
div.id = id;
29+
div.innerHTML = `
30+
<style>
31+
#${id} {
32+
position: fixed;
33+
top: 0;
34+
left: 0;
35+
right: 0;
36+
bottom: 0;
37+
background: rgba(0, 0, 0, 0.8);
38+
z-index: 9999999999999999;
39+
display: flex;
40+
justify-content: center;
41+
align-items: center;
42+
font-size: 18px;
43+
}
44+
#${id} a {
45+
display: inline-block;
46+
transition: all 0.3s ease;
47+
text-decoration: none;
48+
}
49+
#${id} a:hover {
50+
text-decoration: underline;
51+
}
52+
#${id} > div {
53+
position: relative;
54+
background: #eee;
55+
padding: 20px;
56+
border-radius: 5px;
57+
max-width: 500px;
58+
max-height: 500px;
59+
overflow-y: scroll;
60+
overflow-x: hidden;
61+
}
62+
#${id} button {
63+
position: absolute;
64+
top: 10px;
65+
right: 10px;
66+
padding: 10px;
67+
background: #eee;
68+
border-radius: 5px;
69+
cursor: pointer;
70+
}
71+
</style>
72+
<div>
73+
<button>Close</button>
74+
<h3>Captions</h3><br/>
75+
<ul>
76+
${captions
77+
.map(
78+
(caption) => `<li>
79+
<a href="${caption.baseUrl}" target="_blank">
80+
${caption.name.simpleText} (${caption.languageCode})
81+
</a>
82+
</li>`
83+
)
84+
.join("")}
85+
</ul>
86+
</div>
87+
`;
88+
const button = div.querySelector("button");
89+
button.onclick = () => {
90+
div.remove();
91+
};
92+
document.documentElement.appendChild(div);
93+
}
94+
95+
const methods = [
96+
() =>
97+
document.getElementsByTagName("ytd-app")[0].data.playerResponse
98+
.captions.playerCaptionsTracklistRenderer.captionTracks,
99+
() =>
100+
ytplayer.config.args.raw_player_response.captions
101+
.playerCaptionsTracklistRenderer.captionTracks,
102+
];
103+
104+
for (let f of methods) {
105+
try {
106+
let captions = f();
107+
if (captions) {
108+
renderCaptions(captions);
109+
return;
110+
}
111+
} catch (e) {
112+
console.error(e);
113+
}
114+
}
115+
},
116+
},
117+
};

scripts/youtube_getVideoThumbnail.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { BADGES } from "./helpers/badge.js";
2+
import { getIdFromYoutubeURL } from "./youtube_downloadVideo.js";
3+
4+
export default {
5+
icon: '<i class="fa-regular fa-image fa-2x"></i>',
6+
name: {
7+
en: "Get Youtube video's thumbnail",
8+
vi: "Lấy thumbnail video trên Youtube",
9+
},
10+
description: {
11+
en: "Get largest thumbnail of playing youtube video",
12+
vi: "Tải về hình thumbnail độ phân giải lớn nhất của video youtube đang xem",
13+
},
14+
badges: [BADGES.new],
15+
changeLogs: {
16+
"2024-07-04": "init",
17+
},
18+
19+
whiteList: ["https://*.youtube.com/*"],
20+
21+
pageScript: {
22+
onClick: () => {
23+
const methods = [
24+
() =>
25+
document
26+
.getElementsByTagName("ytd-app")[0]
27+
.data.playerResponse.videoDetails.thumbnail.thumbnails.sort(
28+
(a, b) => b.width * b.height - a.width * a.height
29+
)[0].url,
30+
() =>
31+
ytplayer.config.args.raw_player_response.videoDetails.thumbnail.thumbnails.sort(
32+
(a, b) => b.width * b.height - a.width * a.height
33+
)[0].url,
34+
() =>
35+
`https://i.ytimg.com/vi/${getIdFromYoutubeURL(
36+
location.href
37+
)}/maxresdefault.jpg`,
38+
];
39+
40+
for (let f of methods) {
41+
try {
42+
let url = f();
43+
if (url) {
44+
window.open(url, "_blank");
45+
return;
46+
}
47+
} catch (e) {
48+
console.error(e);
49+
}
50+
}
51+
},
52+
},
53+
};

scripts/youtube_localDownloader.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)