From 3f33749673bc35652be26040e260fd1e88093c7e Mon Sep 17 00:00:00 2001 From: arichornlover <78001398+arichornlover@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:07:28 -0500 Subject: [PATCH] Fix compiling (uYouPlus.xm) --- Sources/uYouPlus.xm | 77 +++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/Sources/uYouPlus.xm b/Sources/uYouPlus.xm index 6f58b42..a3455f2 100644 --- a/Sources/uYouPlus.xm +++ b/Sources/uYouPlus.xm @@ -58,6 +58,24 @@ static NSString *accessGroupID() { %end // Workaround: uYou 3.0.3 Adblock fix. +%hook YTAdsInnerTubeContextDecorator +if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { +- (void)decorateContext:(id)context {} +} +%end +%hook YTAccountScopedAdsInnerTubeContextDecorator +if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { +- (void)decorateContext:(id)context {} +} +%end +%hook YTIElementRenderer +- (NSData *)elementData { + if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { + if (self.hasCompatibilityOptions && self.compatibilityOptions.hasAdLoggingData) return nil; + return %orig; + } +} +%end BOOL isAd(YTIElementRenderer *self) { if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { if (self != nil) { @@ -80,6 +98,35 @@ BOOL isAd(YTIElementRenderer *self) { } 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]; + } + %orig; +} +%end + +%hook YTWatchNextResultsViewController +- (void)loadWithModel:(YTISectionListRenderer *)watchNextResults { + if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { + 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]; + } + %orig; +} +%end // Hide YouTube Logo - @dayanch96 %group gHideYouTubeLogo @@ -125,36 +172,6 @@ BOOL isAd(YTIElementRenderer *self) { } %end -%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]; - } - %orig; -} -%end - -%hook YTWatchNextResultsViewController -- (void)loadWithModel:(YTISectionListRenderer *)watchNextResults { - if ([NSUserDefaults.standardUserDefaults boolForKey:@"removeYouTubeAds"]) { - 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]; - } - %orig; -} -%end - // Workaround: fix YouTube Premium Logo not working on v18.35.4 or above. %hook YTVersionUtils // Working Version for Premium Logo + (NSString *)appVersion { return @"18.34.5"; }