Browse Source

Style and prefs loading improvements

master
lint 3 years ago
parent
commit
a7b11813d0
18 changed files with 902 additions and 1012 deletions
  1. +4
    -4
      tweak/AlienBlue.h
  2. +50
    -63
      tweak/AlienBlue.xm
  3. +9
    -9
      tweak/Antenna.h
  4. +60
    -73
      tweak/Antenna.xm
  5. +14
    -14
      tweak/Apollo.h
  6. +111
    -121
      tweak/Apollo.xm
  7. +6
    -6
      tweak/BaconReader.h
  8. +58
    -71
      tweak/BaconReader.xm
  9. +2
    -2
      tweak/Beam.h
  10. +70
    -83
      tweak/Beam.xm
  11. +51
    -63
      tweak/Narwhal.h
  12. +61
    -74
      tweak/Narwhal.xm
  13. +38
    -37
      tweak/Reddit.h
  14. +185
    -199
      tweak/Reddit.xm
  15. +17
    -17
      tweak/Slide.h
  16. +153
    -165
      tweak/Slide.xm
  17. +4
    -2
      tweak/assets/TFHelper.h
  18. +9
    -9
      tweak/assets/TFHelper.m

+ 4
- 4
tweak/AlienBlue.h View File

@@ -29,7 +29,7 @@
@end

@interface CommentsViewController
-(void) respondToStyleChange;
- (void)respondToStyleChange;
@end

@interface CommentPostHeaderNode
@@ -47,15 +47,15 @@
@property(assign, nonatomic) BOOL isPostHeader;
@property(strong, nonatomic) id delegate;
@property(strong, nonatomic) id node;
-(void) addButton:(id) arg1;
- (void)addButton:(id)arg1;
@end

/* -- Other Interfaces -- */

@interface MarkupEngine
+(id) markDownHTML:(id) arg1 forSubreddit:(id) arg2;
+ (id)markDownHTML:(id)arg1 forSubreddit:(id)arg2;
@end

@interface Resources
+(BOOL) isNight;
+ (BOOL)isNight;
@end

+ 50
- 63
tweak/AlienBlue.xm View File

@@ -3,6 +3,7 @@
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"

static BOOL isEnabled;
static BOOL isAlienBlueEnabled;
static BOOL isTFDeletedOnly;
static CGFloat pushshiftRequestTimeoutValue;
@@ -11,99 +12,99 @@ static CGFloat pushshiftRequestTimeoutValue;

%hook CommentOptionsDrawerView

