Skip to content

Commit

Permalink
Update uYouPlus.xm
Browse files Browse the repository at this point in the history
  • Loading branch information
aricloverALT authored Jul 27, 2024
1 parent ab05b04 commit c6fb04b
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions Sources/uYouPlus.xm
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,47 @@ NSString *getAdString(NSString *description) {
return @"video_display_full_buttoned_layout";
return nil;
}
%hook YTInnerTubeCollectionViewController
- (void)addSectionsFromArray:(NSArray <YTIItemSectionRenderer *> *)array {
static BOOL isAdRenderer(YTIElementRenderer *elementRenderer, int kind) {
if ([elementRenderer respondsToSelector:@selector(hasCompatibilityOptions)] && elementRenderer.hasCompatibilityOptions && elementRenderer.compatibilityOptions.hasAdLoggingData) {
HBLogDebug(@"YTX adLogging %d %@", kind, elementRenderer);
return YES;
}
NSString *description = [elementRenderer description];
NSString *adString = getAdString(description);
if (adString) {
HBLogDebug(@"YTX getAdString %d %@ %@", kind, adString, elementRenderer);
return YES;
}
return NO;
}
static NSMutableArray <YTIItemSectionRenderer *> *filteredArray(NSArray <YTIItemSectionRenderer *> *array) {
NSMutableArray <YTIItemSectionRenderer *> *newArray = [array mutableCopy];
NSIndexSet *removeIndexes = [newArray indexesOfObjectsPassingTest:^BOOL(YTIItemSectionRenderer *sectionRenderer, NSUInteger idx, BOOL *stop) {
if (![sectionRenderer isKindOfClass:%c(YTIItemSectionRenderer)])
return NO;
YTIItemSectionSupportedRenderers *firstObject = [sectionRenderer.contentsArray firstObject];
YTIElementRenderer *elementRenderer = firstObject.elementRenderer;
if ([elementRenderer respondsToSelector:@selector(hasCompatibilityOptions)] && elementRenderer.hasCompatibilityOptions && elementRenderer.compatibilityOptions.hasAdLoggingData) {
HBLogDebug(@"YTX adLogging 2 %@", elementRenderer);
return YES;
NSMutableArray <YTIItemSectionSupportedRenderers *> *contentsArray = sectionRenderer.contentsArray;
if (contentsArray.count > 1) {
NSIndexSet *removeContentsArrayIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTIItemSectionSupportedRenderers *sectionSupportedRenderers, NSUInteger idx2, BOOL *stop2) {
YTIElementRenderer *elementRenderer = sectionSupportedRenderers.elementRenderer;
return isAdRenderer(elementRenderer, 3);
}];
[contentsArray removeObjectsAtIndexes:removeContentsArrayIndexes];
}
NSString *description = [elementRenderer description];
NSString *adString = getAdString(description);
if (adString) {
HBLogDebug(@"YTX getAdString 2 %@ %@", adString, elementRenderer);
return YES;
}
return NO;
YTIItemSectionSupportedRenderers *firstObject = [contentsArray firstObject];
YTIElementRenderer *elementRenderer = firstObject.elementRenderer;
return isAdRenderer(elementRenderer, 2);
}];
[newArray removeObjectsAtIndexes:removeIndexes];
%orig(newArray.copy);
return newArray;
}
%hook YTInnerTubeCollectionViewController
- (void)displaySectionsWithReloadingSectionControllerByRenderer:(id)renderer {
NSMutableArray *sectionRenderers = [self valueForKey:@"_sectionRenderers"];
[self setValue:filteredArray(sectionRenderers) forKey:@"_sectionRenderers"];
%orig;
}
- (void)addSectionsFromArray:(NSArray <YTIItemSectionRenderer *> *)array {
%orig(filteredArray(array));
}
%end
%end
Expand Down

0 comments on commit c6fb04b

Please sign in to comment.