1
+ import { UfsGlobal } from './content-scripts/ufs_global.js' ;
1
2
import { BADGES } from './helpers/badge.js' ;
2
3
3
4
export default {
@@ -17,8 +18,8 @@ export default {
17
18
setTimeout ( function ( ) {
18
19
// https://stackoverflow.com/a/8260383/11898496
19
20
function getIdFromYoutubeURL ( url ) {
20
- let regExp = / .* (?: y o u t u .b e \/ | v \/ | u \/ \w \/ | e m b e d \/ | w a t c h \? v = ) ( [ ^ # \& \? ] * ) .* / ;
21
- let match = url . match ( regExp ) ;
21
+ const regExp = / .* (?: y o u t u .b e \/ | v \/ | u \/ \w \/ | e m b e d \/ | w a t c h \? v = ) ( [ ^ # \& \? ] * ) .* / ;
22
+ const match = url . match ( regExp ) ;
22
23
return match && match [ 1 ] . length == 11 ? match [ 1 ] : false ;
23
24
}
24
25
@@ -73,7 +74,7 @@ export default {
73
74
{
74
75
name : 'ymp4.com' ,
75
76
color : colors . default ,
76
- func : ( url ) => 'https://ymp4.download/en50/ ?url=' + url ,
77
+ func : ( url ) => 'https://ymp4.download/?url=' + url ,
77
78
} ,
78
79
{
79
80
name : 'getlinks.vip' ,
@@ -84,31 +85,66 @@ export default {
84
85
85
86
const videoUrl = window . location . href ;
86
87
88
+ const downloadIcon = `
89
+ <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" focusable="false" style="pointer-events:none;display:inherit;width:100%;height:100%;">
90
+ <path d="M17 18v1H6v-1h11zm-.5-6.6-.7-.7-3.8 3.7V4h-1v10.4l-3.8-3.8-.7.7 5 5 5-4.9z"></path>
91
+ </svg>` ;
92
+
87
93
const genDownloadLinkFromProvider = ( provider , url ) =>
88
94
/* 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>`;
95
+ `<a
96
+ href="${ provider . func ( url ) } "
97
+ target="_blank"
98
+ class="ufs-ytDownloadVideoUI__btn"
99
+ onclick="((e)=>e.stopPropagation())(event)">
100
+ ${ provider . name }
101
+ </a>` ;
102
+
103
+ injectCss ( ) ;
94
104
95
105
let intervalId = setInterval ( function ( ) {
96
106
const container = document . querySelector ( '#above-the-fold #title > h1' ) ;
97
107
if ( ! container ) return ;
98
108
99
109
clearInterval ( intervalId ) ;
100
110
111
+ document . addEventListener ( 'click' , ( ) => {
112
+ const el = document . querySelector ( '#ufs-ytDownloadBtn__container' ) ;
113
+ if ( el && el . style . display === 'flex' ) el . style . display = 'none' ;
114
+ } ) ;
115
+
101
116
const links = providers . map ( ( provider ) => genDownloadLinkFromProvider ( provider , videoUrl ) ) ;
102
117
103
118
container . insertAdjacentHTML (
104
119
'afterend' ,
105
120
/* 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>`
121
+ `
122
+ <button
123
+ class="yt-spec-button-shape-next yt-spec-button-shape-next--tonal yt-spec-button-shape-next--mono yt-spec-button-shape-next--size-m yt-spec-button-shape-next--icon-leading"
124
+ style="position:relative;margin:6px 0;"
125
+ onclick="((e)=>{e.stopPropagation();const el = document.querySelector('#ufs-ytDownloadBtn__container');if (!el) return;el.style.display = el.style.display == 'flex' ? 'none' : 'flex'})(event)"
126
+ >
127
+ <div class="yt-spec-button-shape-next__icon">
128
+ ${ downloadIcon }
129
+ </div>
130
+
131
+ <div class="yt-spec-button-shape-next__button-text-content"><span class="yt-core-attributed-string yt-core-attributed-string--white-space-no-wrap" role="text">Tải video</span></div>
132
+
133
+ <div id="ufs-ytDownloadBtn__container" class="ufs-ytDownloadVideoUI__container">
134
+ ${ links . join ( '' ) }
135
+ </div>
136
+ </button>`
109
137
) ;
110
138
} , 500 ) ;
111
139
} , 500 ) ;
112
140
} ,
113
141
} ,
114
142
} ;
143
+
144
+ function injectCss ( path = '/scripts/youtube_downloadVideoUI.css' , id = 'ufs-yt_downloadVideoUI-css' ) {
145
+ if ( ! document . querySelector ( '#' + id ) ) {
146
+ UfsGlobal . Extension . getURL ( path ) . then ( ( url ) => {
147
+ UfsGlobal . DOM . injectCssFile ( url , id ) ;
148
+ } ) ;
149
+ }
150
+ }
0 commit comments