-(id) initWithNode:(id) arg1 {
- (id)initWithNode:(id)arg1 {
id orig = %orig;
NSString *body;
if ([self isPostHeader]) {
body = [[arg1 post] selftext];
} else {
body = [[(CommentNode *)arg1 comment] body];
}
}
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:body isDeletedOnly:isTFDeletedOnly]){
CGSize refSize = [[self buttons][0] frame].size;

UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[undeleteButton setFrame:CGRectMake(0, 0, refSize.width, refSize.height)];
if ([self isPostHeader]){
[undeleteButton addTarget:self action:@selector(didTapPostUndeleteButton:) forControlEvents:UIControlEventTouchUpInside];
} else {
[undeleteButton addTarget:self action:@selector(didTapCommentUndeleteButton:) forControlEvents:UIControlEventTouchUpInside];
}
if ([%c(Resources) isNight]) {
[undeleteButton setImage:[UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"] forState:UIControlStateNormal];
} else {
[undeleteButton setImage:[UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160light.png"] forState:UIControlStateNormal];
}
undeleteButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
undeleteButton.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
[self addButton:undeleteButton];
}
return orig;
}

%new
-(void) didTapCommentUndeleteButton:(id) sender {
%new
- (void)didTapCommentUndeleteButton:(id)sender {
[sender setEnabled:NO];
id comment = [[self node] comment];
[%c(TFHelper) getUndeleteDataWithID:[comment ident] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}

%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
%new
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
id comment = [[self node] comment];
NSString *body = data[@"body"];
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[comment setAuthor:data[@"author"]];
[comment setBody:body];
[comment setBodyHTML:bodyHTML];
[[self delegate] respondToStyleChange];
[data[@"sender"] setEnabled:YES];
}

%new
-(void) didTapPostUndeleteButton:(id) sender {
%new
- (void)didTapPostUndeleteButton:(id)sender {
[sender setEnabled:NO];
id post = [[self node] post];
[%c(TFHelper) getUndeleteDataWithID:[post ident] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}

%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
- (void)completeUndeletePostAction:(NSDictionary *)data {
id post = [[self node] post];
id postComment = [[self node] comment]; //Don't know why he used a comment to store info about a post, but it exists
NSString *body = data[@"body"];
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[post setAuthor:data[@"author"]];
[post setSelftext:body];
[postComment setBodyHTML:bodyHTML];
[[self delegate] respondToStyleChange];
[data[@"sender"] setEnabled:YES];
}

@@ -114,32 +115,18 @@ static CGFloat pushshiftRequestTimeoutValue;

static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isAlienBlueEnabled"] != nil){
isAlienBlueEnabled = [[prefs objectForKey:@"isAlienBlueEnabled"] boolValue];
} else {
isAlienBlueEnabled = YES;
}
if ([prefs objectForKey:@"isTFDeletedOnly"] != nil){
isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
} else {
isTFDeletedOnly = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
isAlienBlueEnabled = [prefs objectForKey:@"isAlienBlueEnabled"] ? [[prefs objectForKey:@"isAlienBlueEnabled"] boolValue] : YES;
isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
} else {
isEnabled = YES;
isAlienBlueEnabled = YES;
isTFDeletedOnly = YES;
pushshiftRequestTimeoutValue = 10;
}
}
}

static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
@@ -149,14 +136,14 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin

%ctor {
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];

if ([processName isEqualToString:@"AlienBlue"]){
if (isAlienBlueEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
if ([processName isEqualToString:@"AlienBlue"]){
if (isAlienBlueEnabled && isEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(AlienBlue);
}
}

+ 9
- 9
tweak/Antenna.h View File

@@ -18,24 +18,24 @@
@interface RCCommentCell : NSObject
@property(strong, nonatomic) id comment;
-(void) updateWithModelObject:(id) arg1;
- (void)updateWithModelObject:(id)arg1;
@end
@interface RCPostCommentsController
@property(strong, nonatomic) id postCommentsCollector;
@property(strong, nonatomic) id delegate;
@property(strong, nonatomic) NSMutableDictionary *commentHeightCache;
-(void) controllerWillChangeContent:(id) arg1;
-(void) controllerDidChangeContent:(id) arg1;
-(void) controller:(id) arg1 didChange:(id) arg2 at:(id) arg3 for:(long long) arg4 newIndexPath:(id) arg5;
- (void)controllerWillChangeContent:(id)arg1;
- (void)controllerDidChangeContent:(id)arg1;
- (void)controller:(id)arg1 didChange:(id)arg2 at:(id)arg3 for:(long long)arg4 newIndexPath:(id)arg5;
//custom elements
-(void)handleUndeleteCommentAction;
- (void)handleUndeleteCommentAction;
@end
@interface AHKActionSheet
@property(strong, nonatomic) NSMutableArray *items;
-(void) addButtonWithTitle:(id) arg1 image:(id) arg2 type:(long long) arg3 handler:(id) arg4;
- (void)addButtonWithTitle:(id)arg1 image:(id)arg2 type:(long long)arg3 handler:(id)arg4;
@end
@interface AHKActionSheetItem
@@ -49,7 +49,7 @@
@property(strong, nonatomic) NSNumber *isSelf;
@property(strong, nonatomic) NSString *itemId;
@property(strong, nonatomic) id selfCommentText;
-(BOOL) isSelfPost;
- (BOOL)isSelfPost;
@end
@interface RCPostActionsSectionHeader : UIView
@@ -73,8 +73,8 @@
@interface RCPostHeaderCellController : NSObject
@property(strong, nonatomic) id post;
@property(strong, nonatomic) UITableView *tableView;
-(void) loadView;
- (void)loadView;
//custom elements
-(void) handleUndeletePostAction:(id) arg1;
- (void)handleUndeletePostAction:(id)arg1;
@end

+ 60
- 73
tweak/Antenna.xm View File

@@ -3,6 +3,7 @@
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isEnabled;
static BOOL isAntennaEnabled;
static BOOL isTFDeletedOnly;
static CGFloat pushshiftRequestTimeoutValue;
@@ -22,7 +23,7 @@ id tfAntennaCommentCell;
%hook RCCommentSwift
-(BOOL) isCommentDeleted{
- (BOOL)isCommentDeleted{
return NO;
}
@@ -31,44 +32,44 @@ id tfAntennaCommentCell;
%hook RCPostCommentsController
-(void) didLongPressCell:(id) arg1 gesture:(id) arg2 {
- (void)didLongPressCell:(id)arg1 gesture:(id)arg2 {
NSString *commentBody = [[[arg1 comment] commentText] body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
tfAntennaController = self;
tfAntennaCommentCell = arg1;
shouldHaveAntennaUndeleteAction = YES;
}
%orig;
shouldHaveAntennaUndeleteAction = NO;
}
%new
-(void) handleUndeleteCommentAction{
- (void)handleUndeleteCommentAction{
[%c(TFHelper) getUndeleteDataWithID:[[tfAntennaCommentCell comment] itemId] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
id comment = [tfAntennaCommentCell comment];
id commentText = [comment commentText];
NSString *body = data[@"body"];
[comment setAuthor:data[@"author"]];
[commentText setBody:body];
[commentText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[commentText setBodyAttributedString:nil];
[commentText setBodyAttributedStringForPreview:nil];
[commentText setTextHeightCache:nil];
[self setCommentHeightCache:nil];
[tfAntennaCommentCell updateWithModelObject:comment];
[[[self delegate] tableView] reloadData];
}
@@ -76,25 +77,25 @@ id tfAntennaCommentCell;
%end
%hook AHKActionSheet
%hook AHKActionSheet
- (void)show {
if (shouldHaveAntennaUndeleteAction) {
-(void)show{
if (shouldHaveAntennaUndeleteAction){
UIImage *undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
AHKActionSheetItem *actionItem = [self items][0];
CGSize actionItemImageSize = [[actionItem image] size];
CGSize newUndeleteImageSize = CGSizeMake(actionItemImageSize.width * 2, actionItemImageSize.height * 2);
UIGraphicsBeginImageContext(newUndeleteImageSize);
[undeleteImage drawInRect:CGRectMake(0, 0, newUndeleteImageSize.width, newUndeleteImageSize.height)];
undeleteImage = UIGraphicsGetImageFromCurrentImageContext();
undeleteImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
undeleteImage = [[UIImage alloc] initWithCGImage:[undeleteImage CGImage] scale:2 orientation:UIImageOrientationUp];
[self addButtonWithTitle:@"TF did that say?" image:undeleteImage type:0 handler:^{[tfAntennaController handleUndeleteCommentAction];}];
}
@@ -107,43 +108,43 @@ id tfAntennaCommentCell;
%hook RCPostActionsSectionHeader
%property(strong, nonatomic) UIButton *undeleteButton;
-(void) layoutSubviews{
- (void)layoutSubviews {
BOOL isAbleToUndeletePost = NO;
id post = [[self delegate] postInternal];
NSString *postBody = [[post selfCommentText] body];
if ([post isSelfPost]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
isAbleToUndeletePost = YES;
NSMutableArray *barButtons = [self defaultHeaderButtons];
if ([barButtons count] <= 5){
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
[barButtons addObject:tempView];
}
%orig;
if (![self undeleteButton]){
UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[undeleteButton addTarget:[[self delegate] headerCellController] action:@selector(handleUndeletePostAction:) forControlEvents:UIControlEventTouchUpInside];
[undeleteButton setImage:[[UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
undeleteButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
undeleteButton.tintColor = [barButtons[4] defaultColor];
[self addSubview:undeleteButton];
[self setUndeleteButton:undeleteButton];
}
[[self undeleteButton] setFrame:[barButtons[[barButtons count] - 1] frame]];
}
}
if (!isAbleToUndeletePost){
%orig;
}
@@ -155,32 +156,32 @@ id tfAntennaCommentCell;
%hook RCPostHeaderCellController
%new
-(void) handleUndeletePostAction:(id) sender{
- (void)handleUndeletePostAction:(id)sender {
[sender setEnabled:NO];
[%c(TFHelper) getUndeleteDataWithID:[[self post] itemId] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
- (void)completeUndeletePostAction:(NSDictionary *)data {
id post = [self post];
id postText = [post selfCommentText];
NSString *body = data[@"body"];
[post setAuthor:data[@"author"]];
[postText setBody:body];
[postText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[postText setBodyAttributedString:nil];
[postText setBodyAttributedStringForPreview:nil];
[postText setTextHeightCache:nil];
[self loadView];
[[self tableView] reloadData];
[data[@"sender"] setEnabled:YES];
}
@@ -191,32 +192,18 @@ id tfAntennaCommentCell;
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isAntennaEnabled"] != nil){
isAntennaEnabled = [[prefs objectForKey:@"isAntennaEnabled"] boolValue];
} else {
isAntennaEnabled = YES;
}
if ([prefs objectForKey:@"isTFDeletedOnly"] != nil){
isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
} else {
isTFDeletedOnly = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
isAntennaEnabled = [prefs objectForKey:@"isAntennaEnabled"] ? [[prefs objectForKey:@"isAntennaEnabled"] boolValue] : YES;
isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
} else {
isEnabled = YES;
isAntennaEnabled = YES;
isTFDeletedOnly = YES;
pushshiftRequestTimeoutValue = 10;
}
}
}
static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
@@ -226,14 +213,14 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
%ctor{
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"amrc"]){
if (isAntennaEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
if (isAntennaEnabled && isEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(Antenna, RCCommentSwift = objc_getClass("amrc.RCCommentSwift"), RCPostSwift = objc_getClass("amrc.RCPostSwift"), RCCommentTextSwift = objc_getClass("amrc.RCCommentTextSwift"));
}
}

+ 14
- 14
tweak/Apollo.h View File

@@ -17,14 +17,14 @@
@interface CommentCellNode
@property(assign,nonatomic)id view;
-(BOOL) isSelected;
-(void) _layoutSublayouts;
-(void) didLoad;
-(void) calculatedLayoutDidChange;
- (BOOL)isSelected;
- (void)_layoutSublayouts;
- (void)didLoad;
- (void)calculatedLayoutDidChange;
//custom elements
@property(strong,nonatomic) UIButton *undeleteButton;
-(void) undeleteCellWasSelected;
- (void)undeleteCellWasSelected;
@end
/* -- Post Interfaces -- */
@@ -33,7 +33,7 @@
@property(assign,nonatomic) NSString *selfText;
@property(assign,nonatomic) NSString *author;
@property(assign,nonatomic) NSString *fullName;
-(BOOL) isSelfPost;
- (BOOL)isSelfPost;
//custom elements
@property(strong, nonatomic) NSString *undeleteAuthor;
@@ -43,7 +43,7 @@
@property(assign,nonatomic) NSString *selfText;
@property(assign,nonatomic) NSString *author;
@property(assign,nonatomic) NSString *fullName;
-(BOOL) isSelfPost;
- (BOOL)isSelfPost;
//custom elements
@property(strong, nonatomic) NSString *undeleteAuthor;
@@ -58,18 +58,18 @@
//custom elements
@property(strong, nonatomic) id headerCellNode;
-(void) undeleteCellWasSelected;
- (void)undeleteCellWasSelected;
@end
/* -- Other Interfaces -- */
@interface MarkdownRenderer
+(id) attributedStringFromMarkdown:(id) arg1 withAttributes:(id) arg2;
+ (id)attributedStringFromMarkdown:(id)arg1 withAttributes:(id)arg2;
@end
@interface ActionController
-(id) tableView:(id) arg1 cellForRowAtIndexPath:(NSIndexPath *)arg2;
-(NSInteger) tableView:(id) arg1 numberOfRowsInSection:(NSInteger) arg2;
- (id)tableView:(id)arg1 cellForRowAtIndexPath:(NSIndexPath *)arg2;
- (NSInteger)tableView:(id)arg1 numberOfRowsInSection:(NSInteger)arg2;
@end
@interface UIImage (ios13)
@@ -88,7 +88,7 @@
@property(assign,nonatomic)id image;
@property(assign,nonatomic) CGRect frame;
@property(assign,nonatomic) id view;
-(CGRect)_frameInWindow;
- (CGRect)_frameInWindow;
@end
@interface ASTextNode
@@ -99,6 +99,6 @@
@interface ApolloButtonNode
@property(assign,nonatomic) ASTextNode *titleNode;
-(void) setAttributedTitle:(id) arg1 forState:(NSInteger) arg2;
-(id) attributedTitleForState:(NSInteger) arg1;
- (void) setAttributedTitle:(id)arg1 forState:(NSInteger)arg2;
- (id) attributedTitleForState:(NSInteger)arg1;
@end

+ 111
- 121
tweak/Apollo.xm View File

@@ -2,8 +2,9 @@
#import "Apollo.h"
#import "assets/TFHelper.h"
static BOOL isTFDeletedOnly;
static BOOL isEnabled;
static BOOL isApolloEnabled;
static BOOL isTFDeletedOnly;
static CGFloat pushshiftRequestTimeoutValue;
static BOOL shouldApolloHaveButton;
@@ -69,10 +70,10 @@ id apolloCommentController;
%hook MarkdownRenderer
+(id) attributedStringFromHTML:(id)arg1 attributes:(id) arg2 compact:(BOOL) arg3{
+ (id)attributedStringFromHTML:(id)arg1 attributes:(id)arg2 compact:(BOOL)arg3 {
apolloBodyAttributes = [arg2 copy];
return %orig;
}
@@ -81,72 +82,80 @@ id apolloCommentController;
%hook ActionController
-(id) tableView:(id) arg1 cellForRowAtIndexPath:(NSIndexPath *) arg2{
if (shouldAddUndeleteCell){
- (id) tableView:(id)arg1 cellForRowAtIndexPath:(NSIndexPath *)arg2 {
if (shouldAddUndeleteCell) {
if ([arg2 row] == [self tableView:arg1 numberOfRowsInSection:0] - 1){
id undeleteCell = [arg1 dequeueReusableCellWithIdentifier:@"IconActionCell" forIndexPath:arg2];
id prevCell = [arg1 dequeueReusableCellWithIdentifier:@"IconActionCell"];
UIImageView *prevCellImageView = MSHookIvar<UIImageView *>(prevCell, "iconImageView");
CGSize prevImageSize = [[prevCellImageView image] size];
UIImage *undeleteImage;
if (@available(iOS 13.0, *)){
UIImage *undeleteImage;
//if (@available(iOS 13.0, *)){
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0")) {
undeleteImage = [UIImage systemImageNamed:@"eye"];
if (!undeleteImage){
undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
} else {
CGSize squareSize = CGSizeMake(undeleteImage.size.width, undeleteImage.size.width);
UIGraphicsBeginImageContextWithOptions(squareSize, NO, 0);
[undeleteImage drawInRect:CGRectMake(0, (squareSize.height - undeleteImage.size.height) / 2, squareSize.width, undeleteImage.size.height)];
undeleteImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
} else {
undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
}
CGFloat undeleteImageSizeValue = prevImageSize.width > prevImageSize.height ? prevImageSize.width : prevImageSize.height;
if (undeleteImageSizeValue == 0){
if (undeleteImageSizeValue == 0) {
undeleteImageSizeValue = 25;
}
UIGraphicsBeginImageContextWithOptions(CGSizeMake(undeleteImageSizeValue, undeleteImageSizeValue), NO, 0);
[undeleteImage drawInRect:CGRectMake(0, 0, undeleteImageSizeValue, undeleteImageSizeValue)];
undeleteImage = [UIGraphicsGetImageFromCurrentImageContext() imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIGraphicsEndImageContext();
UILabel *undeleteLabel = MSHookIvar<UILabel *>(undeleteCell, "actionTitleLabel");
UIImageView *undeleteImageView = MSHookIvar<UIImageView *>(undeleteCell, "iconImageView");
undeleteLabel.text = @"TF Did That Say?";
undeleteImageView.image = undeleteImage;
return undeleteCell;
}
}
return %orig;
return %orig;
}
-(void) tableView:(id) arg1 didSelectRowAtIndexPath:(NSIndexPath *)arg2{
if (shouldAddUndeleteCell){
- (void)tableView:(id)arg1 didSelectRowAtIndexPath:(NSIndexPath *)arg2 {
if (shouldAddUndeleteCell) {
if ([arg2 row] == [self tableView:arg1 numberOfRowsInSection:0] - 1){
if (apolloCommentCell){
if (apolloCommentCell) {
[apolloCommentCell undeleteCellWasSelected];
} else {
[apolloCommentController undeleteCellWasSelected];
}
}
}
}
%orig;
}
-(NSInteger) tableView:(id) arg1 numberOfRowsInSection:(NSInteger) arg2{
- (NSInteger) tableView:(id)arg1 numberOfRowsInSection:(NSInteger)arg2 {
if (shouldAddUndeleteCell){
return %orig + 1;
} else {
@@ -154,10 +163,10 @@ id apolloCommentController;
}
}
-(id) animationControllerForDismissedController:(id) arg1{
- (id) animationControllerForDismissedController:(id)arg1 {
shouldAddUndeleteCell = NO;
return %orig;
}
@@ -167,53 +176,53 @@ id apolloCommentController;
%hook CommentCellNode
%property(strong,nonatomic) UIButton *undeleteButton;
-(void) moreOptionsTappedWithSender:(id) arg1{
- (void)moreOptionsTappedWithSender:(id)arg1 {
if (!shouldApolloHaveButton){
NSString *commentBody = [MSHookIvar<RKComment *>(self, "comment") body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
shouldAddUndeleteCell = YES;
apolloCommentCell = self;
apolloCommentController = nil;
}
}
}
%orig;
}
-(void) longPressedWithGestureRecognizer:(id) arg1{
- (void)longPressedWithGestureRecognizer:(id)arg1 {
if (!shouldApolloHaveButton){
NSString *commentBody = [MSHookIvar<RKComment *>(self, "comment") body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
shouldAddUndeleteCell = YES;
apolloCommentCell = self;
apolloCommentController = nil;
}
}
%orig;
}
-(void) didLoad {
- (void)didLoad {
%orig;
if (shouldApolloHaveButton){
NSString *commentBody = [MSHookIvar<RKComment *>(self, "comment") body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
CGFloat imageSize = 20.0f;
UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[undeleteButton addTarget:self action:@selector(didTapUndeleteButton:) forControlEvents:UIControlEventTouchUpInside];
undeleteButton.frame = CGRectMake(0, 0, imageSize, imageSize);
UIImage* undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
[undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
@@ -223,12 +232,12 @@ id apolloCommentController;
}
}
-(void) _layoutSublayouts{
- (void)_layoutSublayouts {
%orig;
if (shouldApolloHaveButton){
if ([self undeleteButton]){
CGFloat imageSize = 20.0f;
id moreNode = MSHookIvar<id>(self, "moreOptionsNode");
@@ -244,43 +253,43 @@ id apolloCommentController;
}
%new
-(void) didTapUndeleteButton:(id) sender{
- (void)didTapUndeleteButton:(id)sender {
[sender setEnabled:NO];
id comment = MSHookIvar<id>(self, "comment");
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) undeleteCellWasSelected{
- (void)undeleteCellWasSelected {
RKComment *comment = MSHookIvar<RKComment *>(self, "comment");
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
RKComment *comment = MSHookIvar<RKComment *>(self, "comment");
id bodyNode = MSHookIvar<id>(self, "bodyNode");
id authorNode = MSHookIvar<id>(self, "authorNode");
NSString *author = data[@"author"];
NSString *body = data[@"body"];
[comment setAuthor:author];
[comment setBody:body];
NSAttributedString *prevAuthorAttributedString = [authorNode attributedTitleForState:UIControlStateNormal];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString *newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[authorNode setAttributedTitle:newAuthorAttributedString forState:UIControlStateNormal];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]];
if ([data objectForKey:@"sender"]) {
[data[@"sender"] setEnabled:YES];
}
@@ -290,13 +299,13 @@ id apolloCommentController;
%hook CommentsViewController
%property(strong, nonatomic) id headerCellNode;
%property(strong, nonatomic) id headerCellNode;
- (void)moreOptionsBarButtonItemTappedWithSender:(id)arg1 {
-(void) moreOptionsBarButtonItemTappedWithSender:(id) arg1{
RKLink *post = MSHookIvar<RKLink *>(self, "link");
NSString *postBody = [post selfText];
if ([post isSelfPost]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
shouldAddUndeleteCell = YES;
@@ -304,35 +313,35 @@ id apolloCommentController;
apolloCommentController = self;
}
}
%orig;
}
%new
-(void) undeleteCellWasSelected{
- (void)undeleteCellWasSelected {
RKLink *post = MSHookIvar<RKLink *>(self, "link");
[%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
- (void)completeUndeletePostAction:(NSDictionary *)data {
RKLink *post = MSHookIvar<RKLink *>(self, "link");
id headerCellNode = [self headerCellNode];
id bodyNode = MSHookIvar<id>(headerCellNode, "bodyNode");
id postInfoNode = MSHookIvar<id>(headerCellNode, "postInfoNode");
id authorNode = MSHookIvar<id>(postInfoNode, "authorButtonNode");
NSString *author = data[@"author"];
NSString *authorTextString = [NSString stringWithFormat:@"by %@", author];
NSString *body = data[@"body"];
[post setUndeleteAuthor:author];
[post setSelfText:body];
NSAttributedString *prevAuthorAttributedString = [authorNode attributedTitleForState:UIControlStateNormal];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:authorTextString attributes:authorStringAttributes];
@@ -346,31 +355,31 @@ id apolloCommentController;
%hook CommentsHeaderCellNode
-(void) didLoad{
- (void)didLoad {
%orig;
[[self closestViewController] setHeaderCellNode:self];
}
-(void) _layoutSublayouts{
- (void)_layoutSublayouts {
%orig;
[[self closestViewController] setHeaderCellNode:self];
}
-(void) longPressedWithGestureRecognizer:(id) arg1{
- (void)longPressedWithGestureRecognizer:(id)arg1 {
RKLink *post = MSHookIvar<RKLink *>(self, "link");
NSString *postBody = [post selfText];
if ([post isSelfPost]){
if ([post isSelfPost]) {
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
shouldAddUndeleteCell = YES;
apolloCommentCell = nil;
apolloCommentController = self;
}
}
%orig;
}
@@ -381,39 +390,20 @@ id apolloCommentController;
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isApolloEnabled"] != nil) {
isApolloEnabled = [[prefs objectForKey:@"isApolloEnabled"] boolValue];
} else {
isApolloEnabled = YES;
}
if ([prefs objectForKey:@"isTFDeletedOnly"] != nil) {
isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
} else {
isTFDeletedOnly = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
if ([prefs objectForKey:@"shouldApolloHaveButton"] != nil){
shouldApolloHaveButton = [[prefs objectForKey:@"shouldApolloHaveButton"] boolValue];
} else {
shouldApolloHaveButton = NO;
}
if (prefs){
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
isApolloEnabled = [prefs objectForKey:@"isApolloEnabled"] ? [[prefs objectForKey:@"isApolloEnabled"] boolValue] : YES;
isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
shouldApolloHaveButton = [prefs objectForKey:@"shouldApolloHaveButton"] ? [[prefs objectForKey:@"shouldApolloHaveButton"] boolValue] : NO;
} else {
isEnabled = YES;
isApolloEnabled = YES;
isTFDeletedOnly = YES;
pushshiftRequestTimeoutValue = 10;
shouldApolloHaveButton = NO;
}
}
}
static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
@@ -423,14 +413,14 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
%ctor {
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"Apollo"]){
if (isApolloEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
if (isApolloEnabled && isEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(Apollo, CommentsHeaderCellNode = objc_getClass("Apollo.CommentsHeaderCellNode"), CommentCellNode = objc_getClass("Apollo.CommentCellNode"), ApolloButtonNode = objc_getClass("Apollo.ApolloButtonNode"), ActionController = objc_getClass("Apollo.ActionController"), IconActionTableViewCell = objc_getClass("Apollo.IconActionTableViewCell"), CommentsViewController = objc_getClass("Apollo.CommentsViewController"));
}
}

+ 6
- 6
tweak/BaconReader.h View File

@@ -1,7 +1,7 @@
/* -- Votable Interfaces -- */
@interface BRVotable
@interface BRVotable
@property(strong, nonatomic) NSString *serverID;
@property(strong, nonatomic) NSAttributedString *attributedDescriptionString;
@property(assign, nonatomic) CGSize cellSize;
@@ -39,7 +39,7 @@
@interface StoryDetailView
@property(strong, nonatomic) UITableView *tableView;
-(void) refreshTouched;
- (void)refreshTouched;
@end
@interface StoryDetailViewController
@@ -47,13 +47,13 @@
@property(strong, nonatomic) id detailPage;
//custom elements
-(void) handleUndeleteCommentAction;
-(void) handleUndeletePostAction;
- (void)handleUndeleteCommentAction;
- (void)handleUndeletePostAction;
@end
/* -- Other Interfaces -- */
@interface BRUtils
+(id) attributedDescriptionForComment:(id) arg1;
+(id) createAttributedStringFromHTML:(id) arg1 options:(id) arg2;
+ (id)attributedDescriptionForComment:(id)arg1;
+ (id)createAttributedStringFromHTML:(id)arg1 options:(id)arg2;
@end

+ 58
- 71
tweak/BaconReader.xm View File

@@ -3,6 +3,7 @@
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isEnabled;
static BOOL isBaconReaderEnabled;
static BOOL isTFDeletedOnly;
static CGFloat pushshiftRequestTimeoutValue;
@@ -28,19 +29,19 @@ id tfStoryController;
%hook BRComment
-(BOOL) contains_htmlValue{
- (BOOL)contains_htmlValue {
return YES;
}
}
-(BOOL) primitiveContains_htmlValue{
- (BOOL)primitiveContains_htmlValue {
return YES;
}
-(BOOL) is_deletedValue{
- (BOOL)is_deletedValue {
return NO;
}
-(BOOL) primitiveIs_deletedValue{
- (BOOL)primitiveIs_deletedValue {
return NO;
}
@@ -49,16 +50,16 @@ id tfStoryController;
%hook BRStory
+(id) storyWithDictionary:(id) arg1 inContext:(id) arg2 {
+ (id)storyWithDictionary:(id)arg1 inContext:(id)arg2 {
id orig = %orig;
if (tfPostSelftext){
if (tfPostSelftext) {
[orig setSelftext_html:tfPostSelftext];
[orig setAuthor:tfPostAuthor];
tfPostSelftext = nil;
tfPostAuthor = nil;
}
return orig;
}
@@ -67,21 +68,21 @@ id tfStoryController;
%hook UIViewController
-(void) presentViewController:(id) arg1 animated:(BOOL) arg2 completion:(id) arg3 {
if ([arg1 isKindOfClass:[UIAlertController class]] && shouldHaveBRUndeleteAction){
- (void)presentViewController:(id)arg1 animated:(BOOL)arg2 completion:(id)arg3 {
if ([arg1 isKindOfClass:[UIAlertController class]] && shouldHaveBRUndeleteAction) {
UIAlertAction *undeleteAction;
if (tfCommentCellView){
if (tfCommentCellView) {
undeleteAction = [UIAlertAction actionWithTitle:@"TF Did That Say?" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){[tfStoryController handleUndeleteCommentAction];}];
} else {
undeleteAction = [UIAlertAction actionWithTitle:@"TF Did That Say?" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){[tfStoryController handleUndeletePostAction];}];
}
[arg1 addAction:undeleteAction];
}
%orig;
}
@@ -90,76 +91,76 @@ id tfStoryController;
%hook StoryDetailViewController
-(void) showMoreCommentActions:(id) arg1 showAll:(BOOL) arg2 {
- (void)showMoreCommentActions:(id)arg1 showAll:(BOOL)arg2 {
NSString *commentBody = [[arg1 comment] body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]) {
shouldHaveBRUndeleteAction = YES;
tfCommentCellView = arg1;
tfStoryController = self;
tfPostSelftext = nil;
}
%orig;
shouldHaveBRUndeleteAction = NO;
}
-(void) menuTouchedWithSender:(id) arg1 {
if ([[self story] is_selfValue]){
- (void)menuTouchedWithSender:(id)arg1 {
if ([[self story] is_selfValue]) {
NSString *postBody = [[self story] selftext];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]) {
shouldHaveBRUndeleteAction = YES;
tfCommentCellView = nil;
tfStoryController = self;
tfPostSelftext = nil;
}
}
%orig;
shouldHaveBRUndeleteAction = NO;
}
%new
-(void) handleUndeleteCommentAction{
- (void)handleUndeleteCommentAction {
[%c(TFHelper) getUndeleteDataWithID:[[tfCommentCellView comment] serverID] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
id comment = [tfCommentCellView comment];
NSString *body = data[@"body"];
[comment setAuthor:data[@"author"]];
[comment setBody:body];
[comment setBody_html:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[comment setAttributedDescriptionString:nil];
NSAttributedString *commentAttrString = [%c(BRUtils) attributedDescriptionForComment:comment];
[comment setAttributedDescriptionString:commentAttrString];
[[[self detailPage] tableView] reloadData];
}
%new
-(void) handleUndeletePostAction{
- (void)handleUndeletePostAction {
[%c(TFHelper) getUndeleteDataWithID:[[self story] serverID] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
- (void)completeUndeletePostAction:(NSDictionary *)data {
tfPostAuthor = data[@"author"];
tfPostSelftext = [%c(MMMarkdown) HTMLStringWithMarkdown:data[@"body"] extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[[self detailPage] refreshTouched];
}
@@ -170,32 +171,18 @@ id tfStoryController;
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isBaconReaderEnabled"] != nil){
isBaconReaderEnabled = [[prefs objectForKey:@"isBaconReaderEnabled"] boolValue];
} else {
isBaconReaderEnabled = YES;
}
if ([prefs objectForKey:@"isTFDeletedOnly"] != nil) {
isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
} else {
isTFDeletedOnly = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
isBaconReaderEnabled = [prefs objectForKey:@"isBaconReaderEnabled"] ? [[prefs objectForKey:@"isBaconReaderEnabled"] boolValue] : YES;
isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
} else {
isEnabled = YES;
isBaconReaderEnabled = YES;
isTFDeletedOnly = YES;
pushshiftRequestTimeoutValue = 10;
}
}
}
static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
@@ -205,15 +192,15 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
%ctor {
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"BaconReader"]){
if (isBaconReaderEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
if ([processName isEqualToString:@"BaconReader"]){
if (isBaconReaderEnabled && isEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(BaconReader, StoryDetailView = objc_getClass("BaconReader.StoryDetailView"), StoryDetailViewController = objc_getClass("BaconReader.StoryDetailViewController"), CommentCellView = objc_getClass("BaconReader.CommentCellView"), CommentCell = objc_getClass("BaconReader.CommentCell"));
}
}
}
}

+ 2
- 2
tweak/Beam.h View File

@@ -14,7 +14,7 @@
@property(strong, nonatomic) id authorButton;
@property(assign, nonatomic) BOOL isCollapsed;
@property(assign, nonatomic) BOOL commentDidChange;
-(void) reloadContents;
- (void)reloadContents;
//custom elements
@property(strong, nonatomic) UIButton *undeleteButton;
@@ -48,7 +48,7 @@
@end
@interface PostSelfTextPartCell
-(id) _viewControllerForAncestor;
- (id)_viewControllerForAncestor;
@end
@interface PostMetadataView

+ 70
- 83
tweak/Beam.xm View File

@@ -2,6 +2,7 @@
#import "Beam.h"
#import "assets/TFHelper.h"
static BOOL isEnabled;
static BOOL isBeamEnabled;
static BOOL isTFDeletedOnly;
static CGFloat pushshiftRequestTimeoutValue;
@@ -11,34 +12,34 @@ static CGFloat pushshiftRequestTimeoutValue;
%hook CommentCell
%property(strong, nonatomic) UIButton *undeleteButton;
-(void) layoutSubviews{
- (void)layoutSubviews {
%orig;
UIButton *undeleteButton = [self undeleteButton];
if (undeleteButton){
if ([self isCollapsed]){
if (undeleteButton) {
if ([self isCollapsed]) {
[undeleteButton setHidden:YES];
} else {
[undeleteButton setHidden:NO];
}
} else {
NSString *commentBody = [[self comment] content];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]) {
CGFloat authorTextHeight = [[self authorButton] frame].size.height;
undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[undeleteButton addTarget:self action:@selector(handleUndeleteCommentAction:) forControlEvents:UIControlEventTouchUpInside];
[undeleteButton setImage:[UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"] forState:UIControlStateNormal];
undeleteButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
undeleteButton.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
undeleteButton.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - authorTextHeight - 5, 5, authorTextHeight, authorTextHeight);
[[self commentContentView] addSubview:undeleteButton];
[self setUndeleteButton:undeleteButton];
}
@@ -46,26 +47,26 @@ static CGFloat pushshiftRequestTimeoutValue;
}
%new
-(void) handleUndeleteCommentAction:(id) sender{
- (void)handleUndeleteCommentAction:(id)sender {
[sender setEnabled:NO];
[%c(TFHelper) getUndeleteDataWithID:[[self comment] identifier] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
id comment = [self comment];
[comment setAuthor:data[@"author"]];
[comment setContent:data[@"body"]];
[comment setMarkdownString:nil];
[self setCommentDidChange:YES];
[self reloadContents];
[[MSHookIvar<id>(self, "delegate") tableView] reloadData];
[data[@"sender"] setEnabled:YES];
}
@@ -74,13 +75,13 @@ static CGFloat pushshiftRequestTimeoutValue;
%hook PostSelfTextPartCell
-(void) setSelected:(BOOL) arg1 animated:(BOOL) arg2{
- (void)setSelected:(BOOL)arg1 animated:(BOOL)arg2{
%orig;
id postViewController = [self _viewControllerForAncestor];
if ([postViewController isMemberOfClass:objc_getClass("beam.PostDetailEmbeddedViewController")]){
if ([postViewController isMemberOfClass:objc_getClass("beam.PostDetailEmbeddedViewController")]) {
[postViewController setSelfTextView:self];
[postViewController setPost:[self post]];
}
@@ -91,12 +92,12 @@ static CGFloat pushshiftRequestTimeoutValue;
%hook PostMetadataView
-(void) layoutSubviews{
- (void)layoutSubviews {
%orig;
id postViewController = MSHookIvar<id>(self, "delegate");
if ([postViewController isMemberOfClass:objc_getClass("beam.PostDetailEmbeddedViewController")]){
if ([postViewController isMemberOfClass:objc_getClass("beam.PostDetailEmbeddedViewController")]) {
[postViewController setMetadataView:self];
}
}
@@ -107,28 +108,28 @@ static CGFloat pushshiftRequestTimeoutValue;
%hook PostToolbarView
%property(strong, nonatomic) UIButton *undeleteButton;
-(void) layoutSubviews{
- (void)layoutSubviews {
%orig;
if (![self undeleteButton] && [[[self post] isSelfText] boolValue] && [MSHookIvar<id>(self, "delegate") isMemberOfClass:objc_getClass("beam.PostDetailEmbeddedViewController")]){
if (![self undeleteButton] && [[[self post] isSelfText] boolValue] && [MSHookIvar<id>(self, "delegate") isMemberOfClass:objc_getClass("beam.PostDetailEmbeddedViewController")]) {
NSString *postBody = [[self post] content];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]) {
id moreButton = MSHookIvar<id>(self, "moreButton");
CGFloat buttonHeight = [moreButton frame].size.height;
UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[undeleteButton addTarget:MSHookIvar<id>(self, "delegate") action:@selector(handleUndeletePostAction:) forControlEvents:UIControlEventTouchUpInside];
[undeleteButton setImage:[UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"] forState:UIControlStateNormal];
undeleteButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
undeleteButton.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
undeleteButton.frame = CGRectMake([moreButton frame].origin.x - buttonHeight, 1, buttonHeight, buttonHeight);
[self addSubview:undeleteButton];
[self setUndeleteButton:undeleteButton];
}
@@ -143,37 +144,37 @@ static CGFloat pushshiftRequestTimeoutValue;
%property(strong, nonatomic) id post;
%new
-(void) handleUndeletePostAction:(id) sender{
- (void)handleUndeletePostAction:(id)sender {
[sender setEnabled:NO];
id post = [self post];
if (post){
[%c(TFHelper) getUndeleteDataWithID:[post identifier] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
- (void)completeUndeletePostAction:(NSDictionary *)data {
id post = [self post];
[post setAuthor:data[@"author"]];
[post setContent:data[@"body"]];
[post setMarkdownString:nil];
if ([self selfTextView]){
if ([self selfTextView]) {
[[self selfTextView] reloadContents];
}
if ([self metadataView]){
if ([self metadataView]) {
[[self metadataView] setPost:post];
}
[[self tableView] reloadData];
[data[@"sender"] setEnabled:YES];
}
@@ -184,32 +185,18 @@ static CGFloat pushshiftRequestTimeoutValue;
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isBeamEnabled"] != nil){
isBeamEnabled = [[prefs objectForKey:@"isBeamEnabled"] boolValue];
} else {
isBeamEnabled = YES;
}
if ([prefs objectForKey:@"isTFDeletedOnly"] != nil) {
isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
} else {
isTFDeletedOnly = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
isBeamEnabled = [prefs objectForKey:@"isBeamEnabled"] ? [[prefs objectForKey:@"isBeamEnabled"] boolValue] : YES;
isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
} else {
isEnabled = YES;
isBeamEnabled = YES;
isTFDeletedOnly = YES;
pushshiftRequestTimeoutValue = 10;
}
}
}
static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
@@ -219,14 +206,14 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
%ctor{
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"beam"]){
if (isBeamEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
if ([processName isEqualToString:@"beam"]){
if (isBeamEnabled && isEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(Beam, CommentCell = objc_getClass("beam.CommentCell"), PostDetailEmbeddedViewController = objc_getClass("beam.PostDetailEmbeddedViewController"), PostToolbarView = objc_getClass("beam.PostToolbarView"), PostSelfTextPartCell = objc_getClass("beam.PostSelfTextPartCell"), PostMetadataView = objc_getClass("beam.PostMetadataView"));
}
}

+ 51
- 63
tweak/Narwhal.h View File

@@ -7,13 +7,13 @@
@property(assign,nonatomic) NSString* body;
@property(assign,nonatomic) NSString* fullName;
-(BOOL) isSaved;
- (BOOL)isSaved;
@end
@interface NRTCommentsManager
@property(assign,nonatomic) NSMutableArray* comments;
-(void) updateComment:(id) arg1 fromEdited:(id) arg2;
- (void)updateComment:(id)arg1 fromEdited:(id)arg2;
@end
/* -- Post Interfaces -- */
@@ -24,14 +24,14 @@
@property(assign,nonatomic) NSString* fullName;
@end
@interface NRTLinkTitleCell
-(void) configureCellForLink:(id) arg1;
@interface NRTLinkTitleCell
- (void)configureCellForLink:(id)arg1;
@end
@interface NRTLinkTextCell
@property(assign,nonatomic) id bodyLabel;
-(void) configureCellForText:(id) arg1 links:(id) arg2;
- (void)configureCellForText:(id)arg1 links:(id)arg2;
@end
/* -- Other Interfaces -- */
@@ -39,11 +39,11 @@
@interface NRTAuthManager
@property(assign,nonatomic) NSString* currentUsername;
+(id) sharedManager;
+ (id)sharedManager;
@end
@interface NRTMarkdownManager
+(id) attributedStringFromMarkdown:(id) arg1 type:(id) arg2;
+ (id)attributedStringFromMarkdown:(id)arg1 type:(id)arg2;
@end
@interface NRTAttributedLabel
@@ -62,70 +62,58 @@
@property(assign,nonatomic) id linkText;
@property(assign,nonatomic) id tableView;
-(void) _handleActionSheetCopyCommentText:(id) arg1;
-(void) _handleActionSheetDeleteComment:(id) arg1;
-(void) _handleActionSheetDeletePost;
-(void) _handleActionSheetEditComment:(id) arg1;
-(void) _handleActionSheetEditPost;
-(void) _handleActionSheetOpenChrome;
-(void) _handleActionSheetOpenSafari;
-(void) _handleActionSheetPrivateMessage:(id) arg1;
-(void) _handleActionSheetRefreshComments;
-(void) _handleActionSheetRefreshPost;
-(void) _handleActionSheetReportComment:(id) arg1;
-(void) _handleActionSheetReportPost;
-(void) _handleActionSheetSaveComment:(id) arg1 index:(NSUInteger) arg2;
-(void) _handleActionSheetShareComment:(id) arg1;
-(void) _handleActionSheetShareLink;
-(void) _handleActionSheetSharePost;
-(void) _handleActionSheetSortComments;
-(void) _handleActionSheetUnsaveComment:(id) arg1 index:(NSUInteger) arg2;
-(void) _handleActionSheetViewParent:(id) arg1;
-(void) _handleActionSheetViewProfile:(id) arg1;
- (void)_handleActionSheetCopyCommentText:(id)arg1;
- (void)_handleActionSheetDeleteComment:(id)arg1;
- (void)_handleActionSheetDeletePost;
- (void)_handleActionSheetEditComment:(id)arg1;
- (void)_handleActionSheetEditPost;
- (void)_handleActionSheetOpenChrome;
- (void)_handleActionSheetOpenSafari;
- (void)_handleActionSheetPrivateMessage:(id)arg1;
- (void)_handleActionSheetRefreshComments;
- (void)_handleActionSheetRefreshPost;
- (void)_handleActionSheetReportComment:(id)arg1;
- (void)_handleActionSheetReportPost;
- (void)_handleActionSheetSaveComment:(id)arg1 index:(NSUInteger)arg2;
- (void)_handleActionSheetShareComment:(id)arg1;
- (void)_handleActionSheetShareLink;
- (void)_handleActionSheetSharePost;
- (void)_handleActionSheetSortComments;
- (void)_handleActionSheetUnsaveComment:(id)arg1 index:(NSUInteger)arg2;
- (void)_handleActionSheetViewParent:(id)arg1;
- (void)_handleActionSheetViewProfile:(id)arg1;
//custom elements
-(void) handleUndeleteAction:(id) arg1;
-(void) handleUndeletePostAction;
-(void) mainThreadTest:(id) arg1;
- (void) handleUndeleteAction:(id)arg1;
- (void) handleUndeletePostAction;
- (void) mainThreadTest:(id)arg1;
@end
@interface NRTMediaTableViewDataSource
@property(assign,nonatomic) id commentsManager;
@property(assign,nonatomic) id parentController;
-(void) _handleActionSheetCopyCommentText:(id) arg1;
-(void) _handleActionSheetDeleteComment:(id) arg1;
-(void) _handleActionSheetDeletePost;
-(void) _handleActionSheetEditComment:(id) arg1;
-(void) _handleActionSheetEditPost;
-(void) _handleActionSheetOpenChrome;
-(void) _handleActionSheetOpenSafari;
-(void) _handleActionSheetPrivateMessage:(id) arg1;
-(void) _handleActionSheetRefreshComments;
-(void) _handleActionSheetRefreshPost;
-(void) _handleActionSheetReportComment:(id) arg1;
-(void) _handleActionSheetReportPost;
-(void) _handleActionSheetSaveComment:(id) arg1 index:(NSUInteger) arg2;
-(void) _handleActionSheetShareComment:(id) arg1;
-(void) _handleActionSheetShareLink;
-(void) _handleActionSheetSharePost;
-(void) _handleActionSheetSortComments;
-(void) _handleActionSheetUnsaveComment:(id) arg1 index:(NSUInteger) arg2;
-(void) _handleActionSheetViewParent:(id) arg1;
-(void) _handleActionSheetViewProfile:(id) arg1;
- (void)_handleActionSheetCopyCommentText:(id)arg1;
- (void)_handleActionSheetDeleteComment:(id)arg1;
- (void)_handleActionSheetDeletePost;
- (void)_handleActionSheetEditComment:(id)arg1;
- (void)_handleActionSheetEditPost;
- (void)_handleActionSheetOpenChrome;
- (void)_handleActionSheetOpenSafari;
- (void)_handleActionSheetPrivateMessage:(id)arg1;
- (void)_handleActionSheetRefreshComments;
- (void)_handleActionSheetRefreshPost;
- (void)_handleActionSheetReportComment:(id)arg1;
- (void)_handleActionSheetReportPost;
- (void)_handleActionSheetSaveComment:(id)arg1 index:(NSUInteger)arg2;
- (void)_handleActionSheetShareComment:(id)arg1;
- (void)_handleActionSheetShareLink;
- (void)_handleActionSheetSharePost;
- (void)_handleActionSheetSortComments;
- (void)_handleActionSheetUnsaveComment:(id)arg1 index:(NSUInteger)arg2;
- (void)_handleActionSheetViewParent:(id)arg1;
- (void)_handleActionSheetViewProfile:(id)arg1;
//custom elements
-(void) handleUndeleteCommentAction:(id) comment;
- (void)handleUndeleteCommentAction:(id)comment;
@end

+ 61
- 74
tweak/Narwhal.xm View File

@@ -2,6 +2,7 @@
#import "Narwhal.h"
#import "assets/TFHelper.h"
static BOOL isEnabled;
static BOOL isNarwhalEnabled;
static BOOL isTFDeletedOnly;
static CGFloat pushshiftRequestTimeoutValue;
@@ -12,28 +13,28 @@ BOOL shouldHaveUndeleteAction = NO;
id tfComment;
id tfController;
void getUndeleteCommentData(id controller, id comment){
void getUndeleteCommentData(id controller, id comment){
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"comment" : comment} completionTarget:controller completionSelector:@selector(completeUndeleteCommentAction:)];
}
%hook UIViewController
-(void) presentViewController:(id) arg1 animated:(BOOL) arg2 completion:(id) arg3{
if ([arg1 isKindOfClass:[UIAlertController class]] && shouldHaveUndeleteAction){
- (void)presentViewController:(id)arg1 animated:(BOOL)arg2 completion:(id)arg3 {
if ([arg1 isKindOfClass:[UIAlertController class]] && shouldHaveUndeleteAction) {
UIAlertAction* undeleteAction;
if (tfComment){
if (tfComment) {
undeleteAction = [UIAlertAction actionWithTitle:@"tf did that say?" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){getUndeleteCommentData(tfController, tfComment);}];
} else {
undeleteAction = [UIAlertAction actionWithTitle:@"tf did that say?" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){[tfController handleUndeletePostAction];}];
}
[arg1 addAction:undeleteAction];
}
%orig;
}
@@ -42,75 +43,75 @@ void getUndeleteCommentData(id controller, id comment){
%hook NRTLinkViewController
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
- (void)swipeCell:(id)arg1 didEndDragWithState:(NSUInteger)arg2 {
if (arg2 == 2){
if (arg2 == 2) {
if ([arg1 isKindOfClass:[%c(NRTCommentTableViewCell) class]]) {
NSString *commentBody = MSHookIvar<NSString*>([arg1 comment], "_body");
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
tfComment = [arg1 comment];
tfController = self;
shouldHaveUndeleteAction = YES;
}
}
}
}
}
%orig;
shouldHaveUndeleteAction = NO;
}
-(void) _dotsButtonTouched:(id) arg1{
if ([self linkTextOffscreenCell]){
- (void)_dotsButtonTouched:(id)arg1 {
if ([self linkTextOffscreenCell]) {
NSString *postBody = [[self link] selfText];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]) {
tfController = self;
tfComment = nil;
shouldHaveUndeleteAction = YES;
}
}
%orig;
shouldHaveUndeleteAction = NO;
}
%new
-(void) handleUndeletePostAction{
- (void)handleUndeletePostAction {
id post = [self link];
[%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"post" : post} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
%new
- (void)completeUndeletePostAction:(NSDictionary *)data {
id post = data[@"post"];
MSHookIvar<NSString*>(post, "_author") = data[@"author"];
NSAttributedString* postBodyAttributedString = [%c(NRTMarkdownManager) attributedStringFromMarkdown:data[@"body"] type:0];
[self setLinkText:postBodyAttributedString];
[[self tableView] reloadData];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
id comment = data[@"comment"];
if (comment){
if (comment) {
MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
[[self commentsManager] updateComment:comment fromEdited:comment];
}
}
@@ -120,36 +121,36 @@ void getUndeleteCommentData(id controller, id comment){
%hook NRTMediaTableViewDataSource
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
- (void)swipeCell:(id)arg1 didEndDragWithState:(NSUInteger)arg2 {
if (arg2 == 2){
if (arg2 == 2) {
if ([arg1 isKindOfClass:[%c(NRTCommentTableViewCell) class]]) {
NSString *commentBody = MSHookIvar<NSString*>([arg1 comment], "_body");
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]) {
tfComment = [arg1 comment];
tfController = self;
shouldHaveUndeleteAction = YES;
}
}
}
}
}
%orig;
shouldHaveUndeleteAction = NO;
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
id comment = data[@"comment"];
if (comment){
if (comment) {
MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
[[self commentsManager] updateComment:comment fromEdited:comment];
}
}
@@ -161,32 +162,18 @@ void getUndeleteCommentData(id controller, id comment){
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isNarwhalEnabled"] != nil){
isNarwhalEnabled = [[prefs objectForKey:@"isNarwhalEnabled"] boolValue];
} else {
isNarwhalEnabled = YES;
}
if ([prefs objectForKey:@"isTFDeletedOnly"] != nil) {
isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
} else {
isTFDeletedOnly = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
isNarwhalEnabled = [prefs objectForKey:@"isNarwhalEnabled"] ? [[prefs objectForKey:@"isNarwhalEnabled"] boolValue] : YES;
isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
} else {
isEnabled = YES;
isNarwhalEnabled = YES;
isTFDeletedOnly = YES;
pushshiftRequestTimeoutValue = 10;
}
}
}
static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
@@ -196,14 +183,14 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
%ctor {
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];

if ([processName isEqualToString:@"narwhal"]){
if (isNarwhalEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
if ([processName isEqualToString:@"narwhal"]){
if (isNarwhalEnabled && isEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(Narwhal);
}
}

+ 38
- 37
tweak/Reddit.h View File

@@ -3,7 +3,7 @@
/* -- Comment Interfaces -- */
@interface Comment
//v4
//v4
@property(strong,nonatomic) id pk;
@property(strong, nonatomic) NSString *bodyText;
@property(strong, nonatomic) NSString *author;
@@ -16,22 +16,22 @@
@interface CommentsViewController : NSObject
@property(strong,nonatomic) id postData;
-(void) reloadCommentsWithNewCommentsHighlight:(BOOL) arg1 autoScroll:(BOOL) arg2 animated:(BOOL) arg3;
-(void) reloadCommentsSection:(BOOL) arg1;
-(void) reloadPostSection:(BOOL) arg1;
-(void) feedPostViewDidUpdatePost:(id) arg1 shouldReloadFeed:(BOOL) arg2;
-(void) updateFloatingViews;
- (void)reloadCommentsWithNewCommentsHighlight:(BOOL)arg1 autoScroll:(BOOL)arg2 animated:(BOOL)arg3;
- (void)reloadCommentsSection:(BOOL)arg1;
- (void)reloadPostSection:(BOOL)arg1;
- (void)feedPostViewDidUpdatePost:(id)arg1 shouldReloadFeed:(BOOL)arg2;
- (void)updateFloatingViews;
//custom elements
-(void) updateComments;
-(void) updatePostText;
- (void)updateComments;
- (void)updatePostText;
@end
@interface CommentActionSheetViewController : UIViewController
@property(strong,nonatomic) Comment *comment;
@property(strong,nonatomic) id commentTreeNode;
@property(strong,nonatomic) CommentsViewController *commentActionSheetDelegate;
-(id)animationControllerForDismissedController:(id) arg1;
- (id)animationControllerForDismissedController:(id)arg1;
@end
@@ -54,7 +54,7 @@
@interface CommentTreeHeaderNode
@property(strong,nonatomic) id commentTreeNode;
-(void) updateContentViewsForData:(id)arg1;
- (void)updateContentViewsForData:(id)arg1;
@end
@interface CommentTreeCommandBarNode
@@ -68,7 +68,7 @@
@interface CommentTreeHeaderView
@property(strong,nonatomic) id commentTreeNode;
-(void) updateContentViewsForData:(id) arg1;
- (void)updateContentViewsForData:(id)arg1;
@end
/* -- Post Interfaces -- */
@@ -85,7 +85,7 @@
@interface PostDetailViewController
@property(strong,nonatomic) id selfTextNode;
-(void) configureSelfTextNode;
- (void)configureSelfTextNode;
//custom elements
@property(strong,nonatomic) id feedPostTextWithThumbnailNode;
@@ -111,7 +111,7 @@
@interface FeedPostTitleNode
@property(strong,nonatomic) id delegate;
-(void) configureNodes;
- (void)configureNodes;
@end
@interface FeedPostDetailDelegator
@@ -119,7 +119,7 @@
@end
@interface FeedPostContentNode
-(void) configureSelfTextNode;
- (void)configureSelfTextNode;
@end
/* -- Other Interfaces -- */
@@ -130,14 +130,14 @@
@interface RUIActionSheetItem : NSObject
@property(strong,nonatomic) id leftIconImage;
-(id) initWithLeftIconImage:(id) arg1 text:(id) arg2 identifier:(id) arg3 context:(id) arg4;
- (id)initWithLeftIconImage:(id)arg1 text:(id)arg2 identifier:(id)arg3 context:(id)arg4;
@end
@interface ActionSheetItem : NSObject
// <= 4.17
@property(strong,nonatomic) id leftIconImage;
-(id) initWithLeftIconImage:(id) arg1 text:(id) arg2 identifier:(id) arg3 context:(id) arg4;
- (id) initWithLeftIconImage:(id)arg1 text:(id)arg2 identifier:(id)arg3 context:(id)arg4;
@end
@interface RUITheme
@@ -145,65 +145,66 @@
@end
@interface NSAttributedStringMarkdownParser
+(id) currentConfig;
+(id) attributedStringUsingCurrentConfig:(id) arg1;
-(id) attributedStringFromMarkdownString:(id) arg1;
-(id) initWithConfig:(id) arg1;
+ (id)currentConfig;
+ (id)attributedStringUsingCurrentConfig:(id)arg1;
- (id)attributedStringFromMarkdownString:(id)arg1;
- (id)initWithConfig:(id)arg1;
@end
@interface ThemeManager
+(id) sharedManager;
+ (id)sharedManager;
// >= 4.45.0
@property(strong,nonatomic) id darkTheme;
@property(strong,nonatomic) id lightTheme;
-(id) initWithAppSettings:(id) arg1;
- (id)initWithAppSettings:(id)arg1;
// < 4.45.0
@property(strong,nonatomic) id dayTheme;
@property(strong,nonatomic) id nightTheme;
-(id) initWithTraitCollection:(id) arg1 appSettings:(id) arg2;
- (id)initWithTraitCollection:(id)arg1 appSettings:(id)arg2;
@end
@interface AppSettings
+(id) sharedSettings;
+ (id)sharedSettings;
@end
@interface AccountManager
@property(assign,nonatomic) id defaults;
+(id) sharedManager;
+ (id)sharedManager;
@end
/* ---- Reddit v3 ---- */
/* -- Comment Interfaces -- */
@interface CommentCell : UIView
-(id) delegate;
-(id) comment;
-(id) commentView;
- (id)delegate;
- (id)comment;
- (id)commentView;
@end
@interface CommentView
-(void) configureSubviews;
-(void) layoutSubviews;
-(id) commandView;
-(id) comment;
-(id) delegate;
- (void)configureSubviews;
- (void)layoutSubviews;
- (id)commandView;
- (id)comment;
- (id)delegate;
@end
@interface CommentCommandView
@property (strong, nonatomic) id undeleteButton;
-(id)overflowButton;
-(id) comment;
-(id) delegate;
- (id)overflowButton;
- (id)comment;
- (id)delegate;
@end
/* -- Other Interfaces -- */
@interface MarkDownParser
+(id)attributedStringFromMarkdownString:(id)arg1;
+ (id)attributedStringFromMarkdownString:(id)arg1;
@end

+ 185
- 199
tweak/Reddit.xm View File

@@ -2,6 +2,7 @@
#import "Reddit.h"
#import "assets/TFHelper.h"
static BOOL isEnabled;
static BOOL isRedditEnabled;
static BOOL isTFDeletedOnly;
static CGFloat pushshiftRequestTimeoutValue;
@@ -18,9 +19,9 @@ int secondVersionPart = 0;
%hook CommentTreeHeaderView
-(void) layoutSubviews{
- (void)layoutSubviews {
%orig;
[[self commentTreeNode] setCommentTreeHeaderNode:self];
}
@@ -28,9 +29,9 @@ int secondVersionPart = 0;
%hook CommentTreeHeaderNode
-(void) didLoad{
- (void)didLoad {
%orig;
[[self commentTreeNode] setCommentTreeHeaderNode:self];
}
%end
@@ -38,7 +39,7 @@ int secondVersionPart = 0;
%hook CommentTreeCommandBarNode
-(void) didLoad{
- (void)didLoad {
%orig;
[[self commentTreeNode] setCommentTreeCommandBarNode:self];
@@ -48,11 +49,11 @@ int secondVersionPart = 0;
%hook CommentActionSheetViewController
-(void) setItems:(id) arg1{
NSString *commentBody = [[self comment] bodyText];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
- (void)setItems:(id)arg1 {
NSString *commentAuthor = [[self comment] author];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentAuthor isDeletedOnly:isTFDeletedOnly]) {
UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
@@ -64,105 +65,105 @@ int secondVersionPart = 0;
id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
arg1 = [arg1 arrayByAddingObject:undeleteItem];
[undeleteItem release];
}
%orig;
}

-(void) handleDidSelectActionSheetItem:(id) arg1{
- (void)handleDidSelectActionSheetItem:(id)arg1 {
%orig;
if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
[self dismissViewControllerAnimated:YES completion:nil];
if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
[self dismissViewControllerAnimated:YES completion:nil];
id commentTreeNode = [self commentTreeNode];
Comment *comment = [commentTreeNode comment];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
%new
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
id commentTreeNode = [self commentTreeNode];
Comment *comment = [commentTreeNode comment];
NSString *author = data[@"author"];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText;
id themeManager;
id isNightMode;
id textColor;
if (firstVersionPart == 2020){
if (firstVersionPart == 2020) {
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else{
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else {
if (secondVersionPart >= 45){
if (secondVersionPart >= 45) {
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else{
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (secondVersionPart >= 37){
} else if (secondVersionPart >= 37) {
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
}
bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[bodyMutableAttributedText beginEditing];
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
}];
[bodyMutableAttributedText endEditing];
[comment setAuthor:author];
[comment setBodyText:body];
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
[comment setBodyAttributedText:bodyMutableAttributedText];
[[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
[bodyMutableAttributedText release];
@@ -178,22 +179,22 @@ int secondVersionPart = 0;
%hook FeedPostDetailCellNode
-(void) didLoad{
- (void)didLoad {
%orig;
[[[self delegate] viewController] setFeedPostDetailCellNode:self];
}
%end
%hook PostActionSheetViewController
-(void) setItems:(id) arg1{
- (void)setItems:(id)arg1 {
Post *post = [self post];
NSString *postBody = [post selfText];
if ([post isSelfPost]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
if ([post isSelfPost]) {
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]) {
UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
@@ -205,96 +206,96 @@ int secondVersionPart = 0;
id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
arg1 = [arg1 arrayByAddingObject:undeleteItem];
[undeleteItem release];
}
}
%orig;
}
-(void) handleDidSelectActionSheetItem:(id) arg1{
- (void)handleDidSelectActionSheetItem:(id)arg1 {
%orig;
if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
[self dismissViewControllerAnimated:YES completion:nil];
Post *post = [self post];
if ([post isSelfPost]){
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
}
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
- (void)completeUndeletePostAction:(NSDictionary *)data {
Post *post = [self post];
NSString *author = data[@"author"];
NSString *body = data[@"body"];
id themeManager;
id isNightMode;
id textColor;
if (firstVersionPart == 2020){
if (firstVersionPart == 2020) {
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else{
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else {
if (secondVersionPart >= 45){
if (secondVersionPart >= 45) {
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else{
} else {
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (secondVersionPart >= 37){
} else if (secondVersionPart >= 37) {
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
} else {
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
}
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[bodyMutableAttributedText beginEditing];
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
}];
[bodyMutableAttributedText endEditing];
@@ -303,11 +304,11 @@ int secondVersionPart = 0;
[post setAuthor:author];
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
if (firstVersionPart == 2020){
if (firstVersionPart == 2020) {
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
} else {
if (secondVersionPart >= 44){
if (secondVersionPart >= 44) {
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
} else if (secondVersionPart >= 38) {
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
@@ -316,7 +317,7 @@ int secondVersionPart = 0;
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
}
}
[bodyMutableAttributedText release];
}
@@ -329,30 +330,30 @@ int secondVersionPart = 0;
%hook CommentsViewController
%new
-(void) updateComments{
%new
- (void)updateComments {
[self reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
}
%new
-(void) updatePostText{
%new
- (void)updatePostText {
if (secondVersionPart >= 2){
[self reloadPostSection:YES];
} else {
[self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
}
}
}
%end
%hook CommentActionSheetViewController
-(void) setItems:(id) arg1{
NSString *commentBody = [[self comment] bodyText];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
- (void)setItems:(id)arg1 {
NSString *commentAuthor = [[self comment] author];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentAuthor isDeletedOnly:isTFDeletedOnly]) {
UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
@@ -360,9 +361,9 @@ int secondVersionPart = 0;
CGFloat scale = origImage.size.width / existingImageSize.width;
UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
id undeleteItem;
if (secondVersionPart >= 18) {
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
} else {
@@ -370,50 +371,50 @@ int secondVersionPart = 0;
}
arg1 = [arg1 arrayByAddingObject:undeleteItem];
[undeleteItem release];
}
%orig;
}
// >= 4.21
-(void) handleDidSelectActionSheetItem:(id) arg1{
- (void)handleDidSelectActionSheetItem:(id)arg1 {
%orig;
if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
[self dismissViewControllerAnimated:YES completion:nil];
if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
[self dismissViewControllerAnimated:YES completion:nil];
Comment *comment = [self comment];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
// <= 4.20
-(void) actionSheetViewController:(id) arg1 didSelectItem:(id) arg2{
- (void)actionSheetViewController:(id)arg1 didSelectItem:(id)arg2 {
%orig;
if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
[self dismissViewControllerAnimated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
Comment *comment = [self comment];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
%new
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
Comment *comment = [self comment];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[comment setAuthor:data[@"author"]];
[comment setBodyText:body];
[comment setBodyAttributedText:bodyMutableAttributedText];
@@ -431,13 +432,13 @@ int secondVersionPart = 0;
%hook PostActionSheetViewController
-(void) setItems:(id) arg1{
- (void)setItems:(id)arg1{
Post *post = [self post];
NSString *postBody = [post selfText];
if ([post isSelfPost]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
if ([post isSelfPost]) {
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]) {
UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
@@ -445,9 +446,9 @@ int secondVersionPart = 0;
CGFloat scale = origImage.size.width / existingImageSize.width;
UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
id undeleteItem;
if (secondVersionPart >= 18) {
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
} else {
@@ -455,71 +456,70 @@ int secondVersionPart = 0;
}
arg1 = [arg1 arrayByAddingObject:undeleteItem];
[undeleteItem release];
}
}
%orig;
}
// >= 4.21
-(void) handleDidSelectActionSheetItem:(id) arg1{
- (void)handleDidSelectActionSheetItem:(id)arg1 {
%orig;
if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
[self dismissViewControllerAnimated:YES completion:nil];
Post *post = [self post];
if ([post isSelfPost]){
if ([post isSelfPost]) {
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
}
}
// <= 4.20
-(void) actionSheetViewController:(id) arg1 didSelectItem:(id) arg2{
- (void)actionSheetViewController:(id)arg1 didSelectItem:(id)arg2 {
%orig;
if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
[self dismissViewControllerAnimated:YES completion:nil];
Post *post = [self post];
if ([post isSelfPost]){
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
}
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
- (void)completeUndeletePostAction:(NSDictionary *)data {
Post *post = [self post];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[post setAuthor:data[@"author"]];
[post setSelfText:body];
[post setSelfTextAttributed:bodyMutableAttributedText];
if (secondVersionPart >= 8) {
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
}
if (secondVersionPart >= 15) {
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
}
}
[[self postActionSheetDelegate] updatePostText];
[bodyMutableAttributedText release];
}
@@ -528,7 +528,7 @@ int secondVersionPart = 0;
%end
//outdated and unchanged from first version of this tweak...
//outdated and unchanged from first version of this tweak...
//TODO: move button to menu, add post support, make async requests once I feel like doing it
%group Reddit_v3
@@ -552,16 +552,16 @@ int secondVersionPart = 0;
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[comment was unable to be archived]";
}
} else if (error != nil || data == nil){
body = @"[an error occured]";
}
@@ -583,7 +583,7 @@ int secondVersionPart = 0;
[undeleteButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
UIImage* undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
[undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
[commandView setUndeleteButton:undeleteButton];
@@ -613,28 +613,14 @@ int secondVersionPart = 0;
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isRedditEnabled"] != nil){
isRedditEnabled = [[prefs objectForKey:@"isRedditEnabled"] boolValue];
} else {
isRedditEnabled = YES;
}
if ([prefs objectForKey:@"isTFDeletedOnly"] != nil) {
isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
} else {
isTFDeletedOnly = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
isRedditEnabled = [prefs objectForKey:@"isRedditEnabled"] ? [[prefs objectForKey:@"isRedditEnabled"] boolValue] : YES;
isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
} else {
isEnabled = YES;
isRedditEnabled = YES;
isTFDeletedOnly = YES;
pushshiftRequestTimeoutValue = 10;
@@ -648,31 +634,31 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
%ctor{
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];
@try{
@try {
NSArray *redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
firstVersionPart = [redditVersion[0] intValue];
secondVersionPart = [redditVersion[1] intValue];
}
@catch (NSException *exc){
@catch (NSException *exc) {
firstVersionPart = 2020;
secondVersionPart = 0;
}
if ([processName isEqualToString:@"Reddit"]){
if (isRedditEnabled) {
if (isRedditEnabled && isEnabled) {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
if (firstVersionPart == 4 || firstVersionPart == 2020){
if (secondVersionPart <= 32 && firstVersionPart != 2020){
if (firstVersionPart == 4 || firstVersionPart == 2020) {
if (secondVersionPart <= 32 && firstVersionPart != 2020) {
%init(Reddit_v4_ios10);
} else{
%init(Reddit_v4_current);
}
}
} else if (firstVersionPart == 3) {
%init(Reddit_v3);
}

+ 17
- 17
tweak/Slide.h View File

@@ -9,10 +9,10 @@
@end
@interface CommentDepthCell
-(void) showMenu:(id) arg1;
- (void)showMenu:(id)arg1;
//custom elements
-(void) addUndeleteButtonToMenu;
- (void)addUndeleteButtonToMenu;
@end
/* -- Post Interfaces -- */
@@ -22,38 +22,38 @@
@end
@interface CommentViewController : UIViewController
-(void) refresh:(id) arg1;
- (void)refresh:(id)arg1;
//custom elements
@property(strong, nonatomic) UIButton *undeleteButton;
-(void) addUndeleteButtonToToolbar;
-(BOOL) shouldAddUndeleteButtonToToolbar;
- (void)addUndeleteButtonToToolbar;
- (BOOL)shouldAddUndeleteButtonToToolbar;
@end
/* -- Utility Interfaces -- */
@interface UIColor ()
+(UIColor *) colorWithHex:(NSString *) arg1;
-(NSString *) hexString;
+ (UIColor *)colorWithHex:(NSString *)arg1;
- (NSString *)hexString;
@end
@interface NSAttributedString ()
-(void) yy_setTextHighlightRange:(NSRange) range color:(UIColor *) color backgroundColor:(UIColor *) backgroundColor userInfo:(NSDictionary *) userInfo;
- (void)yy_setTextHighlightRange:(NSRange)range color:(UIColor *)color backgroundColor:(UIColor *)backgroundColor userInfo:(NSDictionary *)userInfo;
@end
@interface ColorUtil : NSObject
+(UIColor *) accentColorForSub:(NSString *) arg1;
+(UIColor *) fontColorForTheme:(NSString *) arg1;
+(UIColor *) backgroundColorForTheme:(NSString *) arg1;
+ (UIColor *)accentColorForSub:(NSString *)arg1;
+ (UIColor *)fontColorForTheme:(NSString *)arg1;
+ (UIColor *)backgroundColorForTheme:(NSString *)arg1;
@end
@interface DTHTMLAttributedStringBuilder
-(id) initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary * __autoreleasing*)docAttributes;
-(NSAttributedString *) generatedAttributedString;
- (id) initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary * __autoreleasing*)docAttributes;
- (NSAttributedString *)generatedAttributedString;
@end
@interface FontGenerator : NSObject
+(UIFont *) fontOfSize:(CGFloat) arg1 submission:(BOOL) arg2 willOffset:(BOOL) arg3;
+(UIFont *) boldFontOfSize:(CGFloat) arg1 submission:(BOOL) arg2 willOffset:(BOOL) arg3;
+(UIFont *) italicFontOfSize:(CGFloat) arg1 submission:(BOOL) arg2 willOffset:(BOOL) arg3;
@end
+ (UIFont *)fontOfSize:(CGFloat)arg1 submission:(BOOL)arg2 willOffset:(BOOL)arg3;
+ (UIFont *)boldFontOfSize:(CGFloat)arg1 submission:(BOOL)arg2 willOffset:(BOOL)arg3;
+ (UIFont *)italicFontOfSize:(CGFloat)arg1 submission:(BOOL)arg2 willOffset:(BOOL)arg3;
@end

+ 153
- 165
tweak/Slide.xm View File

@@ -3,6 +3,7 @@
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isEnabled;
static BOOL isSlideEnabled;
static BOOL isTFDeletedOnly;
static CGFloat pushshiftRequestTimeoutValue;
@@ -15,43 +16,43 @@ NSString *slidePostOverrideBodyHtml;
@implementation FontGenerator
+(UIFont *) fontOfSize:(CGFloat) size submission:(BOOL) isSubmission willOffset:(BOOL) willOffset{
+ (UIFont *)fontOfSize:(CGFloat)size submission:(BOOL)isSubmission willOffset:(BOOL)willOffset {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *fontName;
CGFloat fontSize = size;
if (willOffset){
if (willOffset) {
if (isSubmission){
fontSize += ([userDefaults objectForKey:@"POST_FONT_SIZE"] == nil) ? 0 : [userDefaults integerForKey:@"POST_FONT_SIZE"];
} else {
fontSize += ([userDefaults objectForKey:@"COMMENT_FONT_SIZE"] == nil) ? -2 : [userDefaults integerForKey:@"COMMENT_FONT_SIZE"];
}
}
}
if ([userDefaults stringForKey:(isSubmission ? @"postfont" : @"commentfont")] == nil){
if ([userDefaults stringForKey:(isSubmission ? @"postfont" : @"commentfont")] == nil) {
fontName = isSubmission ? @"AvenirNext-DemiBold" : @"AvenirNext-Medium";
} else {
fontName = [userDefaults stringForKey:(isSubmission ? @"postfont" : @"commentfont")];
}
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
if (!font){
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
if (!font) {
font = [UIFont systemFontOfSize:fontSize];
}
return font;
}
+(UIFont *) boldFontOfSize:(CGFloat) size submission:(BOOL) isSubmission willOffset:(BOOL) willOffset {
+ (UIFont *)boldFontOfSize:(CGFloat)size submission:(BOOL)isSubmission willOffset:(BOOL)willOffset {
UIFont *font = [self fontOfSize:size submission:isSubmission willOffset:willOffset];
if ([font.fontName isEqualToString:[UIFont systemFontOfSize:10].fontName]){
return [UIFont boldSystemFontOfSize:font.pointSize];
} else {
UIFontDescriptor *desc = [font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
if (desc == nil){
return font;
} else {
@@ -60,15 +61,15 @@ NSString *slidePostOverrideBodyHtml;
}
}
+(UIFont *) italicFontOfSize:(CGFloat) size submission:(BOOL) isSubmission willOffset:(BOOL) willOffset {
+ (UIFont *)italicFontOfSize:(CGFloat)size submission:(BOOL)isSubmission willOffset:(BOOL)willOffset {
UIFont *font = [self fontOfSize:size submission:isSubmission willOffset:willOffset];
if ([font.fontName isEqualToString:[UIFont systemFontOfSize:10].fontName]){
if ([font.fontName isEqualToString:[UIFont systemFontOfSize:10].fontName]) {
return [UIFont italicSystemFontOfSize:font.pointSize];
} else {
UIFontDescriptor *desc = [font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];
if (desc == nil){
if (desc == nil) {
return font;
} else {
return [UIFont fontWithDescriptor:desc size: 0];
@@ -79,9 +80,9 @@ NSString *slidePostOverrideBodyHtml;
@end
@implementation ColorUtil
@implementation ColorUtil
+(UIColor *) accentColorForSub:(NSString *) subreddit{
+ (UIColor *)accentColorForSub:(NSString *)subreddit {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSData *colorData = [userDefaults dataForKey:[NSString stringWithFormat:@"accent+%@", subreddit]];
UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData];
@@ -89,8 +90,8 @@ NSString *slidePostOverrideBodyHtml;
return color;
} else {
UIColor *baseAccentColor = [NSKeyedUnarchiver unarchiveObjectWithData:[userDefaults dataForKey:@"accentcolor"]];
if (baseAccentColor){
if (baseAccentColor) {
return baseAccentColor;
} else {
return [UIColor colorWithRed:0.161 green:0.475 blue:1.0 alpha:1.0];
@@ -98,10 +99,10 @@ NSString *slidePostOverrideBodyHtml;
}
}
+(UIColor *) fontColorForTheme:(NSString *)theme{
+ (UIColor *)fontColorForTheme:(NSString *)theme {
UIColor *fontColor;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
//if only switch blocks worked with strings...
if ([theme isEqualToString:@"light"]) {
fontColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.87];
@@ -112,9 +113,9 @@ NSString *slidePostOverrideBodyHtml;
} else if ([theme isEqualToString:@"blue"]) {
fontColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.87];
} else if ([theme isEqualToString:@"sepia"]) {
fontColor = [UIColor colorWithRed:0.243 green:.239 blue:.212 alpha:0.87];
fontColor = [UIColor colorWithRed:0.243 green:.239 blue:.212 alpha:0.87];
} else if ([theme isEqualToString:@"red"]) {
fontColor = [UIColor colorWithRed:1.0 green:0.969 blue:0.929 alpha:0.87];
fontColor = [UIColor colorWithRed:1.0 green:0.969 blue:0.929 alpha:0.87];
} else if ([theme isEqualToString:@"deep"]) {
fontColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.87];
} else if ([theme isEqualToString:@"mint"]) {
@@ -133,16 +134,16 @@ NSString *slidePostOverrideBodyHtml;
NSString *customThemeString = [[userDefaults stringForKey:[NSString stringWithFormat:@"Theme+%@", theme]] stringByRemovingPercentEncoding];
if (customThemeString) {
NSString *customFontColorHex = [customThemeString componentsSeparatedByString:@"#"][4];
fontColor = [UIColor colorWithHex:customFontColorHex];
fontColor = [UIColor colorWithHex:customFontColorHex];
} else {
fontColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.87];
}
}
return fontColor;
}
+(UIColor *) backgroundColorForTheme:(NSString *) theme{
+ (UIColor *)backgroundColorForTheme:(NSString *)theme {
UIColor *backgroundColor;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
@@ -155,9 +156,9 @@ NSString *slidePostOverrideBodyHtml;
} else if ([theme isEqualToString:@"blue"]) {
backgroundColor = [UIColor colorWithRed:0.071 green:0.094 blue:0.106 alpha:1.0];
} else if ([theme isEqualToString:@"sepia"]) {
backgroundColor = [UIColor colorWithRed:0.310 green:0.302 blue:0.267 alpha:1.0];
backgroundColor = [UIColor colorWithRed:0.310 green:0.302 blue:0.267 alpha:1.0];
} else if ([theme isEqualToString:@"red"]) {
backgroundColor = [UIColor colorWithRed:0.075 green:0.055 blue:0.051 alpha:1.0];
backgroundColor = [UIColor colorWithRed:0.075 green:0.055 blue:0.051 alpha:1.0];
} else if ([theme isEqualToString:@"deep"]) {
backgroundColor = [UIColor colorWithRed:0.035 green:0.035 blue:0.043 alpha:1.0];
} else if ([theme isEqualToString:@"mint"]) {
@@ -176,12 +177,12 @@ NSString *slidePostOverrideBodyHtml;
NSString *customThemeString = [[userDefaults stringForKey:[NSString stringWithFormat:@"Theme+%@", theme]] stringByRemovingPercentEncoding];
if (customThemeString) {
NSString *customFontColorHex = [customThemeString componentsSeparatedByString:@"#"][3];
backgroundColor = [UIColor colorWithHex:customFontColorHex];
backgroundColor = [UIColor colorWithHex:customFontColorHex];
} else {
backgroundColor = [UIColor colorWithRed:0.352 green:0.352 blue:0.352 alpha:1.0];
}
}
}
return backgroundColor;
}
@@ -189,15 +190,15 @@ NSString *slidePostOverrideBodyHtml;
static UIButton *createUndeleteButton(){
UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160white.png"];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(20, 20), NO, 0);
[undeleteImage drawInRect:CGRectMake(0, 0, 20, 20)];
undeleteImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsBeginImageContextWithOptions(CGSizeMake(35, 35), NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
@@ -208,7 +209,7 @@ static UIButton *createUndeleteButton(){
[undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
undeleteButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
return undeleteButton;
}
@@ -216,25 +217,25 @@ static UIButton *createUndeleteButton(){
%hook UIColor
%new
+(UIColor *) colorWithHex:(NSString *) arg1 {
+ (UIColor *)colorWithHex:(NSString *)arg1 {
if (!arg1){
NSString *firstChar = [arg1 substringToIndex:1];
if ([firstChar isEqualToString:@"#"]){
arg1 = [arg1 substringWithRange:NSMakeRange(1, [arg1 length]-1)];
}
unsigned rgbValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:arg1];
[scanner scanHexInt:&rgbValue];
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:0.87];
} else {
return nil;
}
}
%new
-(NSString *) hexString {
%new
- (NSString *)hexString {
const CGFloat *components = CGColorGetComponents(self.CGColor);
CGFloat r = components[0];
@@ -249,35 +250,35 @@ static UIButton *createUndeleteButton(){
%hook CommentDepthCell
-(void) doShortClick{
- (void)doShortClick {
%orig;
[self addUndeleteButtonToMenu];
}
-(void) doLongClick {
- (void)doLongClick {
%orig;
[self addUndeleteButtonToMenu];
}
%new
-(void) addUndeleteButtonToMenu{
%new
- (void)addUndeleteButtonToMenu {
NSString *commentBody = [MSHookIvar<id>(self, "comment") body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]) {
id controller = MSHookIvar<id>(self, "parent");
if (MSHookIvar<id>(controller, "menuCell")){
if (MSHookIvar<id>(controller, "menuCell")) {
UIStackView *menu = MSHookIvar<UIStackView *>(self, "menu");
if (![[[[menu arrangedSubviews] lastObject] actionsForTarget:self forControlEvent:UIControlEventTouchUpInside] containsObject:@"handleUndeleteComment:"]){
if (![[[[menu arrangedSubviews] lastObject] actionsForTarget:self forControlEvent:UIControlEventTouchUpInside] containsObject:@"handleUndeleteComment:"]) {
UIButton *undeleteButton = createUndeleteButton();
[undeleteButton addTarget:self action:@selector(handleUndeleteComment:) forControlEvents:UIControlEventTouchUpInside];
[menu addArrangedSubview:undeleteButton];
}
}
@@ -285,114 +286,114 @@ static UIButton *createUndeleteButton(){
}
%new
-(void) handleUndeleteComment:(id) sender{
- (void)handleUndeleteComment:(id)sender {
[sender setEnabled:NO];
id comment = MSHookIvar<id>(self, "comment");
[%c(TFHelper) getUndeleteDataWithID:[[comment id] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
- (void)completeUndeleteCommentAction:(NSDictionary *)data {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
id textStackDisplayView = MSHookIvar<id>(self, "commentBody");
id comment = MSHookIvar<id>(self, "comment");
NSString *author = data[@"author"];
NSString *body = data[@"body"];
//Attributed string generation rewrote from Slide_for_Reddit.TextDisplayStackView.createAttributedChunk(...)
//Attributed string generation rewrote from Slide_for_Reddit.TextDisplayStackView.createAttributedChunk(...)
UIFont *font = [%c(FontGenerator) fontOfSize:MSHookIvar<CGFloat>(textStackDisplayView, "fontSize") submission:NO willOffset:YES];
NSString *themeName = [userDefaults stringForKey:@"theme"];
UIColor *fontColor = [%c(ColorUtil) fontColorForTheme:themeName];
UIColor *accentColor = [%c(ColorUtil) accentColorForSub:[comment subreddit]];
NSString *html = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
html = [[html stringByReplacingOccurrencesOfString:@"<sup>" withString:@"<font size=\"1\">"] stringByReplacingOccurrencesOfString:@"</sup>" withString:@"</font>"];
html = [[html stringByReplacingOccurrencesOfString:@"<del>" withString:@"<font color=\"green\">"] stringByReplacingOccurrencesOfString:@"</del>" withString:@"</font>"];
html = [[html stringByReplacingOccurrencesOfString:@"<code>" withString:@"<font color=\"blue\">"] stringByReplacingOccurrencesOfString:@"</code>" withString:@"</font>"];
html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
DTHTMLAttributedStringBuilder *dthtmlBuilder = [[%c(DTHTMLAttributedStringBuilder) alloc] initWithHTML:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{@"DTUseiOS6Attributes": @YES, @"DTDefaultTextColor": fontColor, @"DTDefaultFontSize": @([font pointSize])} documentAttributes:nil];
NSMutableAttributedString *htmlAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[dthtmlBuilder generatedAttributedString]];
NSRange htmlStringRange = NSMakeRange(0, [htmlAttributedString length]);
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t•\t" withString:@" • " options:0 range: htmlStringRange];
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t◦\t" withString:@"  ◦ " options:0 range: htmlStringRange];
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t▪\t" withString:@" ▪ " options:0 range: htmlStringRange];
[htmlAttributedString removeAttribute:@"CTForegroundColorFromContext" range:htmlStringRange];
[htmlAttributedString enumerateAttributesInRange:htmlStringRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
for (NSString *key in attributes){
if ([(UIColor *) attributes[key] isKindOfClass:[UIColor class]]){
for (NSString *key in attributes) {
if ([(UIColor *) attributes[key] isKindOfClass:[UIColor class]]) {
UIColor *attrColor = (UIColor *) attributes[key];
if ([[attrColor hexString] isEqualToString:@"#0000FF"]){
if ([[attrColor hexString] isEqualToString:@"#0000FF"]) {
UIFont *tempFont = [UIFont fontWithName:@"Courier" size:font.pointSize];
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: accentColor, NSBackgroundColorAttributeName: [%c(ColorUtil) backgroundColorForTheme:themeName], NSFontAttributeName: (tempFont ? tempFont : font)} range:range];
} else if ([[attrColor hexString] isEqualToString:@"#008000"]) {
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: fontColor, NSFontAttributeName:font} range:range];
}
} else if ([(NSURL *) attributes[key] isKindOfClass:[NSURL class]]){
} else if ([(NSURL *) attributes[key] isKindOfClass:[NSURL class]]) {
NSURL *attrUrl = (NSURL *)attributes[key];
if (([userDefaults objectForKey:@"ENLARGE_LINKS"] == nil) ? YES : [userDefaults boolForKey:@"ENLARGE_LINKS"]){
if (([userDefaults objectForKey:@"ENLARGE_LINKS"] == nil) ? YES : [userDefaults boolForKey:@"ENLARGE_LINKS"]) {
[htmlAttributedString addAttribute:NSFontAttributeName value:[%c(FontGenerator) boldFontOfSize:18 submission:NO willOffset:YES] range:range];
}
[htmlAttributedString addAttribute:NSForegroundColorAttributeName value:accentColor range:range];
[htmlAttributedString addAttribute:NSForegroundColorAttributeName value:accentColor range:range];
[htmlAttributedString addAttribute:NSUnderlineColorAttributeName value:[UIColor clearColor] range:range];
//skipping showLinkContentType b/c not necessary and spoilers b/c MMMarkdown doesn't support them
[htmlAttributedString yy_setTextHighlightRange:range color: accentColor backgroundColor:nil userInfo:@{@"url": attrUrl}];
break;
}
break;
}
}
}];
[htmlAttributedString beginEditing];
[htmlAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, [htmlAttributedString length]) options:0 usingBlock:^(id value, NSRange range, BOOL *stop){
[htmlAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, [htmlAttributedString length]) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
UIFont *attrFont = (UIFont *)value;
BOOL isBold = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) != 0;
BOOL isItalic = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic) != 0;
UIFont *newFont = font;
if (isBold){
newFont = [%c(FontGenerator) boldFontOfSize:attrFont.pointSize submission:NO willOffset:NO];
} else if (isItalic){
newFont = [%c(FontGenerator) italicFontOfSize:attrFont.pointSize submission:NO willOffset:NO];
}
[htmlAttributedString removeAttribute:NSFontAttributeName range:range];
[htmlAttributedString addAttribute:NSFontAttributeName value:newFont range:range];
[htmlAttributedString addAttribute:NSFontAttributeName value:newFont range:range];
}];
[htmlAttributedString endEditing];
NSMutableAttributedString *newCommentText = [MSHookIvar<NSMutableAttributedString *>(self, "cellContent") initWithAttributedString:htmlAttributedString];
NSAttributedString *tempAttributedString = [[NSAttributedString alloc] initWithString:@""];
[newCommentText appendAttributedString:tempAttributedString]; //to keep the compiler happy
[comment setAuthor:author];
[comment setBody:body];
[comment setBody:body];
id controller = MSHookIvar<id>(self, "parent");
[self showMenu:nil];
[MSHookIvar<id>(controller, "tableView") reloadData];
[data[@"sender"] setEnabled:YES];
}
@@ -401,7 +402,7 @@ static UIButton *createUndeleteButton(){
%hook RSubmission
-(id) author{
- (id)author {
if (shouldSlideOverridePostInfo){
return slidePostOverrideAuthor;
} else {
@@ -409,7 +410,7 @@ static UIButton *createUndeleteButton(){
}
}
-(id) htmlBody{
- (id)htmlBody {
if (shouldSlideOverridePostInfo){
return slidePostOverrideBodyHtml;
}
@@ -424,32 +425,32 @@ static UIButton *createUndeleteButton(){
%hook CommentViewController
%property(strong, nonatomic) UIButton *undeleteButton;
-(void) viewDidLoad {
- (void)viewDidLoad {
%orig;
shouldSlideOverridePostInfo = NO;
slidePostOverrideAuthor = nil;
slidePostOverrideBodyHtml = nil;
UIButton *undeleteButton = createUndeleteButton();
[undeleteButton setImage:[[undeleteButton currentImage] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[undeleteButton addTarget:self action:@selector(handleUndeletePost:) forControlEvents:UIControlEventTouchUpInside];
[self setUndeleteButton:undeleteButton];
}
-(void) viewDidLayoutSubviews{
- (void)viewDidLayoutSubviews {
%orig;
if ([self undeleteButton]){
if ([self shouldAddUndeleteButtonToToolbar]){
if ([self undeleteButton]) {
if ([self shouldAddUndeleteButtonToToolbar]) {
[self addUndeleteButtonToToolbar];
}
}
}
-(void) loadAll:(id) arg1{
- (void)loadAll:(id)arg1 {
%orig;
if ([self undeleteButton]){
if ([self shouldAddUndeleteButtonToToolbar]){
[self addUndeleteButtonToToolbar];
@@ -458,41 +459,41 @@ static UIButton *createUndeleteButton(){
}
%new
-(BOOL) shouldAddUndeleteButtonToToolbar{
- (BOOL)shouldAddUndeleteButtonToToolbar {
id post = MSHookIvar<id>(self, "submission");
if ([post isSelf]){
if ([post isSelf]) {
NSString *postBody = [post body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]){
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:postBody isDeletedOnly:isTFDeletedOnly]) {
return YES;
}
}
return NO;
}
%new
-(void) addUndeleteButtonToToolbar{
- (void)addUndeleteButtonToToolbar {
UIToolbar *toolbar = [[self navigationController] toolbar];
NSMutableArray *toolbarItems = [[toolbar items] mutableCopy];
UIView *firstView = [toolbarItems[0] customView];
if (firstView){
if (firstView) {
UIColor *tintColor = [toolbar tintColor];
UIButton *undeleteButton = [self undeleteButton];
[undeleteButton setTintColor:tintColor];
if ([firstView isMemberOfClass:[UIView class]]){
if ([firstView isMemberOfClass:[UIView class]]) {
if (![undeleteButton isDescendantOfView:firstView]){
[firstView addSubview:undeleteButton];
[undeleteButton setFrame:firstView.bounds];
}
} else if ([firstView isMemberOfClass:[UIButton class]] && undeleteButton != firstView){
} else if ([firstView isMemberOfClass:[UIButton class]] && undeleteButton != firstView) {
UIBarButtonItem *undeleteItem = [[UIBarButtonItem alloc] initWithCustomView:undeleteButton];
[toolbarItems insertObject:toolbarItems[1] atIndex:0];
[toolbarItems insertObject:undeleteItem atIndex:0];
[toolbar setItems:toolbarItems animated:NO];
@@ -501,22 +502,22 @@ static UIButton *createUndeleteButton(){
}
%new
-(void) handleUndeletePost:(id) sender{
- (void)handleUndeletePost:(id)sender {
shouldSlideOverridePostInfo = YES;
[sender setEnabled:NO];
[%c(TFHelper) getUndeleteDataWithID:[MSHookIvar<id>(self, "submission") name] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
[%c(TFHelper) getUndeleteDataWithID:[MSHookIvar<id>(self, "submission") name] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
- (void)completeUndeletePostAction:(NSDictionary *)data {
slidePostOverrideAuthor = data[@"author"];
slidePostOverrideBodyHtml = [%c(MMMarkdown) HTMLStringWithMarkdown:data[@"body"] extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[self refresh:nil];
[data[@"sender"] setEnabled:YES];
}
@@ -527,32 +528,19 @@ static UIButton *createUndeleteButton(){
static void loadPrefs(){
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
if (prefs){
if ([prefs objectForKey:@"isSlideEnabled"] != nil){
isSlideEnabled = [[prefs objectForKey:@"isSlideEnabled"] boolValue];
} else {
isSlideEnabled = YES;
}
if ([prefs objectForKey:@"isTFDeletedOnly"] != nil){
isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
} else {
isTFDeletedOnly = YES;
}
if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
} else {
pushshiftRequestTimeoutValue = 10;
}
isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
isSlideEnabled = [prefs objectForKey:@"isSlideEnabled"] ? [[prefs objectForKey:@"isSlideEnabled"] boolValue] : YES;
isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
} else {
isEnabled = YES;
isSlideEnabled = YES;
isTFDeletedOnly = YES;
pushshiftRequestTimeoutValue = 10;
}
}
}
static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
@@ -562,14 +550,14 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
%ctor {
loadPrefs();
NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"Slide for Reddit"]){
if (isSlideEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
if (isSlideEnabled && isEnabled){
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(Slide, CommentDepthCell = objc_getClass("Slide_for_Reddit.CommentDepthCell"), RSubmission = objc_getClass("Slide_for_Reddit.RSubmission"), CommentViewController = objc_getClass("Slide_for_Reddit.CommentViewController"));
}
}

+ 4
- 2
tweak/assets/TFHelper.h View File

@@ -1,7 +1,9 @@
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
@interface TFHelper : NSObject
+(void) getUndeleteDataWithID:(NSString *) ident isComment:(BOOL) isComment timeout:(CGFloat) timeout extraData:(NSDictionary *) extra completionTarget:(id) target completionSelector:(SEL) sel;
+(BOOL) shouldShowUndeleteButtonWithInfo:(NSString *) content isDeletedOnly:(BOOL) isDeletedOnly;
+ (void)getUndeleteDataWithID:(NSString *)ident isComment:(BOOL)isComment timeout:(CGFloat)timeout extraData:(NSDictionary *)extra completionTarget:(id)target completionSelector:(SEL)sel;
+ (BOOL)shouldShowUndeleteButtonWithInfo:(NSString *)content isDeletedOnly:(BOOL)isDeletedOnly;
@end

+ 9
- 9
tweak/assets/TFHelper.m View File

@@ -3,22 +3,22 @@
@implementation TFHelper
+(void) getUndeleteDataWithID:(NSString *) ident isComment:(BOOL) isComment timeout:(CGFloat) timeout extraData:(NSDictionary *) extra completionTarget:(id) target completionSelector:(SEL) sel{
+ (void)getUndeleteDataWithID:(NSString *)ident isComment:(BOOL)isComment timeout:(CGFloat)timeout extraData:(NSDictionary *)extra completionTarget:(id)target completionSelector:(SEL)sel {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
if (isComment){
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]];
} else {
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", ident]]];
}
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:timeout];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
@@ -36,19 +36,19 @@
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableDictionary *result = [@{@"author" : author, @"body" : body} mutableCopy];
if (extra){
[result addEntriesFromDictionary:extra];
}
[target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO];
}];
}
+(BOOL) shouldShowUndeleteButtonWithInfo:(NSString *) content isDeletedOnly:(BOOL) isDeletedOnly{
if (!isDeletedOnly){
return YES;
} else {
@@ -58,7 +58,7 @@
return YES;
}
}
return NO;
}

Loading…
Cancel
Save