mirror of
https://github.com/arichornlover/uYouEnhanced.git
synced 2026-03-11 17:15:32 +00:00
Updated uYou AdBlocking Workaround
This commit is contained in:
parent
3e7c454c67
commit
94d53814ca
1 changed files with 52 additions and 36 deletions
|
|
@ -88,6 +88,15 @@ static int contrastMode() {
|
|||
|
||||
%group uYouAdBlockingWorkaround
|
||||
// Workaround: uYou 3.0.3 Adblock fix - @PoomSmart
|
||||
%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
|
||||
|
||||
%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 <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];
|
||||
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 <YTISectionListSupportedRenderers *> *contentsArray = watchNextResults.contentsArray;
|
||||
%hook YTInnerTubeCollectionViewController
|
||||
- (void)loadWithModel:(YTISectionListRenderer *)model {
|
||||
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];
|
||||
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];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue