From 9e60d9fe3e27a4180df522d7aa66e124e3f29334 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Mon, 9 Aug 2021 00:23:09 -0600 Subject: [PATCH] Fixed issue where some some videos would send many requests to SponsorBlock when only one was needed --- .../skip-ad-button/skip-ad-button.component.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/components/skip-ad-button/skip-ad-button.component.ts b/src/app/components/skip-ad-button/skip-ad-button.component.ts index 2222862..9f8cd74 100644 --- a/src/app/components/skip-ad-button/skip-ad-button.component.ts +++ b/src/app/components/skip-ad-button/skip-ad-button.component.ts @@ -17,10 +17,16 @@ export class SkipAdButtonComponent implements OnInit { sponsor_block_cache = {}; show_skip_ad_button = false; + skip_ad_button_check_interval = null; + constructor(private postsService: PostsService) { } ngOnInit(): void { - setInterval(() => this.skipAdButtonCheck(), 500); + this.skip_ad_button_check_interval = setInterval(() => this.skipAdButtonCheck(), 500); + } + + ngOnDestroy(): void { + clearInterval(this.skip_ad_button_check_interval); } checkSponsorBlock(video_to_check) { @@ -45,6 +51,8 @@ export class SkipAdButtonComponent implements OnInit { const found_data = res['find'](data => data['videoID'] === video_id); if (found_data) { this.sponsor_block_cache[video_to_check.url] = found_data; + } else { + this.sponsor_block_cache[video_to_check.url] = null; } }, err => { // likely doesn't exist