uYou Adblock Fix - #457

The stuff was from YouTube Reborn v4.2.6 but modified it for uYouEnhanced.
This commit is contained in:
arichornlover 2024-03-21 20:54:35 -05:00 committed by GitHub
parent f3e096d9b3
commit da03edf564
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 <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];
}
%orig;
}
%end
%hook YTWatchNextResultsViewController
- (void)loadWithModel:(YTISectionListRenderer *)watchNextResults {
if ([@"removeYouTubeAds" boolValue]) {
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];
}
%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"; }