選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Reddit.xm 22KB

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