Skip to content

Commit

Permalink
v2.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dayanch96 committed Feb 21, 2024
1 parent f96d397 commit f7d567b
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ endif
DEBUG=0
FINALPACKAGE=1
ARCHS = arm64
PACKAGE_VERSION = 2.6.1
PACKAGE_VERSION = 2.6.2
TARGET := iphone:clang:latest:13.0

include $(THEOS)/makefiles/common.mk
Expand Down
2 changes: 1 addition & 1 deletion Settings.x
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static YTSettingsSectionItem *createSwitchItem(NSString *title, NSString *titleD
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
NSArray <YTSettingsSectionItem *> *rows = @[
createSwitchItem(LOC(@"CopyVideoInfo"), LOC(@"CopyVideoInfoDesc"), @"copyVideoInfo", &kCopyVideoInfo, selfObject),
createSwitchItem(LOC(@"CopyPostText"), LOC(@"CopyPostTextDesc"), @"copyPostText", &kCopyPostText, selfObject),
createSwitchItem(LOC(@"PostManager"), LOC(@"PostManagerDesc"), @"postManager", &kPostManager, selfObject),
createSwitchItem(LOC(@"SavePostImage"), LOC(@"SavePostImageDesc"), @"savePostImage", &kSavePostImage, selfObject),
createSwitchItem(LOC(@"SaveProfilePhoto"), LOC(@"SaveProfilePhotoDesc"), @"saveProfilePhoto", &kSaveProfilePhoto, selfObject),
createSwitchItem(LOC(@"CopyCommentText"), LOC(@"CopyCommentTextDesc"), @"copyCommentText", &kCopyCommentText, selfObject),
Expand Down
10 changes: 8 additions & 2 deletions YTLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ BOOL kRemoveSubscriptions;
BOOL kRemoveUploads;
BOOL kRemoveLibrary;
BOOL kCopyVideoInfo;
BOOL kCopyPostText;
BOOL kPostManager;
BOOL kSavePostImage;
BOOL kSaveProfilePhoto;
BOOL kCopyCommentText;
Expand Down Expand Up @@ -289,14 +289,20 @@ int kPivotIndex;
@end

@interface ASDisplayNode : NSObject
@property (nonatomic, assign, readonly) UIViewController *closestViewController;
@property (atomic, assign, readonly) ASNodeAncestryEnumerator *supernodes;
@property (atomic, copy, readwrite) NSArray *yogaChildren;
@property (atomic) CALayer *layer;
@end

@interface ELMContainerNode : ASDisplayNode
@property (nonatomic, strong, readwrite) NSString *copiedComment;
@end

@interface ELMExpandableTextNode : ASDisplayNode
@property (atomic, assign, readonly) ASDisplayNode *currentTextNode;
@end

@interface ASNetworkImageNode : ASDisplayNode
@property (atomic, copy, readwrite) NSURL *URL;
@end
Expand All @@ -307,7 +313,7 @@ int kPivotIndex;

@interface _ASDisplayView : UIView
@property (nonatomic, strong, readwrite) ASDisplayNode *keepalive_node;
- (void)copyText:(UILongPressGestureRecognizer *)sender;
- (void)postManager:(UILongPressGestureRecognizer *)sender;
- (void)saveImage:(UILongPressGestureRecognizer *)sender;
- (void)savePFP:(UILongPressGestureRecognizer *)sender;
- (void)copyComment:(UILongPressGestureRecognizer *)sender;
Expand Down
150 changes: 107 additions & 43 deletions YTLite.x
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,8 @@ static BOOL isOverlayShown = YES;
- (void)didLoad {
%orig;

ASTextNode *textNode = (ASTextNode *)self;

if (kCopyCommentText && [[self valueForKey:@"_accessibilityIdentifier"] isEqualToString:@"id.comment.content.label"]) {
ASTextNode *textNode = (ASTextNode *)self;
NSString *comment = textNode.attributedText.string;

NSMutableArray *allObjects = self.supernodes.allObjects;
Expand All @@ -658,15 +657,77 @@ static BOOL isOverlayShown = YES;
}
}
}

if (kPostManager && [self isKindOfClass:NSClassFromString(@"ELMExpandableTextNode")]) {
ELMExpandableTextNode *expandableTextNode = (ELMExpandableTextNode *)self;
ASTextNode *textNode = (ASTextNode *)expandableTextNode.currentTextNode;

NSString *text = textNode.attributedText.string;

NSMutableArray *allObjects = self.supernodes.allObjects;
for (ELMContainerNode *containerNode in allObjects) {
if ([containerNode.description containsString:@"id.ui.backstage.original_post"] && text) {
containerNode.copiedComment = text;
break;
}
}
}
}
%end

