-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJavaScript.xm
46 lines (40 loc) · 1.31 KB
/
JavaScript.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
#import <Headers/Interfaces.h>
@import WebKit;
static void warningAlert(id self, NSString* message) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Warning" message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:ok];
[(UIViewController*)self presentViewController:alert animated:YES completion:nil];
}
%group JavaScript
%hook WKWebView
-(void)layoutSubviews {
%orig;
[self reload];
}
%end
%hook WKPreferences
-(void)setJavaScriptEnabled:(BOOL)arg1 {
arg1 = YES;
%orig;
}
-(BOOL)javaScriptEnabled {
return YES;
}
%end
%hook FeaturedViewController
-(void)viewDidAppear:(BOOL)arg1 {
%orig;
BOOL alertShown = [[[NSUserDefaults standardUserDefaults] objectForKey:@"ocean_jsWarningShown"] boolValue];
if (!alertShown) {
warningAlert(self, @"JavaScript is currently enabled for all repos, this means repos can show you ads and potentially malware. If you want to disable this feature, you can do so from Ocean's settings page.");
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"ocean_jsWarningShown"];
}
}
%end
%end
%ctor {
if ([prefs boolForKey:@"enableJS"]) {
%init(JavaScript);
}
}