@@ -16,8 +16,6 @@ import {
1616import { userRatingsUrl } from '../vars' ;
1717
1818export class UserRatingsScraper {
19- private films : CSFDUserRatings [ ] = [ ] ;
20-
2119 public async userRatings (
2220 user : string | number ,
2321 config ?: CSFDUserRatingConfig ,
@@ -45,7 +43,7 @@ export class UserRatingsScraper {
4543
4644 const items = parse ( response ) ;
4745 const movies = items . querySelectorAll ( '.box-user-rating .table-container tbody tr' ) ;
48- allMovies = [ ...this . getPage ( config , movies ) ] ;
46+ allMovies = [ ...allMovies , ... this . getPage ( config , movies ) ] ;
4947
5048 // Sleep
5149 if ( config . allPagesDelay ) {
@@ -59,6 +57,7 @@ export class UserRatingsScraper {
5957 }
6058
6159 private getPage ( config : CSFDUserRatingConfig , movies : HTMLElement [ ] ) {
60+ const films : CSFDUserRatings [ ] = [ ] ;
6261 if ( config ) {
6362 if ( config . includesOnly ?. length && config . excludes ?. length ) {
6463 console . warn (
@@ -76,23 +75,23 @@ export class UserRatingsScraper {
7675 // Filtering includesOnly
7776 if ( config ?. includesOnly ?. length ) {
7877 if ( config . includesOnly . some ( ( include ) => type === include ) ) {
79- this . buildUserRatings ( el ) ;
78+ films . push ( this . buildUserRatings ( el ) ) ;
8079 }
8180 // Filter exludes
8281 } else if ( config ?. excludes ?. length ) {
8382 if ( ! config . excludes . some ( ( exclude ) => type === exclude ) ) {
84- this . buildUserRatings ( el ) ;
83+ films . push ( this . buildUserRatings ( el ) ) ;
8584 }
8685 } else {
8786 // Without filtering
88- this . buildUserRatings ( el ) ;
87+ films . push ( this . buildUserRatings ( el ) ) ;
8988 }
9089 }
91- return this . films ;
90+ return films ;
9291 }
9392
94- private buildUserRatings ( el : HTMLElement ) {
95- this . films . push ( {
93+ private buildUserRatings ( el : HTMLElement ) : CSFDUserRatings {
94+ return {
9695 id : getUserRatingId ( el ) ,
9796 title : getUserRatingTitle ( el ) ,
9897 year : getUserRatingYear ( el ) ,
@@ -101,6 +100,6 @@ export class UserRatingsScraper {
101100 colorRating : getUserRatingColorRating ( el ) as CSFDColorRating ,
102101 userDate : getUserRatingDate ( el ) ,
103102 userRating : getUserRating ( el ) as CSFDStars
104- } ) ;
103+ } ;
105104 }
106105}
0 commit comments