static void downloadImageFromURL(UIResponder *responder, NSURL *URL) {
NSString *URLString = URL.absoluteString;

if (kFixAlbums && [URLString hasPrefix:@"https://yt3."]) {
URLString = [URLString stringByReplacingOccurrencesOfString:@"https://yt3." withString:@"https://yt4."];
}

NSURL *downloadURL = nil;
if ([URLString containsString:@"c-fcrop"]) {
NSRange croppedURL = [URLString rangeOfString:@"c-fcrop"];
if (croppedURL.location != NSNotFound) {
NSString *newURL = [URLString stringByReplacingOccurrencesOfString:[URLString substringFromIndex:croppedURL.location] withString:@"nd-v1"];
downloadURL = [NSURL URLWithString:newURL];
}
} else {
downloadURL = URL;
}

NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:downloadURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (data) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];
[request addResourceWithType:PHAssetResourceTypePhoto data:data options:nil];
} completionHandler:^(BOOL success, NSError *error) {
[[%c(YTToastResponderEvent) eventWithMessage:success ? LOC(@"Saved") : [NSString stringWithFormat:LOC(@"%@: %@"), LOC(@"Error"), error.localizedDescription] firstResponder:responder] send];
}];
} else {
[[%c(YTToastResponderEvent) eventWithMessage:[NSString stringWithFormat:LOC(@"%@: %@"), LOC(@"Error"), error.localizedDescription] firstResponder:responder] send];
}
}] resume];
}

static void genImageFromLayer(CALayer *layer, UIColor *backgroundColor, void (^completionHandler)(UIImage *)) {
UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, backgroundColor.CGColor);
CGContextFillRect(context, CGRectMake(0, 0, layer.frame.size.width, layer.frame.size.height));
[layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

if (completionHandler) {
completionHandler(image);
}
}

%hook _ASDisplayView
- (void)setKeepalive_node:(id)arg1 {
%orig;

NSArray *gesturesInfo = @[
@{@"selector": @"copyText:", @"text": @"ELMExpandableTextNode-View", @"key": @(kCopyPostText)},
@{@"selector": @"postManager:", @"text": @"id.ui.backstage.original_post", @"key": @(kPostManager)},
@{@"selector": @"saveImage:", @"text": @"YTImageZoomNode-View", @"key": @(kSavePostImage)},
@{@"selector": @"savePFP:", @"text": @"ELMImageNode-View", @"key": @(kSaveProfilePhoto)},
@{@"selector": @"copyComment:", @"text": @"id.ui.comment_cell", @"key": @(kCopyCommentText)}
Expand Down Expand Up @@ -713,13 +774,46 @@ static BOOL isOverlayShown = YES;
}

%new
- (void)copyText:(UILongPressGestureRecognizer *)sender {
- (void)postManager:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
[UIPasteboard generalPasteboard].string = self.accessibilityLabel;
ELMContainerNode *nodeForLayer = (ELMContainerNode *)self.keepalive_node.yogaChildren[0];
ELMContainerNode *containerNode = (ELMContainerNode *)self.keepalive_node;
NSString *text = containerNode.copiedComment;
CALayer *layer = nodeForLayer.layer;
UIColor *backgroundColor = containerNode.closestViewController.view.backgroundColor;

UIResponder *responder = self.nextResponder;
while (responder && ![responder isKindOfClass:[UIViewController class]]) responder = responder.nextResponder;
if (responder) [[%c(YTToastResponderEvent) eventWithMessage:LOC(@"Copied") firstResponder:responder] send];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:LOC(@"SelectAction") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
alertController.view.tintColor = [UIColor labelColor];

[alertController addAction:[UIAlertAction actionWithTitle:LOC(@"CopyPostText") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (text) {
[UIPasteboard generalPasteboard].string = text;
[[%c(YTToastResponderEvent) eventWithMessage:LOC(@"Copied") firstResponder:containerNode.closestViewController] send];
}
}]];

[alertController addAction:[UIAlertAction actionWithTitle:LOC(@"SavePostAsImage") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
genImageFromLayer(layer, backgroundColor, ^(UIImage *image) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAssetFromImage:image];
request.creationDate = [NSDate date];
} completionHandler:^(BOOL success, NSError *error) {
NSString *message = success ? LOC(@"Saved") : [NSString stringWithFormat:LOC(@"%@: %@"), LOC(@"Error"), error.localizedDescription];
[[%c(YTToastResponderEvent) eventWithMessage:message firstResponder:containerNode.closestViewController] send];
}];
});
}]];

[alertController addAction:[UIAlertAction actionWithTitle:LOC(@"CopyPostAsImage") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
genImageFromLayer(layer, backgroundColor, ^(UIImage *image) {
[UIPasteboard generalPasteboard].image = image;
[[%c(YTToastResponderEvent) eventWithMessage:LOC(@"Copied") firstResponder:containerNode.closestViewController] send];
});
}]];

