Skip to content

Commit 6d45c02

Browse files
committed
feat: ✨ add script to render youtube video download buttons for each video
1 parent a719d9b commit 6d45c02

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

popup/tabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ const tabs = [
500500
scripts: [
501501
// s.youtube_localDownloader,
502502
s.youtube_downloadVideo,
503+
s.youtube_downloadVideoUI,
503504
s.youtube_toggleLight,
504505
s.pictureInPicture,
505506
s.pip_fullWebsite,

scripts/_index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,4 @@ export { default as showImageOnHoverLink } from "./showImageOnHoverLink.js";
168168
export { default as fb_allInOne } from "./fb_allInOne.js";
169169
export { default as fb_getPostReactionCount } from "./fb_getPostReactionCount.js";
170170
export { default as bypass_learnAnything } from "./bypass_learnAnything.js";
171+
export { default as youtube_downloadVideoUI } from "./youtube_downloadVideoUI.js";

scripts/youtube_downloadVideoUI.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { BADGES } from './helpers/badge.js';
2+
3+
export default {
4+
icon: `https://www.youtube.com/s/desktop/ff71ea81/img/favicon_48x48.png`,
5+
name: {
6+
en: 'Render buttons to download youtube video/audio',
7+
vi: 'Tạo các nút để tải video/audio youtube',
8+
},
9+
description: {
10+
en: 'Bypass age restriction, without login',
11+
vi: 'Tải cả video giới hạn độ tuổi, không cần đăng nhập',
12+
},
13+
badges: [BADGES.new],
14+
15+
contentScript: {
16+
onDocumentIdle: () => {
17+
setTimeout(function () {
18+
// https://stackoverflow.com/a/8260383/11898496
19+
function getIdFromYoutubeURL(url) {
20+
let regExp = /.*(?: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+
25+
const colors = {
26+
default: '#272727',
27+
green: '#2fb024',
28+
red: '#e62e2e',
29+
blue: '#3034bd',
30+
};
31+
32+
const providers = [
33+
{
34+
name: 'savefrom.net',
35+
color: colors.green,
36+
func: (url) => url.replace('youtube', 'ssyoutube'),
37+
},
38+
{
39+
name: '10downloader.com',
40+
color: colors.blue,
41+
func: (url) => url.replace('youtube', '000tube'),
42+
},
43+
{
44+
name: 'y2mate.com',
45+
color: colors.red,
46+
func: (url) => url.replace('youtube', 'youtubepp'),
47+
},
48+
{
49+
name: 'yt5s.com',
50+
color: colors.blue,
51+
func: (url) => url.replace('youtube', 'youtube5s'),
52+
},
53+
{
54+
name: 'yt1s.com',
55+
color: colors.red,
56+
func: (url) => 'https://yt1s.com/vi/youtube-to-mp4?q=' + url,
57+
},
58+
{
59+
name: 'tubemp3.to',
60+
color: colors.default,
61+
func: (url) => 'https://tubemp3.to/' + url,
62+
},
63+
{
64+
name: '10downloader.com',
65+
color: colors.default,
66+
func: (url) => 'https://10downloader.com/download?v=' + url,
67+
},
68+
{
69+
name: '9xbuddy.com',
70+
color: colors.default,
71+
func: (url) => 'https://9xbuddy.com/process?url=' + url,
72+
},
73+
{
74+
name: 'ymp4.com',
75+
color: colors.default,
76+
func: (url) => 'https://ymp4.download/en50/?url=' + url,
77+
},
78+
{
79+
name: 'getlinks.vip',
80+
color: colors.default,
81+
func: (url) => 'https://getlinks.vip/vi/youtube/' + getIdFromYoutubeURL(url),
82+
},
83+
];
84+
85+
const videoUrl = window.location.href;
86+
87+
const genDownloadLinkFromProvider = (provider, url) =>
88+
/* html */
89+
`<a href="${provider.func(
90+
url
91+
)}" target="_blank" style="display:inline-block;font-size:16px;padding:8px 12px;background-color:${
92+
provider.color
93+
};color:white;border-radius:12px;text-decoration:none;font-weight:bold">${provider.name}</a>`;
94+
95+
let intervalId = setInterval(function () {
96+
const container = document.querySelector('#above-the-fold #title > h1');
97+
if (!container) return;
98+
99+
clearInterval(intervalId);
100+
101+
const links = providers.map((provider) => genDownloadLinkFromProvider(provider, videoUrl));
102+
103+
container.insertAdjacentHTML(
104+
'afterend',
105+
/* html */
106+
`<div style="display:flex;justify-content:start;align-items:center;flex-wrap:wrap;gap:6px;width:100%;h:max-content">
107+
${links.join('')}
108+
</div>`
109+
);
110+
}, 500);
111+
}, 500);
112+
},
113+
},
114+
};

0 commit comments

Comments
 (0)