Redirect rules: for example, twitter->nitter
This commit is contained in:
24
App/Backend/PersonalRedirectRules.swift
Normal file
24
App/Backend/PersonalRedirectRules.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// PersonalRedirectRules.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 9/30/20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class PersonalRedirectRules
|
||||
{
|
||||
func redirectedURL(for url: URL) -> URL? {
|
||||
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false) {
|
||||
|
||||
// Rule for nitter.net
|
||||
if url.host == "twitter.com" {
|
||||
components.host = "nitter.net"
|
||||
return components.url
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
private let toolbarController = ToolbarViewController()
|
||||
|
||||
private let autocompleteViewController = AutocompleteViewController()
|
||||
private let redirectRules = PersonalRedirectRules()
|
||||
|
||||
private var policyManager: ResourcePolicyManager { tabController.policyManager }
|
||||
|
||||
@@ -373,8 +374,16 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
}
|
||||
|
||||
preferences.allowsContentJavaScript = allowJavaScript
|
||||
|
||||
if let url = navigationAction.request.url,
|
||||
let redirectedURL = redirectRules.redirectedURL(for: url)
|
||||
{
|
||||
tab.beginLoadingURL(redirectedURL)
|
||||
decisionHandler(.cancel, preferences)
|
||||
} else {
|
||||
decisionHandler(.allow, preferences)
|
||||
}
|
||||
}
|
||||
|
||||
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
||||
self.loadError = error
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
1AB88EFD24D3BA560006F850 /* TabController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB88EFC24D3BA560006F850 /* TabController.swift */; };
|
||||
1AB88EFF24D3BBA50006F850 /* TabPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB88EFE24D3BBA50006F850 /* TabPickerViewController.swift */; };
|
||||
1AB88F0624D4D3A90006F850 /* UIGestureRecognizer+Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB88F0524D4D3A90006F850 /* UIGestureRecognizer+Actions.swift */; };
|
||||
1AD3103D252541E600A4A952 /* PersonalRedirectRules.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD3103C252541E600A4A952 /* PersonalRedirectRules.swift */; };
|
||||
1ADFF46024C7DE53006DC7AE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF45F24C7DE53006DC7AE /* AppDelegate.swift */; };
|
||||
1ADFF46224C7DE53006DC7AE /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF46124C7DE53006DC7AE /* SceneDelegate.swift */; };
|
||||
1ADFF46924C7DE54006DC7AE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1ADFF46824C7DE54006DC7AE /* Assets.xcassets */; };
|
||||
@@ -83,6 +84,7 @@
|
||||
1AB88EFC24D3BA560006F850 /* TabController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabController.swift; sourceTree = "<group>"; };
|
||||
1AB88EFE24D3BBA50006F850 /* TabPickerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabPickerViewController.swift; sourceTree = "<group>"; };
|
||||
1AB88F0524D4D3A90006F850 /* UIGestureRecognizer+Actions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIGestureRecognizer+Actions.swift"; sourceTree = "<group>"; };
|
||||
1AD3103C252541E600A4A952 /* PersonalRedirectRules.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonalRedirectRules.swift; sourceTree = "<group>"; };
|
||||
1ADFF45C24C7DE53006DC7AE /* rossler\\attix.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "rossler\\\\attix.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
1ADFF45F24C7DE53006DC7AE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
1ADFF46124C7DE53006DC7AE /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
|
||||
@@ -247,6 +249,7 @@
|
||||
children = (
|
||||
CD853BD224E77BEF00D2BDCC /* History */,
|
||||
1ADFF4AD24C8ED32006DC7AE /* ResourcePolicyManager.swift */,
|
||||
1AD3103C252541E600A4A952 /* PersonalRedirectRules.swift */,
|
||||
);
|
||||
path = Backend;
|
||||
sourceTree = "<group>";
|
||||
@@ -446,6 +449,7 @@
|
||||
1A03810D24E71CA700826501 /* ToolbarView.swift in Sources */,
|
||||
CD853BD424E77BF900D2BDCC /* HistoryItem.swift in Sources */,
|
||||
1ADFF48D24C8C176006DC7AE /* SBRProcessBundleBridge.m in Sources */,
|
||||
1AD3103D252541E600A4A952 /* PersonalRedirectRules.swift in Sources */,
|
||||
1AB88F0624D4D3A90006F850 /* UIGestureRecognizer+Actions.swift in Sources */,
|
||||
1ADFF46224C7DE53006DC7AE /* SceneDelegate.swift in Sources */,
|
||||
CD853BCE24E7763900D2BDCC /* BrowserHistory.swift in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user