[alertController addAction:[UIAlertAction actionWithTitle:LOC(@"Cancel") style:UIAlertActionStyleCancel handler:nil]];

[containerNode.closestViewController presentViewController:alertController animated:YES completion:nil];
}
}

Expand All @@ -729,41 +823,11 @@ static BOOL isOverlayShown = YES;

ASNetworkImageNode *imageNode = (ASNetworkImageNode *)self.keepalive_node;
NSURL *imageURL = imageNode.URL;
if (imageURL) {
NSString *URLString = imageURL.absoluteString;

if (kFixAlbums && [URLString hasPrefix:@"https://yt3."]) {
URLString = [URLString stringByReplacingOccurrencesOfString:@"https://yt3." withString:@"https://yt4."];
}

NSURL *downloadURL = nil;
if ([URLString containsString:@"c-fcrop"]) {
NSRange croppedURL = [URLString rangeOfString:@"c-fcrop"];
if (croppedURL.location != NSNotFound) {
NSString *newURL = [URLString stringByReplacingOccurrencesOfString:[URLString substringFromIndex:croppedURL.location] withString:@"nd-v1"];
downloadURL = [NSURL URLWithString:newURL];
}
} else {
downloadURL = imageURL;
}

UIResponder *responder = self.nextResponder;
while (responder && ![responder isKindOfClass:[UIViewController class]]) responder = responder.nextResponder;
UIResponder *responder = self.nextResponder;
while (responder && ![responder isKindOfClass:[UIViewController class]]) responder = responder.nextResponder;

NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:downloadURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (data) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];
[request addResourceWithType:PHAssetResourceTypePhoto data:data options:nil];
} completionHandler:^(BOOL success, NSError *error) {
if (responder) [[%c(YTToastResponderEvent) eventWithMessage:success ? LOC(@"Saved") : [NSString stringWithFormat:LOC(@"%@: %@"), LOC(@"Error"), error.localizedDescription] firstResponder:responder] send];
}];
} else {
if (responder) [[%c(YTToastResponderEvent) eventWithMessage:[NSString stringWithFormat:LOC(@"%@: %@"), LOC(@"Error"), error.localizedDescription] firstResponder:responder] send];
}
}] resume];
}
if (imageURL) downloadImageFromURL(responder, imageURL);
}
}

