From 1d6dc49a5e6b4ef0c18a12b6787322e39cfe6e7b Mon Sep 17 00:00:00 2001 From: Alan Tan Date: Sat, 18 May 2024 02:03:23 +0800 Subject: [PATCH] Update adblock --- Tweak.xm | 103 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/Tweak.xm b/Tweak.xm index 683731d9..fb555381 100644 --- a/Tweak.xm +++ b/Tweak.xm @@ -1129,61 +1129,92 @@ static UIButton *makeUnderRebornPlayerButton(ELMCellNode *node, NSString *title, - (BOOL)isMonetized { return NO; } %end %hook YTDataUtils -+ (id)spamSignalsDictionary { return nil; } -+ (id)spamSignalsDictionaryWithoutIDFA { return nil; } ++ (id)spamSignalsDictionary { return @{}; } ++ (id)spamSignalsDictionaryWithoutIDFA { return @{}; } %end %hook YTAdsInnerTubeContextDecorator -- (void)decorateContext:(id)context {} +- (void)decorateContext:(id)context { %orig(nil); } %end %hook YTAccountScopedAdsInnerTubeContextDecorator -- (void)decorateContext:(id)context {} +- (void)decorateContext:(id)context { %orig(nil); } %end -%hook YTIElementRenderer -- (NSData *)elementData { - if (self.hasCompatibilityOptions && self.compatibilityOptions.hasAdLoggingData) return nil; - return %orig; +%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 -BOOL isAd(YTIElementRenderer *self) { - if (self != nil) { - NSString *description = [self description]; +BOOL isAdString(NSString *description) { if ([description containsString:@"brand_promo"] - || [description containsString:@"statement_banner"] - || [description containsString:@"product_carousel"] + || [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_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:@"shelf_header"] || [description containsString:@"square_image_layout"] - || [description containsString:@"landscape_image_wide_button_layout"] - || [description containsString:@"feed_ad_metadata"]) + || [description containsString:@"text_image_button_layout"] + || [description containsString:@"text_search_ad"] + || [description containsString:@"expandable_list"] + || [description containsString:@"expandable_metadata"] + || [description containsString:@"video_display_full_buttoned_layout"]) return YES; - }return NO; + return NO; +} +NSData *cellDividerData; +%hook YTIElementRenderer +- (NSData *)elementData { + NSString *description = [self description]; + if ([description containsString:@"cell_divider"]) { + if (!cellDividerData) cellDividerData = %orig; + return cellDividerData; + } + if ([self respondsToSelector:@selector(hasCompatibilityOptions)] && self.hasCompatibilityOptions && self.compatibilityOptions.hasAdLoggingData) return cellDividerData; + return %orig; } -%hook YTSectionListViewController +%end +%hook YTInnerTubeCollectionViewController - (void)loadWithModel:(YTISectionListRenderer *)model { - 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]; + 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]; + 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]; + } %orig; } %end %hook YTWatchNextResultsViewController - (void)loadWithModel:(YTISectionListRenderer *)watchNextResults { - NSMutableArray *contentsArray = watchNextResults.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]; + if ([watchNextResults isKindOfClass:%c(YTISectionListRenderer)]) { + NSMutableArray *contentsArray = watchNextResults.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]; + YTIElementRenderer *elementRenderer = firstObject.elementRenderer; + NSString *description = [elementRenderer description]; + return isAdString(description); + }]; + [contentsArray removeObjectsAtIndexes:removeIndexes]; + } %orig; } %end