Fix AdBlock Workaround

This will also disable uYou’s `Remove YouTube Ads` now due to conflicts.
This commit is contained in:
arichornlover 2024-05-22 20:38:28 -05:00 committed by GitHub
parent c52afd1b1a
commit f310548624
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -120,32 +120,33 @@ static int contrastMode() {
%end %end
%end %end
// uYou AdBlock Workaround (for uYou Option) - @PoomSmart // uYou AdBlock Workaround (Note: disables uYou's "Remove YouTube Ads" Option) - @PoomSmart, @arichornlover & @Dodieboy
%group uYouAdBlockingWorkaround %group uYouAdBlockingWorkaround
// Workaround: uYou 3.0.3 Adblock fix - @PoomSmart // Workaround: uYou 3.0.3 Adblock fix
%hook YTHotConfig
- (BOOL)disableAfmaIdfaCollection { return NO; }
%end
%hook YTIPlayerResponse
- (BOOL)isMonetized { return NO; }
%end
%hook YTDataUtils
+ (id)spamSignalsDictionary { return @{}; }
+ (id)spamSignalsDictionaryWithoutIDFA { return @{}; }
%end
%hook YTAdsInnerTubeContextDecorator
- (void)decorateContext:(id)context { %orig(nil); }
%end
%hook YTAccountScopedAdsInnerTubeContextDecorator
- (void)decorateContext:(id)context { %orig(nil); }
%end
%hook YTReelInfinitePlaybackDataSource %hook YTReelInfinitePlaybackDataSource
- (void)setReels:(NSMutableOrderedSet <YTReelModel *> *)reels { - (void)setReels:(NSMutableOrderedSet <YTReelModel *> *)reels {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { [reels removeObjectsAtIndexes:[reels indexesOfObjectsPassingTest:^BOOL(YTReelModel *obj, NSUInteger idx, BOOL *stop) {
[reels removeObjectsAtIndexes:[reels indexesOfObjectsPassingTest:^BOOL(YTReelModel *obj, NSUInteger idx, BOOL *stop) { return [obj respondsToSelector:@selector(videoType)] ? obj.videoType == 3 : NO;
return [obj respondsToSelector:@selector(videoType)] ? obj.videoType == 3 : NO; }]];
}]];
}
%orig; %orig;
} }
%end %end
%hook YTAdsInnerTubeContextDecorator
- (void)decorateContext:(id)context {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) {}
}
%end
%hook YTAccountScopedAdsInnerTubeContextDecorator
- (void)decorateContext:(id)context {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) {}
}
%end
BOOL isAdString(NSString *description) { BOOL isAdString(NSString *description) {
if ([description containsString:@"brand_promo"] if ([description containsString:@"brand_promo"]
|| [description containsString:@"carousel_footered_layout"] || [description containsString:@"carousel_footered_layout"]
@ -155,19 +156,18 @@ BOOL isAdString(NSString *description) {
|| [description containsString:@"full_width_square_image_layout"] || [description containsString:@"full_width_square_image_layout"]
|| [description containsString:@"home_video_with_context"] || [description containsString:@"home_video_with_context"]
|| [description containsString:@"landscape_image_wide_button_layout"] || [description containsString:@"landscape_image_wide_button_layout"]
// || [description containsString:@"product_carousel"]
|| [description containsString:@"product_engagement_panel"] || [description containsString:@"product_engagement_panel"]
|| [description containsString:@"product_item"] || [description containsString:@"product_item"]
|| [description containsString:@"shelf_header"] || [description containsString:@"shelf_header"]
// || [description containsString:@"statement_banner"] || [description containsString:@"square_image_layout"]
|| [description containsString:@"square_image_layout"] // install app ad
|| [description containsString:@"text_image_button_layout"] || [description containsString:@"text_image_button_layout"]
|| [description containsString:@"text_search_ad"] || [description containsString:@"text_search_ad"]
|| [description containsString:@"expandable_list"]
|| [description containsString:@"expandable_metadata"]
|| [description containsString:@"video_display_full_buttoned_layout"]) || [description containsString:@"video_display_full_buttoned_layout"])
return YES; return YES;
return NO; return NO;
} }
%hook YTIElementRenderer %hook YTIElementRenderer
- (NSData *)elementData { - (NSData *)elementData {
NSString *description = [self description]; NSString *description = [self description];
@ -176,34 +176,54 @@ BOOL isAdString(NSString *description) {
return cellDividerData; return cellDividerData;
} }
if ([self respondsToSelector:@selector(hasCompatibilityOptions)] && self.hasCompatibilityOptions && self.compatibilityOptions.hasAdLoggingData) return cellDividerData; if ([self respondsToSelector:@selector(hasCompatibilityOptions)] && self.hasCompatibilityOptions && self.compatibilityOptions.hasAdLoggingData) return cellDividerData;
// if (isAdString(description)) return cellDividerData;
return %orig; return %orig;
} }
%end %end
%hook YTInnerTubeCollectionViewController %hook YTInnerTubeCollectionViewController
- (void)loadWithModel:(YTISectionListRenderer *)model { - (void)loadWithModel:(YTISectionListRenderer *)model {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { if ([model isKindOfClass:%c(YTISectionListRenderer)]) {
if ([model isKindOfClass:%c(YTISectionListRenderer)]) { NSMutableArray <YTISectionListSupportedRenderers *> *contentsArray = model.contentsArray;
NSMutableArray <YTISectionListSupportedRenderers *> *contentsArray = model.contentsArray; NSIndexSet *removeIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTISectionListSupportedRenderers *renderers, NSUInteger idx, BOOL *stop) {
NSIndexSet *removeIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTISectionListSupportedRenderers *renderers, NSUInteger idx, BOOL *stop) { if (![renderers isKindOfClass:%c(YTISectionListSupportedRenderers)])
if (![renderers isKindOfClass:%c(YTISectionListSupportedRenderers)]) return NO;
return NO; YTIItemSectionRenderer *sectionRenderer = renderers.itemSectionRenderer;
YTIItemSectionRenderer *sectionRenderer = renderers.itemSectionRenderer; YTIItemSectionSupportedRenderers *firstObject = [sectionRenderer.contentsArray firstObject];
YTIItemSectionSupportedRenderers *firstObject = [sectionRenderer.contentsArray firstObject]; YTIElementRenderer *elementRenderer = firstObject.elementRenderer;
YTIElementRenderer *elementRenderer = firstObject.elementRenderer; NSString *description = [elementRenderer description];
NSString *description = [elementRenderer description]; return isAdString(description)
return isAdString(description) || [description containsString:@"post_shelf"]
|| [description containsString:@"post_shelf"] || [description containsString:@"product_carousel"]
|| [description containsString:@"product_carousel"] || [description containsString:@"statement_banner"];
|| [description containsString:@"statement_banner"]; }];
}]; [contentsArray removeObjectsAtIndexes:removeIndexes];
[contentsArray removeObjectsAtIndexes:removeIndexes];
}
} }
%orig; %orig;
} }
%end %end
%hook YTWatchNextResultsViewController
- (void)loadWithModel:(YTISectionListRenderer *)watchNextResults {
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
%hook _ASDisplayView
- (void)didMoveToWindow {
%orig();
if ([self.accessibilityIdentifier isEqualToString:@"id.products_in_video_with_preview_overlay_badge.view"]) self.hidden = YES;
}
%end
%end %end
// Hide YouTube Logo - @dayanch96 // Hide YouTube Logo - @dayanch96
@ -1752,11 +1772,12 @@ static BOOL findCell(ASNodeController *nodeController, NSArray <NSString *> *ide
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"YouPiPEnabled"]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"YouPiPEnabled"];
} }
if (![allKeys containsObject:@"uYouAdBlockingWorkaroundLite_enabled"]) { if (![allKeys containsObject:@"uYouAdBlockingWorkaroundLite_enabled"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"uYouAdBlockingWorkaroundLite_enabled"]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"uYouAdBlockingWorkaroundLite_enabled"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"removeYouTubeAds"]; [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"removeYouTubeAds"];
} }
if (![allKeys containsObject:@"uYouAdBlockingWorkaround_enabled"]) { if (![allKeys containsObject:@"uYouAdBlockingWorkaround_enabled"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"uYouAdBlockingWorkaround_enabled"]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"uYouAdBlockingWorkaround_enabled"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"removeYouTubeAds"];
} }
// Broken uYou 3.0.3 setting: No Suggested Videos at The Video End // Broken uYou 3.0.3 setting: No Suggested Videos at The Video End
// Set default to allow autoplay, user can disable later // Set default to allow autoplay, user can disable later