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

Reddit.xm 21KB

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