Expand Down Expand Up @@ -1067,7 +1131,7 @@ static void reloadPrefs() {
kRemoveUploads = (prefs[@"removeUploads"] != nil) ? [prefs[@"removeUploads"] boolValue] : YES;
kRemoveLibrary = [prefs[@"removeLibrary"] boolValue] ?: NO;
kCopyVideoInfo = [prefs[@"copyVideoInfo"] boolValue] ?: NO;
kCopyPostText = [prefs[@"copyPostText"] boolValue] ?: NO;
kPostManager = [prefs[@"postManager"] boolValue] ?: NO;
kSavePostImage = [prefs[@"savePostImage"] boolValue] ?: NO;
kSaveProfilePhoto = [prefs[@"savePostImage"] boolValue] ?: NO;
kCopyCommentText = [prefs[@"copyCommentText"] boolValue] ?: NO;
Expand Down Expand Up @@ -1153,7 +1217,7 @@ static void reloadPrefs() {
@"removeUploads" : @(kRemoveUploads),
@"removeLibrary" : @(kRemoveLibrary),
@"copyVideoInfo" : @(kCopyVideoInfo),
@"copyPostText" : @(kCopyPostText),
@"postManager" : @(kPostManager),
@"savePostImage" : @(kSavePostImage),
@"saveProfilePhoto" : @(kSaveProfilePhoto),
@"copyCommentText" : @(kCopyCommentText),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
"Other" = "Other";
"CopyVideoInfo" = "Copy video information";
"CopyVideoInfoDesc" = "Adds button to copy video title and description into Video Description panel.";
"CopyPostText" = "Copy community posts text";
"CopyPostTextDesc" = "Copies community posts text to the clipboard by long tap.";
"PostManager" = "Save post information";
"PostManagerDesc" = "Allows to copy post text and save post as image by long tap.";
"SavePostImage" = "Save image from community posts";
"SavePostImageDesc" = "Saves community post image to the Photos app by long tap.";
"SaveProfilePhoto" = "Save profile picture";
Expand Down Expand Up @@ -206,6 +206,9 @@
"SelectAction" = "Select action";
"CopyTitle" = "Copy title";
"CopyDescription" = "Copy description";
"CopyPostText" = "Copy post text";
"SavePostAsImage" = "Save post as image";
"CopyPostAsImage" = "Copy post as image";
"Cancel" = "Cancel";
"Copied" = "Copied to clipboard";
"Saved" = "Saved to Photos";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
"Other" = "Otro";
"CopyVideoInfo" = "Copy video information";
"CopyVideoInfoDesc" = "Adds button to copy video title and description into Video Description panel.";
"CopyPostText" = "Copia el texto de las publicaciones de la comunidad";
"CopyPostTextDesc" = "Copia el texto de los posts de la comunidad al portapapeles mediante pulsación larga";
"PostManager" = "Save post information";
"PostManagerDesc" = "Allows to copy post text and save post as image by long tap.";
"SavePostImage" = "Guardar imagen de las entradas de la comunidad";
"SavePostImageDesc" = "Guarda la imagen de las publicaciones de la comunidad en la aplicación Fotos con un toque prolongado";
"SaveProfilePhoto" = "Guardar foto de perfil";
Expand Down Expand Up @@ -206,6 +206,9 @@
"SelectAction" = "Select action";
"CopyTitle" = "Copy title";
"CopyDescription" = "Copy description";
"CopyPostText" = "Copy post text";
"SavePostAsImage" = "Save post as image";
"CopyPostAsImage" = "Copy post as image";
"Cancel" = "Cancel";
"Copied" = "Copiado al portapapeles";
"Done" = "Done";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
"Other" = "Autre";
"CopyVideoInfo" = "Copier les informations vidéo";
"CopyVideoInfoDesc" = "Ajout d'un bouton permettant de copier le titre et la description de la vidéo dans le panneau Description de la vidéo.";
"CopyPostText" = "Copier le texte des publications de la communauté";
"CopyPostTextDesc" = "Copie le texte des publications de la communauté dans le presse-papiers en appuyant longuement.";
"PostManager" = "Save post information";
"PostManagerDesc" = "Allows to copy post text and save post as image by long tap.";
"SavePostImage" = "Enregistrer l'image des publications de la communauté";
"SavePostImageDesc" = "Enregistre l'image des publications de la communauté dans l'application Photos en appuyant longuement.";
"SaveProfilePhoto" = "Enregistrer la photo de profil";
Expand Down Expand Up @@ -206,6 +206,9 @@
"SelectAction" = "Sélectionner une action";
"CopyTitle" = "Copier le titre";
"CopyDescription" = "Copier la description";
"CopyPostText" = "Copy post text";
"SavePostAsImage" = "Save post as image";
"CopyPostAsImage" = "Copy post as image";
"Cancel" = "Annuler";
"Copied" = "Copié dans le presse-papiers";
"Saved" = "Enregistré dans Photos";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
"Other" = "その他";
"CopyVideoInfo" = "Copy video information";
"CopyVideoInfoDesc" = "Adds button to copy video title and description into Video Description panel.";
"CopyPostText" = "Copy community posts text";
"CopyPostTextDesc" = "Copies community posts text to the clipboard by long tap.";
"PostManager" = "Save post information";
"PostManagerDesc" = "Allows to copy post text and save post as image by long tap.";
"SavePostImage" = "Save community posts image";
"SavePostImageDesc" = "Saves community posts image to the Photos app by long tap.";
"SaveProfilePhoto" = "Save profile picture";
Expand Down Expand Up @@ -206,6 +206,9 @@
"SelectAction" = "Select action";
"CopyTitle" = "Copy title";
"CopyDescription" = "Copy description";
"CopyPostText" = "Copy post text";
"SavePostAsImage" = "Save post as image";
"CopyPostAsImage" = "Copy post as image";
"Cancel" = "Cancel";
"Copied" = "Copied to clipboard";
"Saved" = "Saved to Photos";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
"Other" = "Другие настройки";
"CopyVideoInfo" = "Копировать информацию о видео";
"CopyVideoInfoDesc" = "Добавляет кнопку для копирования названия и описания видео в панель описания видео.";
"CopyPostText" = "Копировать текст постов";
"CopyPostTextDesc" = "Копирует текст постов в буфер обмена долгим нажатием.";
"PostManager" = "Сохранять информацию с постов";
"PostManagerDesc" = "Позволяет скопировать текст из поста или сохранить пост как фото долгим нажатием по нему.";
"SavePostImage" = "Сохранять изображения постов";
"SavePostImageDesc" = "Сохраняет изображения постов в «Фото» долгим нажатием по ним.";
"SaveProfilePhoto" = "Сохранять фото профиля";
Expand Down Expand Up @@ -206,6 +206,9 @@
"SelectAction" = "Выберите действие";
"CopyTitle" = "Скопировать название";
"CopyDescription" = "Скопировать описание";
"CopyPostText" = "Копировать текст поста";
"SavePostAsImage" = "Сохранить пост как фото";
"CopyPostAsImage" = "Скопировать пост как фото";
"Cancel" = "Отмена";
"Copied" = "Скопировано в буфер обмена";
"Saved" = "Сохранено в Фото";
Expand Down
Loading

0 comments on commit f7d567b

Please sign in to comment.