No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. #import "Reddit.h"
  2. #import "assets/TFHelper.h"
  3. static BOOL isEnabled;
  4. static BOOL isRedditEnabled;
  5. static BOOL isTFDeletedOnly;
  6. static CGFloat pushshiftRequestTimeoutValue;
  7. int firstVersionPart = 2020;
  8. int secondVersionPart = 0;
  9. %group Reddit_v4_current
  10. %hook CommentTreeNode
  11. %property(assign,nonatomic)id commentTreeHeaderNode;
  12. %property(assign,nonatomic)id commentTreeCommandBarNode;
  13. %end
  14. %hook CommentTreeHeaderView
  15. - (void)layoutSubviews {
  16. %orig;
  17. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  18. }
  19. %end
  20. %hook CommentTreeHeaderNode
  21. - (void)didLoad {
  22. %orig;
  23. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  24. }
  25. %end
  26. %hook CommentTreeCommandBarNode
  27. - (void)didLoad {
  28. %orig;
  29. [[self commentTreeNode] setCommentTreeCommandBarNode:self];
  30. }
  31. %end
  32. %hook CommentActionSheetViewController
  33. - (void)setItems:(id)arg1 {
  34. NSString *author = [[self comment] author];
  35. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  36. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  37. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  38. CGFloat scale = origImage.size.width / existingImageSize.width;
  39. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  40. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  41. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  42. [undeleteItem release];
  43. }
  44. %orig;
  45. }
  46. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  47. %orig;
  48. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  49. [self dismissViewControllerAnimated:YES completion:nil];
  50. id commentTreeNode = [self commentTreeNode];
  51. Comment *comment = [commentTreeNode comment];
  52. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  53. }
  54. }
  55. %new
  56. - (void)completeUndeleteCommentAction:(NSDictionary *)data {
  57. id commentTreeNode = [self commentTreeNode];
  58. Comment *comment = [commentTreeNode comment];
  59. NSString *author = data[@"author"];
  60. NSString *body = data[@"body"];
  61. NSMutableAttributedString *bodyMutableAttributedText;
  62. id themeManager;
  63. id isNightMode;
  64. id textColor;
  65. if (firstVersionPart == 2020) {
  66. AppSettings *appSettings = [%c(AppSettings) sharedSettings];
  67. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:appSettings];
  68. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  69. if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0") && [appSettings isAutoDarkModeEnabled]) {
  70. NSInteger sysInterfaceStyle = [[UITraitCollection _currentTraitCollection] userInterfaceStyle];
  71. if (sysInterfaceStyle == UIUserInterfaceStyleDark){
  72. textColor = [[themeManager darkTheme] bodyTextColor];
  73. } else {
  74. textColor = [[themeManager lightTheme] bodyTextColor];
  75. }
  76. } else {
  77. if (isNightMode) {
  78. textColor = [[themeManager darkTheme] bodyTextColor];
  79. } else {
  80. textColor = [[themeManager lightTheme] bodyTextColor];
  81. }
  82. }
  83. [themeManager release];
  84. } else {
  85. if (secondVersionPart >= 45) {
  86. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  87. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  88. if (isNightMode) {
  89. textColor = [[themeManager darkTheme] bodyTextColor];
  90. } else {
  91. textColor = [[themeManager lightTheme] bodyTextColor];
  92. }
  93. [themeManager release];
  94. } else if (secondVersionPart >= 37) {
  95. themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  96. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  97. if (isNightMode) {
  98. textColor = [[themeManager nightTheme] bodyTextColor];
  99. } else {
  100. textColor = [[themeManager dayTheme] bodyTextColor];
  101. }
  102. [themeManager release];
  103. } else {
  104. themeManager = [%c(ThemeManager) sharedManager];
  105. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  106. if (isNightMode) {
  107. textColor = [[themeManager nightTheme] bodyTextColor];
  108. } else {
  109. textColor = [[themeManager dayTheme] bodyTextColor];
  110. }
  111. }
  112. }
  113. bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  114. [bodyMutableAttributedText beginEditing];
  115. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  116. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  117. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  118. }];
  119. [bodyMutableAttributedText endEditing];
  120. [comment setAuthor:author];
  121. [comment setBodyText:body];
  122. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  123. [comment setBodyAttributedText:bodyMutableAttributedText];
  124. [[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
  125. [bodyMutableAttributedText release];
  126. }
  127. %end
  128. %hook PostDetailViewController
  129. %property(strong,nonatomic) id feedPostTextWithThumbnailNode;
  130. %property(strong,nonatomic) id feedPostDetailCellNode;
  131. %end
  132. %hook FeedPostDetailCellNode
  133. - (void)didLoad {
  134. %orig;
  135. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  136. }
  137. %end
  138. %hook PostActionSheetViewController
  139. - (void)setItems:(id)arg1 {
  140. Post *post = [self post];
  141. NSString *author = [post author];
  142. if ([post isSelfPost]) {
  143. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  144. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  145. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  146. CGFloat scale = origImage.size.width / existingImageSize.width;
  147. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  148. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  149. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  150. [undeleteItem release];
  151. }
  152. }
  153. %orig;
  154. }
  155. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  156. %orig;
  157. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  158. [self dismissViewControllerAnimated:YES completion:nil];
  159. Post *post = [self post];
  160. if ([post isSelfPost]){
  161. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  162. }
  163. }
  164. }
  165. %new
  166. - (void)completeUndeletePostAction:(NSDictionary *)data {
  167. Post *post = [self post];
  168. NSString *author = data[@"author"];
  169. NSString *body = data[@"body"];
  170. id themeManager;
  171. id isNightMode;
  172. id textColor;
  173. if (firstVersionPart == 2020) {
  174. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  175. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  176. if (isNightMode) {
  177. textColor = [[themeManager darkTheme] bodyTextColor];
  178. } else {
  179. textColor = [[themeManager lightTheme] bodyTextColor];
  180. }
  181. [themeManager release];
  182. } else {
  183. if (secondVersionPart >= 45) {
  184. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  185. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  186. if (isNightMode) {
  187. textColor = [[themeManager darkTheme] bodyTextColor];
  188. } else {
  189. textColor = [[themeManager lightTheme] bodyTextColor];
  190. }
  191. [themeManager release];
  192. } else if (secondVersionPart >= 37) {
  193. themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  194. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  195. if (isNightMode) {
  196. textColor = [[themeManager nightTheme] bodyTextColor];
  197. } else {
  198. textColor = [[themeManager dayTheme] bodyTextColor];
  199. }
  200. [themeManager release];
  201. } else {
  202. themeManager = [%c(ThemeManager) sharedManager];
  203. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  204. if (isNightMode) {
  205. textColor = [[themeManager nightTheme] bodyTextColor];
  206. } else {
  207. textColor = [[themeManager dayTheme] bodyTextColor];
  208. }
  209. }
  210. }
  211. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  212. [bodyMutableAttributedText beginEditing];
  213. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  214. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  215. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  216. }];
  217. [bodyMutableAttributedText endEditing];
  218. [post setSelfText:body];
  219. [post setAuthor:author];
  220. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  221. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  222. if (firstVersionPart == 2020) {
  223. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  224. } else {
  225. if (secondVersionPart >= 44) {
  226. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  227. } else if (secondVersionPart >= 38) {
  228. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  229. } else {
  230. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  231. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
  232. }
  233. }
  234. [bodyMutableAttributedText release];
  235. }
  236. %end
  237. %end
  238. %group Reddit_v4_ios10
  239. %hook CommentsViewController
  240. %new
  241. - (void)updateComments {
  242. [self reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  243. }
  244. %new
  245. - (void)updatePostText {
  246. if (secondVersionPart >= 2){
  247. [self reloadPostSection:YES];
  248. } else {
  249. [self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
  250. }
  251. }
  252. %end
  253. %hook CommentActionSheetViewController
  254. - (void)setItems:(id)arg1 {
  255. NSString *author = [[self comment] author];
  256. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  257. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  258. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  259. CGFloat scale = origImage.size.width / existingImageSize.width;
  260. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  261. id undeleteItem;
  262. if (secondVersionPart >= 18) {
  263. undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  264. } else {
  265. undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  266. }
  267. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  268. [undeleteItem release];
  269. }
  270. %orig;
  271. }
  272. // >= 4.21
  273. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  274. %orig;
  275. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  276. [self dismissViewControllerAnimated:YES completion:nil];
  277. Comment *comment = [self comment];
  278. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  279. }
  280. }
  281. // <= 4.20
  282. - (void)actionSheetViewController:(id)arg1 didSelectItem:(id)arg2 {
  283. %orig;
  284. if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  285. [self dismissViewControllerAnimated:YES completion:nil];
  286. Comment *comment = [self comment];
  287. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  288. }
  289. }
  290. %new
  291. - (void)completeUndeleteCommentAction:(NSDictionary *)data {
  292. Comment *comment = [self comment];
  293. NSString *body = data[@"body"];
  294. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  295. [comment setAuthor:data[@"author"]];
  296. [comment setBodyText:body];
  297. [comment setBodyAttributedText:bodyMutableAttributedText];
  298. if (secondVersionPart >= 12) {
  299. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  300. }
  301. [[self commentActionSheetDelegate] updateComments];
  302. [bodyMutableAttributedText release];
  303. }
  304. %end
  305. %hook PostActionSheetViewController
  306. - (void)setItems:(id)arg1{
  307. Post *post = [self post];
  308. NSString *author = [post author];
  309. if ([post isSelfPost]) {
  310. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  311. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  312. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  313. CGFloat scale = origImage.size.width / existingImageSize.width;
  314. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  315. id undeleteItem;
  316. if (secondVersionPart >= 18) {
  317. undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  318. } else {
  319. undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  320. }
  321. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  322. [undeleteItem release];
  323. }
  324. }
  325. %orig;
  326. }
  327. // >= 4.21
  328. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  329. %orig;
  330. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  331. [self dismissViewControllerAnimated:YES completion:nil];
  332. Post *post = [self post];
  333. if ([post isSelfPost]) {
  334. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  335. }
  336. }
  337. }
  338. // <= 4.20
  339. - (void)actionSheetViewController:(id)arg1 didSelectItem:(id)arg2 {
  340. %orig;
  341. if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  342. [self dismissViewControllerAnimated:YES completion:nil];
  343. Post *post = [self post];
  344. if ([post isSelfPost]){
  345. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  346. }
  347. }
  348. }
  349. %new
  350. - (void)completeUndeletePostAction:(NSDictionary *)data {
  351. Post *post = [self post];
  352. NSString *body = data[@"body"];
  353. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  354. [post setAuthor:data[@"author"]];
  355. [post setSelfText:body];
  356. [post setSelfTextAttributed:bodyMutableAttributedText];
  357. if (secondVersionPart >= 8) {
  358. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  359. }
  360. if (secondVersionPart >= 15) {
  361. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  362. }
  363. [[self postActionSheetDelegate] updatePostText];
  364. [bodyMutableAttributedText release];
  365. }
  366. %end
  367. %end
  368. //outdated and unchanged from first version of this tweak...
  369. //TODO: move button to menu, add post support, make async requests once I feel like doing it
  370. %group Reddit_v3
  371. %hook CommentView
  372. %new
  373. -(void) buttonAction {
  374. id commentsViewController = [self delegate];
  375. id comment = [self comment];
  376. NSError* error;
  377. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  378. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment pkWithoutPrefix]]]];
  379. [request setHTTPMethod:@"GET"];
  380. NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
  381. NSString *author = @"[author]";
  382. NSString *body = @"[body]";
  383. if (data != nil && error == nil){
  384. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  385. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  386. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  387. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  388. body = @"[comment was unable to be archived]";
  389. }
  390. } else if (error != nil || data == nil){
  391. body = @"[an error occured]";
  392. }
  393. [comment setValue:author forKey:@"author"];
  394. [comment setValue:[%c(MarkDownParser) attributedStringFromMarkdownString: body] forKey:@"bodyAttributedText"];
  395. [comment setValue:body forKey:@"bodyText"];
  396. [commentsViewController reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  397. }
  398. -(id) initWithFrame:(id)arg1{
  399. id orig = %orig;
  400. id commandView = [self commandView];
  401. UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
  402. [undeleteButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
  403. UIImage* undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  404. [undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
  405. [commandView setUndeleteButton:undeleteButton];
  406. [commandView addSubview:undeleteButton];
  407. return orig;
  408. }
  409. %end
  410. %hook CommentCommandView
  411. %property (assign, nonatomic) id undeleteButton;
  412. -(void) layoutSubviews{
  413. %orig;
  414. UIButton *button = [self undeleteButton];
  415. button.frame = CGRectMake([[self overflowButton ] frame].origin.x - 32, 0, 32, 32);
  416. }
  417. %end
  418. %end
  419. static void loadPrefs(){
  420. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
  421. if (prefs){
  422. isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
  423. isRedditEnabled = [prefs objectForKey:@"isRedditEnabled"] ? [[prefs objectForKey:@"isRedditEnabled"] boolValue] : YES;
  424. isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
  425. pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
  426. } else {
  427. isEnabled = YES;
  428. isRedditEnabled = YES;
  429. isTFDeletedOnly = YES;
  430. pushshiftRequestTimeoutValue = 10;
  431. }
  432. }
  433. static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
  434. loadPrefs();
  435. }
  436. %ctor{
  437. loadPrefs();
  438. NSString* processName = [[NSProcessInfo processInfo] processName];
  439. @try {
  440. NSArray *redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
  441. firstVersionPart = [redditVersion[0] intValue];
  442. secondVersionPart = [redditVersion[1] intValue];
  443. }
  444. @catch (NSException *exc) {
  445. firstVersionPart = 2020;
  446. secondVersionPart = 0;
  447. }
  448. if ([processName isEqualToString:@"Reddit"]){
  449. if (isRedditEnabled && isEnabled) {
  450. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
  451. if (firstVersionPart == 4 || firstVersionPart == 2020) {
  452. if (secondVersionPart <= 32 && firstVersionPart != 2020) {
  453. %init(Reddit_v4_ios10);
  454. } else{
  455. %init(Reddit_v4_current);
  456. }
  457. } else if (firstVersionPart == 3) {
  458. %init(Reddit_v3);
  459. }
  460. }
  461. }
  462. }