From c15ca3b7df794a9aa35c0b91108eec2c1b213f0f Mon Sep 17 00:00:00 2001 From: Jason Morley Date: Tue, 15 Jun 2021 10:15:32 -0700 Subject: [PATCH] feat: Open links on the Internet Archive from the context menu (#125) --- core/BookmarksCore.xcodeproj/project.pbxproj | 6 ++++ core/BookmarksCore/Extensions/URL.swift | 29 ++++++++++++++++++++ macos/Bookmarks/Views/ContentView.swift | 4 +++ 3 files changed, 39 insertions(+) create mode 100644 core/BookmarksCore/Extensions/URL.swift diff --git a/core/BookmarksCore.xcodeproj/project.pbxproj b/core/BookmarksCore.xcodeproj/project.pbxproj index b19b0882..d92981cd 100644 --- a/core/BookmarksCore.xcodeproj/project.pbxproj +++ b/core/BookmarksCore.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ D84CE488261E2B7D00AF1901 /* Pinboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84CE487261E2B7D00AF1901 /* Pinboard.swift */; }; D8569FCC261E2603006926BF /* BookmarksCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D8569FC2261E2603006926BF /* BookmarksCore.framework */; }; D8569FD3261E2603006926BF /* BookmarksCore.h in Headers */ = {isa = PBXBuildFile; fileRef = D8569FC5261E2603006926BF /* BookmarksCore.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D8717C4E2679153F007617C5 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8717C4D2679153F007617C5 /* URL.swift */; }; + D8717C4F2679153F007617C5 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8717C4D2679153F007617C5 /* URL.swift */; }; D8AA4055261E2E8D00D11421 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8AA4054261E2E8D00D11421 /* String.swift */; }; D8AA4061261E305200D11421 /* NSCoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8AA4060261E305200D11421 /* NSCoder.swift */; }; D8B04B1E261EC65D00376ADD /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B04B1D261EC65C00376ADD /* Settings.swift */; }; @@ -100,6 +102,7 @@ D8569FC6261E2603006926BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; D8569FCB261E2603006926BF /* BookmarksCore iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "BookmarksCore iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; D8569FD2261E2603006926BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D8717C4D2679153F007617C5 /* URL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = ""; }; D8AA4054261E2E8D00D11421 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = ""; }; D8AA4060261E305200D11421 /* NSCoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSCoder.swift; sourceTree = ""; }; D8B04B1D261EC65C00376ADD /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; @@ -240,6 +243,7 @@ D8AA4060261E305200D11421 /* NSCoder.swift */, D8AA4054261E2E8D00D11421 /* String.swift */, D8D3F5B4261E5AF300B2D66F /* UIImage.swift */, + D8717C4D2679153F007617C5 /* URL.swift */, D8D3F601261E5BF600B2D66F /* URLComponents.swift */, D8D3F610261E5C0C00B2D66F /* View.swift */, ); @@ -519,6 +523,7 @@ D8D3F59F261E5AAE00B2D66F /* WebViewDownloader.swift in Sources */, D8B04B1F261EC65D00376ADD /* Settings.swift in Sources */, D84CE484261E2AD000AF1901 /* Post.swift in Sources */, + D8717C4E2679153F007617C5 /* URL.swift in Sources */, D8B04B31261EC7E700376ADD /* BookmarksManager.swift in Sources */, D8D3F602261E5BF600B2D66F /* URLComponents.swift in Sources */, D8AA4055261E2E8D00D11421 /* String.swift in Sources */, @@ -560,6 +565,7 @@ D8D3F59E261E5AAE00B2D66F /* WebViewDownloader.swift in Sources */, D8B04B1E261EC65D00376ADD /* Settings.swift in Sources */, D8CF8CA1261E35B300E52E85 /* Pinboard.swift in Sources */, + D8717C4F2679153F007617C5 /* URL.swift in Sources */, D8B04B32261EC7E700376ADD /* BookmarksManager.swift in Sources */, D8D3F603261E5BF600B2D66F /* URLComponents.swift in Sources */, D8CF8CB0261E35BB00E52E85 /* String.swift in Sources */, diff --git a/core/BookmarksCore/Extensions/URL.swift b/core/BookmarksCore/Extensions/URL.swift new file mode 100644 index 00000000..b2a0108b --- /dev/null +++ b/core/BookmarksCore/Extensions/URL.swift @@ -0,0 +1,29 @@ +// Copyright (c) 2020-2021 InSeven Limited +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +import Foundation + +public extension URL { + + var internetArchiveUrl: URL { + URL(string: "https://web.archive.org/web/*/")!.appendingPathComponent(self.absoluteString) + } + +} diff --git a/macos/Bookmarks/Views/ContentView.swift b/macos/Bookmarks/Views/ContentView.swift index 293cdc2f..c104f81f 100644 --- a/macos/Bookmarks/Views/ContentView.swift +++ b/macos/Bookmarks/Views/ContentView.swift @@ -53,6 +53,10 @@ struct ContentView: View { NSWorkspace.shared.open(item.url) } Divider() + Button("View on Internet Archive") { + NSWorkspace.shared.open(item.url.internetArchiveUrl) + } + Divider() Button("Share") { print("Share") print(item.identifier)