forked from haoict/facebook-no-ads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.xm
177 lines (154 loc) · 6.21 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#import "Tweak.h"
/**
* Load Preferences
*/
BOOL noads;
BOOL canSaveVideo;
BOOL hideNewsFeedComposer;
BOOL hideNewsFeedRoom;
BOOL hideNewsFeedStories;
static void reloadPrefs() {
NSDictionary *settings = [[NSMutableDictionary alloc] initWithContentsOfFile:@PLIST_PATH] ?: [@{} mutableCopy];
noads = [[settings objectForKey:@"noads"] ?: @(YES) boolValue];
canSaveVideo = [[settings objectForKey:@"canSaveVideo"] ?: @(YES) boolValue];
hideNewsFeedComposer = [[settings objectForKey:@"hideNewsFeedComposer"] ?: @(NO) boolValue];
hideNewsFeedRoom = [[settings objectForKey:@"hideNewsFeedRoom"] ?: @(NO) boolValue];
hideNewsFeedStories = [[settings objectForKey:@"hideNewsFeedStories"] ?: @(NO) boolValue];
}
%group NoAds
%hook FBMemSponsoredData
- (id)initWithFBTree:(void *)arg1 {
return nil;
}
%end
%end
%group HideNewsFeedComposer
%hook FBNewsFeedViewControllerConfiguration
- (BOOL)shouldHideComposer {
return TRUE;
}
%end
%end
%group HideNewsFeedChatRoomStories
%hook FBComponentCollectionViewDataSource
- (id)collectionView:(id)arg1 cellForItemAtIndexPath:(NSIndexPath *)arg2 {
id orig = %orig;
if (![arg1 isKindOfClass:%c(FBNewsFeedCollectionView)]) {
return orig;
}
if ([self shouldHideSectionNumber:arg2.section]) {
[orig setHidden: YES];
} else {
[orig setHidden: NO];
}
return orig;
}
- (CGSize)collectionView:(id)arg1 layout:(id)arg2 sizeForItemAtIndexPath:(NSIndexPath *)arg3 {
CGSize orig = %orig;
if (![arg1 isKindOfClass:%c(FBNewsFeedCollectionView)]) {
return orig;
}
if ([self shouldHideSectionNumber:arg3.section]) {
orig.height = 1;
orig.width = 1;
}
return orig;
}
%new
- (BOOL)shouldHideSectionNumber:(int)sectionNumber {
if (hideNewsFeedComposer) {
if (sectionNumber == 0) {
return TRUE;
}
} else {
if (sectionNumber == 1) {
return TRUE;
}
}
return FALSE;
}
%end
%end
%group CanSaveVideo
%hook VideoContainerView
- (id)syc:(CGRect)arg1:(id)arg2 {
id orig = %orig;
[orig addHandleLongPress];
return orig;
}
%new
- (void)addHandleLongPress {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 0.5;
[self addGestureRecognizer:longPress];
}
%new
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Download Video" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSURL *videoURL = [self.controller currentVideoPlaybackItem].HDPlaybackURL;
if (!videoURL) {
videoURL = [self.controller currentVideoPlaybackItem].SDPlaybackURL;
}
NSString *videoURLString = videoURL.absoluteString;
[HCommon showToastMessage:@"Downloading in background..." withTitle:@"Please wait" timeout:1.0 viewController:nil];
[HDownloadMedia checkPermissionToPhotosAndDownload:videoURLString appendExtension:nil mediaType:Video toAlbum:@"Facebook"];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[[self reactViewController] presentViewController:alert animated:YES completion:nil];
}
}
%end
%hook FBVideoOverlayPluginComponentBackgroundView
- (id)initWithFrame:(struct CGRect)arg1 {
id orig = %orig;
[orig addHandleLongPress];
return orig;
}
%new
- (void)addHandleLongPress {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 0.5;
[self addGestureRecognizer:longPress];
}
%new
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
UIView *view = self.superview.superview.superview.superview;
if (![view isKindOfClass:%c(VideoContainerView)]) {
view = self.superview.subviews[1].subviews[0].subviews[0];
}
VideoContainerView *videoContainerView = (VideoContainerView *)view;
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Download Video" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSURL *videoURL = [videoContainerView.controller currentVideoPlaybackItem].HDPlaybackURL;
if (!videoURL) {
videoURL = [videoContainerView.controller currentVideoPlaybackItem].SDPlaybackURL;
}
NSString *videoURLString = videoURL.absoluteString;
[HCommon showToastMessage:@"Downloading in background..." withTitle:@"Please wait" timeout:1.0 viewController:nil];
[HDownloadMedia checkPermissionToPhotosAndDownload:videoURLString appendExtension:nil mediaType:Video toAlbum:@"Facebook"];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[[self reactViewController] presentViewController:alert animated:YES completion:nil];
}
}
%end
%end
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) reloadPrefs, CFSTR(PREF_CHANGED_NOTIF), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
reloadPrefs();
if (noads) {
%init(NoAds);
}
if (canSaveVideo) {
%init(CanSaveVideo);
}
if (hideNewsFeedComposer) {
%init(HideNewsFeedComposer);
}
if (hideNewsFeedRoom || hideNewsFeedStories) {
%init(HideNewsFeedChatRoomStories);
}
}