@@ -11,6 +11,20 @@ export default {
1111 whiteList : [ "*://doutu.be" ] ,
1212
1313 func : async function ( ) {
14+ // https://stackoverflow.com/a/18197341/11898496
15+ function download ( filename , text ) {
16+ var element = document . createElement ( "a" ) ;
17+ element . setAttribute (
18+ "href" ,
19+ "data:text/plain;charset=utf-8," + encodeURIComponent ( text )
20+ ) ;
21+ element . setAttribute ( "download" , filename ) ;
22+ element . style . display = "none" ;
23+ document . body . appendChild ( element ) ;
24+ element . click ( ) ;
25+ document . body . removeChild ( element ) ;
26+ }
27+
1428 const WAIT_FOR_FULL_VIDEO_LOADED = 5000 ;
1529 const FIND_FULL_VIDEO_INTERVAL = 100 ;
1630 const sleep = ( m ) => new Promise ( ( r ) => setTimeout ( r , m ) ) ;
@@ -20,7 +34,15 @@ export default {
2034 const closeFullVideo = ( ) =>
2135 document . querySelector ( "div.top-8.left-4" ) ?. click ( ) ;
2236
23- alert ( "Getting video, open console (F12) to see result." ) ;
37+ if (
38+ ! confirm (
39+ "Tool sẽ tự động mở từng ảnh/video để lấy link.\nVui lòng không thoát trang web.\nBấm OK để bắt đầu quá trình lấy link."
40+ )
41+ ) {
42+ return ;
43+ }
44+
45+ let allUrls = [ ] ;
2446
2547 const queue = getAllVideo ( ) ;
2648 while ( queue . length > 0 ) {
@@ -38,6 +60,7 @@ export default {
3860 }
3961
4062 if ( full_video ) {
63+ allUrls . push ( full_video . src ) ;
4164 console . log ( full_video . src ) ;
4265 } else {
4366 console . log ( "Not found full video" ) ;
@@ -46,5 +69,9 @@ export default {
4669 closeFullVideo ( ) ;
4770 await sleep ( 500 ) ;
4871 }
72+
73+ console . log ( allUrls ) ;
74+ alert ( "Tìm được " + allUrls . length + " videos. Bấm ok để tải xuống link." ) ;
75+ download ( location . pathname + ".txt" , allUrls . join ( "\n" ) ) ;
4976 } ,
5077} ;
0 commit comments