Skip to content

Commit d60308c

Browse files
Merge pull request #30 from yuran1811/feat/youglish_search
feat: youglish search
2 parents 822de84 + acb5a11 commit d60308c

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

popup/tabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ const tabs = [
499499
...CATEGORY.youtube,
500500
scripts: [
501501
s.youtube_downloadVideo,
502+
s.youtube_downloadVideoUI,
502503
s.youtube_getVideoThumbnail,
503504
s.youtube_getVideoCaption,
504505
s.youtube_toggleLight,

scripts/_index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,7 @@ export { default as showImageOnHoverLink } from "./showImageOnHoverLink.js";
167167
export { default as fb_allInOne } from "./fb_allInOne.js";
168168
export { default as fb_getPostReactionCount } from "./fb_getPostReactionCount.js";
169169
export { default as bypass_learnAnything } from "./bypass_learnAnything.js";
170+
export { default as youtube_downloadVideoUI } from "./youtube_downloadVideoUI.js";
171+
export { default as youglish_search } from "./youglish_search.js";
170172
export { default as youtube_getVideoThumbnail } from "./youtube_getVideoThumbnail.js";
171173
export { default as youtube_getVideoCaption } from "./youtube_getVideoCaption.js";

scripts/youglish_search.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { BADGES } from './helpers/badge.js';
2+
3+
const contextMenuId = 'youglish-search';
4+
5+
export default {
6+
icon: '<i class="fa-solid fa-expand fa-lg fa-bounce"></i>',
7+
name: {
8+
en: 'YouGlish search',
9+
vi: 'Tìm kiếm trên YouGlish',
10+
},
11+
description: {
12+
en: "Master English pronunciation naturally! Learn how to pronounce tricky sounds like a native with YouGlish's real-world clips. No more dictionary confusion, just real English in context. (from 'youglish.com')",
13+
vi: 'Làm chủ phát âm tiếng Anh một cách tự nhiên! Học cách phát âm những âm thanh khó khăn như người bản xứ với các đoạn video thực tế từ YouGlish. Không còn bối rối với từ điển, chỉ có tiếng Anh thực sự trong ngữ cảnh. (từ "youglish.com")',
14+
},
15+
badges: [BADGES.new],
16+
changeLogs: {
17+
'2024-07-06': 'init',
18+
},
19+
20+
popupScript: {
21+
onClick: () => window.close(),
22+
},
23+
24+
backgroundScript: {
25+
runtime: {
26+
onInstalled: () => {
27+
chrome.contextMenus.create({
28+
title: 'YouGlish Search',
29+
contexts: ['selection'],
30+
id: contextMenuId,
31+
parentId: 'root',
32+
});
33+
},
34+
},
35+
contextMenus: {
36+
onClicked: ({ info }, context) => {
37+
if (info.menuItemId == contextMenuId) {
38+
const content = (info.selectionText || '').trim().toLowerCase();
39+
if (!content.length) return;
40+
41+
const link = `https://youglish.com/pronounce/${content}/english`;
42+
chrome.tabs.create({ url: link });
43+
}
44+
},
45+
},
46+
},
47+
};

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)