Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update adblock #51

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 67 additions & 36 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -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 <YTReelModel *> *)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 <YTISectionListSupportedRenderers *> *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 <YTISectionListSupportedRenderers *> *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 <YTISectionListSupportedRenderers *> *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 <YTISectionListSupportedRenderers *> *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
Expand Down