From da03edf564ce5438bbd442e096bf6367b7764aed Mon Sep 17 00:00:00 2001 From: arichornlover <78001398+arichornlover@users.noreply.github.com> Date: Thu, 21 Mar 2024 20:54:35 -0500 Subject: [PATCH] uYou Adblock Fix - #457 The stuff was from YouTube Reborn v4.2.6 but modified it for uYouEnhanced. --- Sources/uYouPlus.xm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Sources/uYouPlus.xm b/Sources/uYouPlus.xm index 1f803dc..8c0b577 100644 --- a/Sources/uYouPlus.xm +++ b/Sources/uYouPlus.xm @@ -87,7 +87,7 @@ static NSString *accessGroupID() { %end %end -// YouTube Premium Logo - @arichorn - this doesn't always function +// YouTube Premium Logo - @arichornlover - this doesn't always function. %group gPremiumYouTubeLogo %hook YTHeaderLogoController - (void)setPremiumLogo:(BOOL)isPremiumLogo { @@ -101,6 +101,37 @@ static NSString *accessGroupID() { } %end +// Workaround: uYou 3.0.3 Adblock fix. +%hook YTSectionListViewController +- (void)loadWithModel:(YTISectionListRenderer *)model { + if ([@"removeYouTubeAds" boolValue]) { + 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 ([@"removeYouTubeAds" boolValue]) { + 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"; }