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

Reddit.xm 21KB

5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 = 0;
  8. int secondVersionPart = 0;
  9. %group Reddit_v4_current
  10. UIColor * getCurrentTextColor() {
  11. ThemeManager *themeManager;
  12. id isNightMode;
  13. UIColor *textColor;
  14. if (firstVersionPart >= 2021) {
  15. RUIThemeGuidance *themeGuidance = [%c(RUIThemeGuidance) sharedGuidance];
  16. textColor = [[themeGuidance currentTheme] bodyTextColor];
  17. } else if (firstVersionPart == 2020) {
  18. if (secondVersionPart <= 40) {
  19. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  20. AppSettings *appSettings = [%c(AppSettings) sharedSettings];
  21. AccountManager *accountManager = secondVersionPart >= 29 ? [appDelegate accountManager] : [%c(AccountManager) sharedManager];
  22. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:appSettings];
  23. isNightMode = [[accountManager defaults] objectForKey:@"kUseNightKey"];
  24. if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0") && [appSettings isAutoDarkModeEnabled]) {
  25. NSInteger sysInterfaceStyle = [[UITraitCollection _currentTraitCollection] userInterfaceStyle];
  26. if (sysInterfaceStyle == UIUserInterfaceStyleDark){
  27. textColor = [[themeManager darkTheme] bodyTextColor];
  28. } else {
  29. textColor = [[themeManager lightTheme] bodyTextColor];
  30. }
  31. } else {
  32. if (isNightMode) {
  33. textColor = [[themeManager darkTheme] bodyTextColor];
  34. } else {
  35. textColor = [[themeManager lightTheme] bodyTextColor];
  36. }
  37. }
  38. [themeManager release];
  39. } else {
  40. RUIThemeGuidance *themeGuidance = [%c(RUIThemeGuidance) sharedGuidance];
  41. textColor = [[themeGuidance currentTheme] bodyTextColor];
  42. }
  43. } else {
  44. if (secondVersionPart >= 45) {
  45. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  46. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  47. if (isNightMode) {
  48. textColor = [[themeManager darkTheme] bodyTextColor];
  49. } else {
  50. textColor = [[themeManager lightTheme] bodyTextColor];
  51. }
  52. [themeManager release];
  53. } else if (secondVersionPart >= 37) {
  54. themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  55. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  56. if (isNightMode) {
  57. textColor = [[themeManager nightTheme] bodyTextColor];
  58. } else {
  59. textColor = [[themeManager dayTheme] bodyTextColor];
  60. }
  61. [themeManager release];
  62. } else {
  63. themeManager = [%c(ThemeManager) sharedManager];
  64. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  65. if (isNightMode) {
  66. textColor = [[themeManager nightTheme] bodyTextColor];
  67. } else {
  68. textColor = [[themeManager dayTheme] bodyTextColor];
  69. }
  70. }
  71. }
  72. return textColor;
  73. }
  74. %hook CommentTreeNode
  75. %property(assign,nonatomic)id commentTreeHeaderNode;
  76. %property(assign,nonatomic)id commentTreeCommandBarNode;
  77. %end
  78. %hook CommentTreeHeaderView
  79. - (void)layoutSubviews {
  80. %orig;
  81. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  82. }
  83. %end
  84. %hook CommentTreeHeaderNode
  85. - (void)didLoad {
  86. %orig;
  87. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  88. }
  89. %end
  90. %hook CommentTreeCommandBarNode
  91. - (void)didLoad {
  92. %orig;
  93. [[self commentTreeNode] setCommentTreeCommandBarNode:self];
  94. }
  95. %end
  96. %hook CommentActionSheetViewController
  97. - (void)setItems:(id)arg1 {
  98. NSString *author = [[self comment] author];
  99. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  100. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  101. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  102. CGFloat scale = origImage.size.width / existingImageSize.width;
  103. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  104. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  105. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  106. [undeleteItem release];
  107. }
  108. %orig;
  109. }
  110. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  111. %orig;
  112. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  113. [self dismissViewControllerAnimated:YES completion:nil];
  114. id commentTreeNode = [self commentTreeNode];
  115. Comment *comment = [commentTreeNode comment];
  116. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  117. }
  118. }
  119. %new
  120. - (void)completeUndeleteCommentAction:(NSDictionary *)data {
  121. id commentTreeNode = [self commentTreeNode];
  122. Comment *comment = [commentTreeNode comment];
  123. NSString *author = data[@"author"];
  124. NSString *body = data[@"body"];
  125. UIColor *textColor = getCurrentTextColor();
  126. NSMutableAttributedString *bodyMutableAttributedText;
  127. bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  128. [bodyMutableAttributedText beginEditing];
  129. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  130. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  131. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  132. }];
  133. [bodyMutableAttributedText endEditing];
  134. [comment setAuthor:author];
  135. [comment setBodyText:body];
  136. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  137. if ((firstVersionPart == 2020 && secondVersionPart <= 39) || firstVersionPart == 4) {
  138. [comment setBodyAttributedText:bodyMutableAttributedText];
  139. }
  140. CommentTreeHeaderNode *headerNode = [commentTreeNode commentTreeHeaderNode];
  141. [headerNode updateContentViewsForData:comment];
  142. [headerNode configureNodes];
  143. if (firstVersionPart >= 2021) {
  144. CommentTreeTextNode *textNode = [[headerNode supernode] textNode];
  145. [textNode configureTextNode];
  146. }
  147. [bodyMutableAttributedText release];
  148. }
  149. %end
  150. %hook PostDetailViewController
  151. %property(strong,nonatomic) id feedPostTextWithThumbnailNode;
  152. %property(strong,nonatomic) id feedPostDetailCellNode;
  153. %end
  154. %hook FeedPostDetailCellNode
  155. - (void)didLoad {
  156. %orig;
  157. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  158. }
  159. %end
  160. %hook PostActionSheetViewController
  161. - (void)setItems:(id)arg1 {
  162. Post *post = [self post];
  163. NSString *author = [post author];
  164. if ([post isSelfPost]) {
  165. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  166. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  167. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  168. CGFloat scale = origImage.size.width / existingImageSize.width;
  169. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  170. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  171. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  172. [undeleteItem release];
  173. }
  174. }
  175. %orig;
  176. }
  177. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  178. %orig;
  179. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  180. [self dismissViewControllerAnimated:YES completion:nil];
  181. Post *post = [self post];
  182. if ([post isSelfPost]){
  183. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  184. }
  185. }
  186. }
  187. %new
  188. - (void)completeUndeletePostAction:(NSDictionary *)data {
  189. Post *post = [self post];
  190. NSString *author = data[@"author"];
  191. NSString *body = data[@"body"];
  192. UIColor *textColor = getCurrentTextColor();
  193. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  194. [bodyMutableAttributedText beginEditing];
  195. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  196. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  197. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  198. }];
  199. [bodyMutableAttributedText endEditing];
  200. [post setSelfText:body];
  201. [post setAuthor:author];
  202. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  203. FeedPostTitleNode *titleNode = [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode];
  204. Post *feedPost = [titleNode post];
  205. [feedPost setAuthor:author];
  206. if (firstVersionPart >= 2021) {
  207. RichTextDisplayNode *selfTextNode = [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] selfTextNode];
  208. [selfTextNode setAttributedText:bodyMutableAttributedText];
  209. [selfTextNode configureDisplayNodes];
  210. [titleNode configureNodes];
  211. } else if (firstVersionPart == 2020) {
  212. if (secondVersionPart >= 42) {
  213. RichTextDisplayNode *selfTextNode = [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] selfTextNode];
  214. [selfTextNode setAttributedText:bodyMutableAttributedText];
  215. [selfTextNode configureDisplayNodes];
  216. } else {
  217. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  218. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  219. }
  220. if (secondVersionPart >= 41) {
  221. [titleNode configureNodes];
  222. }
  223. } else {
  224. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  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 = 0;
  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 >= 2020 || (firstVersionPart == 4 && secondVersionPart > 32)) {
  452. %init(Reddit_v4_current);
  453. } else if (firstVersionPart == 4 && secondVersionPart <= 32) {
  454. %init(Reddit_v4_ios10);
  455. } else if (firstVersionPart == 3) {
  456. %init(Reddit_v3);
  457. }
  458. }
  459. }
  460. }