@@ -10,18 +10,20 @@ class InputError extends Error {
1010
1111
1212function _lastList ( ) {
13+ this . cachedUrls = [ ] ;
1314
14- this . run = ( ) => {
15+ this . run = ( url = '' , pages = 1 , playlistName = 'Last List' ) => {
1516 try {
16- let url ;
17- try {
18- url = utils . InputBox ( 0 , "Enter the URL:" , "Download" , '' , true ) ;
19- } catch ( e ) {
20- throw new InputError ( 'Cancelled Input' ) ;
21- }
22-
2317 if ( ! url ) {
24- throw new InputError ( 'No URL' ) ;
18+ try {
19+ url = utils . InputBox ( 0 , "Enter the URL:" , "Download" , this . cachedUrls . length ? this . cachedUrls [ 0 ] : '' , true ) ;
20+ } catch ( e ) {
21+ throw new InputError ( 'Cancelled Input' ) ;
22+ }
23+
24+ if ( ! url ) {
25+ throw new InputError ( 'No URL' ) ;
26+ }
2527 }
2628
2729 // if url has page as parameter, set directPage to true
@@ -39,29 +41,39 @@ function _lastList() {
3941 url = url . replace ( matches [ 0 ] [ 1 ] , "" ) ;
4042 }
4143
42- let pages ;
43- try {
44- pages = utils . InputBox ( 0 , "Enter the number of pages:" , "Download" , '1' , true ) ;
45- } catch ( e ) {
46- throw new InputError ( 'Cancelled Input' ) ;
47- }
48- pages = parseInt ( pages ) ;
49- if ( isNaN ( pages ) || pages < 1 ) {
50- pages = 1 ;
51- }
44+ if ( ! pages || isNaN ( pages ) || pages < 1 ) {
45+ try {
46+ pages = utils . InputBox ( 0 , "Enter the number of pages:" , "Download" , '1' , true ) ;
47+ } catch ( e ) {
48+ throw new InputError ( 'Cancelled Input' ) ;
49+ }
5250
53- let playlistName ;
54- try {
55- playlistName = utils . InputBox ( 0 , "Enter the playlist name:" , "Download" , 'LastList' , true ) ;
56- } catch ( e ) {
57- throw new InputError ( 'Cancelled Input' ) ;
51+ pages = parseInt ( pages ) ;
52+ if ( isNaN ( pages ) || pages < 1 ) {
53+ pages = 1 ;
54+ }
5855 }
5956
6057 if ( ! playlistName ) {
61- throw new InputError ( 'No playlist name' ) ;
58+ try {
59+ playlistName = utils . InputBox ( 0 , "Enter the playlist name:" , "Download" , 'Last List' , true ) ;
60+ } catch ( e ) {
61+ throw new InputError ( 'Cancelled Input' ) ;
62+ }
63+
64+ if ( ! playlistName ) {
65+ throw new InputError ( 'No playlist name' ) ;
66+ }
6267 }
6368
6469 this . scrapeUrl ( url , startPage , pages , playlistName ) ;
70+
71+ // removes url from cache if it exists and slices the cache to 9 items
72+ this . cachedUrls = this . cachedUrls . filter ( ( cachedUrl ) => {
73+ return cachedUrl !== url ;
74+ } ) . slice ( 0 , 9 ) ;
75+ // add url to the beginning of the cache
76+ this . cachedUrls . unshift ( url ) ;
6577 } catch ( e ) {
6678 if ( e instanceof InputError ) {
6779 // do nothing
0 commit comments