From 94d53814ca7a8fa57fa89815555f6bb2122bd616 Mon Sep 17 00:00:00 2001 From: arichornlover <78001398+arichornlover@users.noreply.github.com> Date: Wed, 8 May 2024 17:45:28 -0500 Subject: [PATCH] Updated `uYou AdBlocking Workaround` --- Sources/uYouPlus.xm | 88 ++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/Sources/uYouPlus.xm b/Sources/uYouPlus.xm index 955d068..26bfafc 100644 --- a/Sources/uYouPlus.xm +++ b/Sources/uYouPlus.xm @@ -88,6 +88,15 @@ static int contrastMode() { %group uYouAdBlockingWorkaround // Workaround: uYou 3.0.3 Adblock fix - @PoomSmart +%hook YTReelInfinitePlaybackDataSource +- (void)setReels:(NSMutableOrderedSet *)reels { + [reels removeObjectsAtIndexes:[reels indexesOfObjectsPassingTest:^BOOL(YTReelModel *obj, NSUInteger idx, BOOL *stop) { + return [obj respondsToSelector:@selector(videoType)] ? obj.videoType == 3 : NO; + }]]; + %orig; +} +%end + %hook YTAdsInnerTubeContextDecorator - (void)decorateContext:(id)context { if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) {} @@ -99,52 +108,59 @@ if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) {} if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) {} } %end -BOOL isAd(YTIElementRenderer *self) { - if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { - if (self != nil) { - NSString *description = [self description]; - if ([description containsString:@"brand_promo"] - || [description containsString:@"statement_banner"] - || [description containsString:@"product_carousel"] - || [description containsString:@"product_engagement_panel"] - || [description containsString:@"product_item"] - || [description containsString:@"expandable_list"] - || [description containsString:@"text_search_ad"] - || [description containsString:@"text_image_button_layout"] - || [description containsString:@"carousel_headered_layout"] - || [description containsString:@"carousel_footered_layout"] - || [description containsString:@"square_image_layout"] - || [description containsString:@"landscape_image_wide_button_layout"] - || [description containsString:@"feed_ad_metadata"]) - return YES; - } - } + +BOOL isAdString(NSString *description) { + if ([description containsString:@"brand_promo"] + || [description containsString:@"carousel_footered_layout"] + || [description containsString:@"carousel_headered_layout"] + || [description containsString:@"feed_ad_metadata"] + || [description containsString:@"full_width_portrait_image_layout"] + || [description containsString:@"full_width_square_image_layout"] + || [description containsString:@"home_video_with_context"] + || [description containsString:@"landscape_image_wide_button_layout"] + // || [description containsString:@"product_carousel"] + || [description containsString:@"product_engagement_panel"] + || [description containsString:@"product_item"] + || [description containsString:@"shelf_header"] + // || [description containsString:@"statement_banner"] + || [description containsString:@"square_image_layout"] // install app ad + || [description containsString:@"text_image_button_layout"] + || [description containsString:@"text_search_ad"] + || [description containsString:@"video_display_full_buttoned_layout"]) + return YES; return NO; } -%hook YTSectionListViewController -- (void)loadWithModel:(YTISectionListRenderer *)model { - if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { - NSMutableArray *contentsArray = model.contentsArray; - NSIndexSet *removeIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTISectionListSupportedRenderers *renderers, NSUInteger idx, BOOL *stop) { - YTIItemSectionRenderer *sectionRenderer = renderers.itemSectionRenderer; - YTIItemSectionSupportedRenderers *firstObject = [sectionRenderer.contentsArray firstObject]; - return firstObject.hasPromotedVideoRenderer || firstObject.hasCompactPromotedVideoRenderer || firstObject.hasPromotedVideoInlineMutedRenderer || isAd(firstObject.elementRenderer); - }]; - [contentsArray removeObjectsAtIndexes:removeIndexes]; +NSData *cellDividerData; + +%hook YTIElementRenderer +- (NSData *)elementData { + NSString *description = [self description]; + if ([description containsString:@"cell_divider"]) { + if (!cellDividerData) cellDividerData = %orig; + return cellDividerData; } - %orig; + if ([self respondsToSelector:@selector(hasCompatibilityOptions)] && self.hasCompatibilityOptions && self.compatibilityOptions.hasAdLoggingData) return cellDividerData; + // if (isAdString(description)) return cellDividerData; + return %orig; } %end -%hook YTWatchNextResultsViewController -- (void)loadWithModel:(YTISectionListRenderer *)watchNextResults { - if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { - NSMutableArray *contentsArray = watchNextResults.contentsArray; +%hook YTInnerTubeCollectionViewController +- (void)loadWithModel:(YTISectionListRenderer *)model { + if ([model isKindOfClass:%c(YTISectionListRenderer)]) { + NSMutableArray *contentsArray = model.contentsArray; NSIndexSet *removeIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTISectionListSupportedRenderers *renderers, NSUInteger idx, BOOL *stop) { + if (![renderers isKindOfClass:%c(YTISectionListSupportedRenderers)]) + return NO; YTIItemSectionRenderer *sectionRenderer = renderers.itemSectionRenderer; YTIItemSectionSupportedRenderers *firstObject = [sectionRenderer.contentsArray firstObject]; - return firstObject.hasPromotedVideoRenderer || firstObject.hasCompactPromotedVideoRenderer || firstObject.hasPromotedVideoInlineMutedRenderer || isAd(firstObject.elementRenderer); + YTIElementRenderer *elementRenderer = firstObject.elementRenderer; + NSString *description = [elementRenderer description]; + return isAdString(description) + || [description containsString:@"post_shelf"] + || [description containsString:@"product_carousel"] + || [description containsString:@"statement_banner"]; }]; [contentsArray removeObjectsAtIndexes:removeIndexes]; }