Skip to content

Instantly share code, notes, and snippets.

@pixelomer
Created September 22, 2019 13:36
Show Gist options
  • Save pixelomer/eb5ff0fc8f00c8f3aa7b4a358f116797 to your computer and use it in GitHub Desktop.
Save pixelomer/eb5ff0fc8f00c8f3aa7b4a358f116797 to your computer and use it in GitHub Desktop.
Incomplete tweak
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#define NSLog(args...) NSLog(@"[CleanTube] "args)
static NSString * const reuseIdentifier = @"CleanTubeCell";
@interface YTAsyncCollectionView : UICollectionView<UICollectionViewDataSource>
@property (nonatomic, retain) NSMutableArray<NSIndexPath *> *cleanIndexPaths;
@end
%hook YTAsyncCollectionView
%property (nonatomic, retain) NSMutableArray *cleanIndexPaths;
- (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths {
NSLog(@"Prefetching...");
for (NSIndexPath *ip in indexPaths) {
[self collectionView:collectionView cellForItemAtIndexPath:ip];
}
}
+ (YTAsyncCollectionView *)alloc {
YTAsyncCollectionView *orig = %orig;
orig.prefetchDataSource = self;
return orig;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = %orig;
NSLog(@"Searching inside cell (%@): %@", indexPath, cell);
if ((self.superview.class != %c(YTWatchNextView)) || indexPath.section != 5 || !cell) return cell;
// Here we go. We're going multiple layers down to get the comment text.
UIView *currentView = cell.contentView; // Collection View Content
currentView = currentView.subviews.firstObject; // Layer #1, ELMCellNode-View
currentView = currentView.subviews.firstObject; // Layer #2, ELMContainerNode-View
currentView = currentView.subviews.firstObject; // Layer #3, ELMContainerNode-View
currentView = currentView.subviews.firstObject; // Layer #4, ELMContainerNode-View
currentView = currentView.subviews.lastObject; // Layer #5, ELMContainerNode-View
currentView = currentView.subviews.lastObject; // Layer #6, ELMContainerNode-View
currentView = currentView.subviews.lastObject; // Layer #7, ELMContainerNode-View
currentView = currentView.subviews.lastObject; // Layer #8, ELMExpandableTextNode-View
currentView = currentView.subviews.firstObject; // Layer #9, ELMTextNode-View
// The current view *should* contain the comment, so let's have a look at it
if (!currentView) return cell;
NSString *fullComment = currentView.accessibilityLabel;
NSLog(@"%@", fullComment);
if ([fullComment rangeOfString:@"20[0-9][0-9]" options:NSRegularExpressionSearch].location != NSNotFound) {
NSLog(@"Match");
static BOOL didRegisterCell = NO;
if (!didRegisterCell) {
didRegisterCell = YES;
[self registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
}
if (!self.cleanIndexPaths) {
self.cleanIndexPaths = [NSMutableArray new];
}
if (![self.cleanIndexPaths containsObject:indexPath]) {
[self.cleanIndexPaths addObject:indexPath];
}
cell = [self dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
}
return cell;
}
- (CGSize)collectionView:(id)view layout:(id)layout sizeForItemAtIndexPath:(NSIndexPath *)path {
return [self.cleanIndexPaths containsObject:path] ? ((CGSize){1,1}) : %orig;
}
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment