|
|
|
@ -7,6 +7,7 @@ |
|
|
|
// |
|
|
|
|
|
|
|
import SwiftUI |
|
|
|
import WebKit |
|
|
|
|
|
|
|
struct KBrowserView: View { |
|
|
|
@ObservedObject var viewModel = WebViewModel() |
|
|
|
@ -20,11 +21,33 @@ struct KBrowserView: View { |
|
|
|
@State var cookieString = "" |
|
|
|
|
|
|
|
var item: String |
|
|
|
var child = false |
|
|
|
var completionHandler: (() -> Void)? |
|
|
|
|
|
|
|
@State var videoModel: SVideoModel? |
|
|
|
@State private var showingAlert = false |
|
|
|
|
|
|
|
|
|
|
|
init(item: String, child: Bool = false, completionHandler: (() -> ())? = nil) { |
|
|
|
self.item = item |
|
|
|
self.completionHandler = completionHandler |
|
|
|
|
|
|
|
let m = $viewModel.popup |
|
|
|
|
|
|
|
if !child { |
|
|
|
viewModel.navigationHandler = { s in |
|
|
|
print(s) |
|
|
|
|
|
|
|
m.wrappedValue = false |
|
|
|
// |
|
|
|
// if s.contains("/scenes/") { |
|
|
|
// m.wrappedValue = true |
|
|
|
// } |
|
|
|
|
|
|
|
return m.wrappedValue |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// For WebView's forward and backward navigation |
|
|
|
var webViewNavigationBar: some View { |
|
|
|
VStack(spacing: 0) { |
|
|
|
@ -76,11 +99,23 @@ struct KBrowserView: View { |
|
|
|
VStack(spacing: 0) { |
|
|
|
HStack { |
|
|
|
Button(action: { |
|
|
|
self.viewModel.webViewNavigationPublisher.send(.backward) |
|
|
|
}, label: { |
|
|
|
Text("back") |
|
|
|
}) |
|
|
|
.buttonStyle(BorderlessButtonStyle()) |
|
|
|
Button(action: { |
|
|
|
completionHandler!() |
|
|
|
}, label: { |
|
|
|
Text("cancel") |
|
|
|
}) |
|
|
|
.buttonStyle(BorderlessButtonStyle()) |
|
|
|
Button(action: { |
|
|
|
toggleFilter() |
|
|
|
}, label: { |
|
|
|
Text("filter") |
|
|
|
}).foregroundColor(viewModel.filter ? Color.yellow : Color.blue) |
|
|
|
.buttonStyle(BorderlessButtonStyle()) |
|
|
|
Spacer() |
|
|
|
Text (serverMessage).foregroundColor(Color.blue) |
|
|
|
Button(action: { |
|
|
|
@ -152,6 +187,11 @@ struct KBrowserView: View { |
|
|
|
showVideoView = false |
|
|
|
}, model: videoModel!).background(Color.black) |
|
|
|
}) |
|
|
|
// .fullScreenCover(isPresented: $viewModel.popup, content: { |
|
|
|
// KBrowserView(item: viewModel.url!.absoluteString, child: false) { |
|
|
|
// viewModel.popup = false |
|
|
|
// } |
|
|
|
// }) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -160,13 +200,16 @@ struct KBrowserView: View { |
|
|
|
if let u = URL(string: s) { |
|
|
|
name = u.lastPathComponent |
|
|
|
if s.contains("720") { |
|
|
|
name = name + "720 " |
|
|
|
name = name + " 720 " |
|
|
|
} |
|
|
|
if s.contains("1080") { |
|
|
|
name = name + "1080 " |
|
|
|
name = name + " 1080 " |
|
|
|
} |
|
|
|
if s.contains("2160") { |
|
|
|
name = name + " 2160 " |
|
|
|
} |
|
|
|
if s.contains("480") { |
|
|
|
name = name + "480 " |
|
|
|
name = name + " 480 " |
|
|
|
} |
|
|
|
} |
|
|
|
return name |
|
|
|
@ -198,7 +241,7 @@ struct KBrowserView: View { |
|
|
|
mitem.externalURL = host + url |
|
|
|
} |
|
|
|
else { |
|
|
|
mitem.externalURL = url |
|
|
|
mitem.externalURL = url.replacingOccurrences(of: "//", with: "/") |
|
|
|
} |
|
|
|
|
|
|
|
mitem.cookies = cookieString |
|
|
|
@ -267,6 +310,49 @@ struct KBrowserView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func toggleFilter() { |
|
|
|
viewModel.filter = !viewModel.filter |
|
|
|
|
|
|
|
if (viewModel.filter) { |
|
|
|
let blockRules = """ |
|
|
|
[ |
|
|
|
{ |
|
|
|
"trigger": { |
|
|
|
"url-filter": ".*", |
|
|
|
"resource-type": ["image"] |
|
|
|
}, |
|
|
|
"action": { |
|
|
|
"type": "block" |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"trigger": { |
|
|
|
"url-filter": ".*", |
|
|
|
"resource-type": ["media"] |
|
|
|
}, |
|
|
|
"action": { |
|
|
|
"type": "block" |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
"""; |
|
|
|
|
|
|
|
|
|
|
|
WKContentRuleListStore.default().compileContentRuleList( |
|
|
|
forIdentifier: "ContentBlockingRules", |
|
|
|
encodedContentRuleList: blockRules) { (contentRuleList, error) in |
|
|
|
|
|
|
|
if let error = error { |
|
|
|
print(error) |
|
|
|
} |
|
|
|
|
|
|
|
viewModel.userContentController!.add(contentRuleList!) |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
viewModel.userContentController!.removeAllContentRuleLists() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
struct ContentView_Previews: PreviewProvider { |
|
|
|
|