-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTweak.xm
executable file
·180 lines (136 loc) · 4.43 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
177
178
179
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
static id addressView = nil;
static id buttonBar = nil;
static id navbars = nil;
static id button = nil;
static NSHTTPCookieAcceptPolicy policy;
static BOOL enabled = nil;
%hook AddressView
%new(v@:cc)
- (void)setPrivate:(BOOL)priv animated:(BOOL)animated {
UIView *bar = MSHookIvar<id>(self, "_gradientBar");
NSArray *subs = [bar subviews];
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
}
if (priv) {
for (UIView *s in subs) {
if ([s isKindOfClass:[UIImageView class]]) [s setAlpha:0.7f];
}
} else {
for (UIView *s in subs) {
if ([s isKindOfClass:[UIImageView class]]) [s setAlpha:1.0f];
}
}
if (animated) [UIView commitAnimations];
}
- (id)initWithFrame:(CGRect)frame {
return (addressView = %orig);
}
%end
%hook UINavigationBar
%new(v@:cc)
+ (void)setPrivate:(BOOL)priv animated:(BOOL)animated {
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
}
for (id nav in navbars) {
if (priv) [nav setTintColor:[UIColor grayColor]];
else [nav setTintColor:nil];
}
if (animated) [UIView commitAnimations];
}
- (id)initWithFrame:(CGRect)frame {
self = %orig;
[navbars addObject:self];
[[self class] setPrivate:enabled animated:NO];
return self;
}
- (void)dealloc {
[navbars removeObject:self];
%orig;
}
%end
%hook BrowserButtonBar
%new(v@:cc)
- (void)setPrivate:(BOOL)priv animated:(BOOL)animated {
if (animated) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
}
if (priv) [self setTintColor:[UIColor grayColor]];
else [self setTintColor:nil];
if (animated) [UIView commitAnimations];
}
- (void)setFrame:(CGRect)frame {
%orig;
// XXX: i fail, and i know it
if (frame.size.height < 44.0f)
[button setFrame:CGRectMake(180.0f, 5.0f, 120.0f, 24.0f)];
else
[button setFrame:CGRectMake(112.0f, 8.0f, 120.0f, 30.0f)];
}
%end
%hook WebHistory
// XXX: (jedi mind trick:) you did /not/ see this
- (void)_visitedURL:(NSURL *)url withTitle:(NSString *)title method:(NSString *)method wasFailure:(BOOL)wasFailure increaseVisitCount:(BOOL)increaseVisitCount {
if (!enabled) %orig;
}
%end
%hook BrowserController
- (void)addRecentSearch:(id)search {
if (!enabled) %orig;
}
- (void)setShowingTabs:(BOOL)tabs {
%orig;
if (tabs) [buttonBar addSubview:button];
else [button removeFromSuperview];
}
%end
%hook Application
%new(v@:)
- (void)togglePrivate {
enabled = !enabled;
if (enabled) {
policy = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookieAcceptPolicy];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever];
[[NSUserDefaults standardUserDefaults] setInteger:policy forKey:@"CovertCookiePolicy"];
} else {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:policy];
}
if (enabled) {
[button setStyle:(UIBarButtonItemStyle)2];
[button setTitle:@"Exit Private" forState:UIControlStateNormal];
} else {
[button setStyle:(UIBarButtonItemStyle)0];
[button setTitle:@"Private Browsing" forState:UIControlStateNormal];
[MSHookIvar<id>(addressView, "_searchTextField") setText:@""];
}
[buttonBar setPrivate:enabled animated:YES];
[addressView setPrivate:enabled animated:YES];
[UINavigationBar setPrivate:enabled animated:YES];
}
- (void)applicationWillTerminate:(UIApplication *)application {
%orig;
[[NSUserDefaults standardUserDefaults] setInteger:policy forKey:@"CovertCookiePolicy"];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:policy];
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
%orig;
navbars = [[NSMutableArray alloc] init];
buttonBar = [[%c(BrowserController) sharedBrowserController] buttonBar];
if ([[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys] containsObject:@"CovertCookiePolicy"]) {
policy = [[NSUserDefaults standardUserDefaults] integerForKey:@"CovertCookiePolicy"];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:policy];
} else {
policy = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookieAcceptPolicy];
[[NSUserDefaults standardUserDefaults] setInteger:policy forKey:@"CovertCookiePolicy"];
}
button = [[%c(UINavigationButton) alloc] initWithTitle:@"Private Browsing"];
[button addTarget:self action:@selector(togglePrivate) forControlEvents:UIControlEventTouchUpInside];
[buttonBar setFrame:[buttonBar frame]];
}
%end