diff --git a/ReaderTranslator.xcodeproj/project.pbxproj b/ReaderTranslator.xcodeproj/project.pbxproj index 0c3700f..18f5e41 100644 --- a/ReaderTranslator.xcodeproj/project.pbxproj +++ b/ReaderTranslator.xcodeproj/project.pbxproj @@ -61,6 +61,10 @@ F033F41523A75B5600605325 /* SentencesView_Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = F033F41423A75B5600605325 /* SentencesView_Row.swift */; }; F0369E3223A2D92C00C33139 /* StatusBarView_Sync.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0369E3123A2D92C00C33139 /* StatusBarView_Sync.swift */; }; F0369E3323A2D92C00C33139 /* StatusBarView_Sync.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0369E3123A2D92C00C33139 /* StatusBarView_Sync.swift */; }; + F038B00B241112D8006B8C1F /* gtranslator.js in Resources */ = {isa = PBXBuildFile; fileRef = F038B00A241112D8006B8C1F /* gtranslator.js */; }; + F038B00E2411337C006B8C1F /* gtranslator.js in Resources */ = {isa = PBXBuildFile; fileRef = F038B00C24113331006B8C1F /* gtranslator.js */; }; + F038B00F24113388006B8C1F /* gtranslator.js in Resources */ = {isa = PBXBuildFile; fileRef = F038B00C24113331006B8C1F /* gtranslator.js */; }; + F038B01724116964006B8C1F /* GTranslatorMiniView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F038B01624116964006B8C1F /* GTranslatorMiniView.swift */; }; F040512B23ABDBDB00A5240C /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0C36A9C2359C78A001E396C /* Array.swift */; }; F040D5782336A77D004567B8 /* UserDefault.swift in Sources */ = {isa = PBXBuildFile; fileRef = F040D5772336A77D004567B8 /* UserDefault.swift */; }; F040D57C2336BD97004567B8 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = F040D57B2336BD97004567B8 /* README.md */; }; @@ -604,6 +608,9 @@ F033F41123A6D3A800605325 /* DirectoryObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryObserver.swift; sourceTree = ""; }; F033F41423A75B5600605325 /* SentencesView_Row.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentencesView_Row.swift; sourceTree = ""; }; F0369E3123A2D92C00C33139 /* StatusBarView_Sync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarView_Sync.swift; sourceTree = ""; }; + F038B00A241112D8006B8C1F /* gtranslator.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = gtranslator.js; sourceTree = ""; }; + F038B00C24113331006B8C1F /* gtranslator.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = gtranslator.js; sourceTree = ""; }; + F038B01624116964006B8C1F /* GTranslatorMiniView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GTranslatorMiniView.swift; sourceTree = ""; }; F03D7DFD234DF59500E53E3D /* files */ = {isa = PBXFileReference; lastKnownFileType = folder; path = files; sourceTree = ""; }; F040D5772336A77D004567B8 /* UserDefault.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefault.swift; sourceTree = ""; }; F040D57B2336BD97004567B8 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; @@ -941,6 +948,14 @@ path = SentencesView; sourceTree = ""; }; + F038B00724111225006B8C1F /* Scripts */ = { + isa = PBXGroup; + children = ( + F038B00A241112D8006B8C1F /* gtranslator.js */, + ); + path = Scripts; + sourceTree = ""; + }; F04924372341F2F800F3C728 /* Recovered References */ = { isa = PBXGroup; children = ( @@ -1074,6 +1089,7 @@ isa = PBXGroup; children = ( F09459C3240930D8001EC43D /* GTranslatorView.swift */, + F038B01624116964006B8C1F /* GTranslatorMiniView.swift */, F09459BC24093031001EC43D /* ReaderView_Pdf.swift */, F09459D52409320E001EC43D /* MacmillanView.swift */, F09459DB24093230001EC43D /* SafariView.swift */, @@ -1094,6 +1110,7 @@ F09760BB240925680030F928 /* ReaderTranslatorMobile */ = { isa = PBXGroup; children = ( + F038B00724111225006B8C1F /* Scripts */, F09760D5240926C40030F928 /* Delegates */, F09459BB24093020001EC43D /* Views */, F09760C0240925680030F928 /* ContentView.swift */, @@ -1335,6 +1352,7 @@ children = ( F058C7ED2396ACC0002C84F0 /* reverso-reverso-speaker.js */, F075445923447A2800E1D88E /* reader-translator.js */, + F038B00C24113331006B8C1F /* gtranslator.js */, F058C7F12397A180002C84F0 /* longman.json */, F08D45BD240E9B4D00E7A08E /* cambridge.json */, F0E5BC6623D630DF004DACE5 /* merriam-webster.json */, @@ -1650,6 +1668,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + F038B00F24113388006B8C1F /* gtranslator.js in Resources */, F058C7FD2397FBCD002C84F0 /* longman.json in Resources */, F0120382239182DC008D0B47 /* LaunchScreen.storyboard in Resources */, F012037F239182DC008D0B47 /* Preview Assets.xcassets in Resources */, @@ -1662,6 +1681,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + F038B00E2411337C006B8C1F /* gtranslator.js in Resources */, F08D45BE240E9CDC00E7A08E /* cambridge.json in Resources */, F058C7F22397A94D002C84F0 /* longman.json in Resources */, F0C36AA7235ADF5E001E396C /* reader-translator.js in Resources */, @@ -1690,6 +1710,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + F038B00B241112D8006B8C1F /* gtranslator.js in Resources */, F09760C92409256C0030F928 /* LaunchScreen.storyboard in Resources */, F09760C62409256C0030F928 /* Preview Assets.xcassets in Resources */, F09459A924092E0E001EC43D /* reverso-reverso-speaker.js in Resources */, @@ -2098,6 +2119,7 @@ F09760C1240925680030F928 /* ContentView.swift in Sources */, F09760E22409280E0030F928 /* String.swift in Sources */, F094597D24092D1B001EC43D /* StackView.swift in Sources */, + F038B01724116964006B8C1F /* GTranslatorMiniView.swift in Sources */, F09459CA240931AC001EC43D /* WikipediaView.swift in Sources */, F09459D0240931E2001EC43D /* ReversoView.swift in Sources */, F094599424092D7E001EC43D /* NetBrowser.swift in Sources */, diff --git a/ReaderTranslator/Components/ViewRepresentable/GTranslatorRepresenter.swift b/ReaderTranslator/Components/ViewRepresentable/GTranslatorRepresenter.swift index bee6ca2..1eb6bfc 100644 --- a/ReaderTranslator/Components/ViewRepresentable/GTranslatorRepresenter.swift +++ b/ReaderTranslator/Components/ViewRepresentable/GTranslatorRepresenter.swift @@ -12,6 +12,9 @@ import WebKit struct GTranslatorRepresenter: ViewRepresentable, WKScriptsSetup { @Binding var selectedText: TranslateAction + static var isMiniMode: Bool = false { + didSet { setMiniMode() } + } static var coorinator: Coordinator? static var pageView: WKPageView? @@ -53,6 +56,8 @@ struct GTranslatorRepresenter: ViewRepresentable, WKScriptsSetup { setupScriptCoordinator(view: view, coordinator: context.coordinator) setupScript(view: view, file: "gtranslator-reverso-speaker") + setupScript(view: view, file: "gtranslator") + Self.setMiniMode() return view } @@ -93,6 +98,11 @@ struct GTranslatorRepresenter: ViewRepresentable, WKScriptsSetup { return (slValue, tlValue) } + + static private func setMiniMode() { + let mode = isMiniMode ? "mini" : "full" + GTranslatorRepresenter.pageView?.evaluateJavaScript("readerTranslatorMode('\(mode)')") + } } extension GTranslatorRepresenter.Coordinator: WKScriptMessageHandler { diff --git a/ReaderTranslator/Components/ViewRepresentable/Scripts/gtranslator.js b/ReaderTranslator/Components/ViewRepresentable/Scripts/gtranslator.js new file mode 100644 index 0000000..23eeb5a --- /dev/null +++ b/ReaderTranslator/Components/ViewRepresentable/Scripts/gtranslator.js @@ -0,0 +1,10 @@ +(function() { + const css = " \ + #source { font-size: 18px!important; } \ + .translation { font-size: 18px!important; } \ + " + + var style = document.createElement('style') + style.innerHTML = css + document.head.appendChild(style) +})() diff --git a/ReaderTranslatorMac/Info.plist b/ReaderTranslatorMac/Info.plist index 1a66397..9b49a67 100644 --- a/ReaderTranslatorMac/Info.plist +++ b/ReaderTranslatorMac/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 1.11.0 + 1.11.1 CFBundleVersion 1800 LSApplicationCategoryType diff --git a/ReaderTranslatorMobile/ContentView.swift b/ReaderTranslatorMobile/ContentView.swift index b525156..1c37edf 100644 --- a/ReaderTranslatorMobile/ContentView.swift +++ b/ReaderTranslatorMobile/ContentView.swift @@ -8,19 +8,37 @@ import SwiftUI +struct LazyView: View { + let build: () -> Content + init(_ build: @autoclosure @escaping () -> Content) { + self.build = build + } + + var body: Content { + build() + } +} + struct ContentView: View { @State var isShow = false - + init() { ViewsStore.shared.enabledViews = [.gTranslator, .web] } - + var body: some View { NavigationView { VStack { - NavigationLink(destination: GTranslatorView(), isActive: $isShow) { EmptyView() } + NavigationLink( + destination: GTranslatorView(), + isActive: $isShow + ) { + EmptyView() + } WebView() + if !isShow { GTranslatorMiniView().frame(height: 200) } } + .edgesIgnoringSafeArea(.bottom) .navigationBarTitle("ReaderTranslator", displayMode: .inline) .navigationBarItems(trailing: Button("Translate") { self.isShow = true }) } diff --git a/ReaderTranslatorMobile/Scripts/gtranslator.js b/ReaderTranslatorMobile/Scripts/gtranslator.js new file mode 100644 index 0000000..71f825a --- /dev/null +++ b/ReaderTranslatorMobile/Scripts/gtranslator.js @@ -0,0 +1,22 @@ +(function() { + const css = " \ + .reader-mini #gb, .reader-mini .tlid-input, .reader-mini .gp-footer { display: none; } \ + #source { font-size: 18px!important; } \ + .translation { font-size: 18px!important; } \ + " + + let style = document.createElement('style') + style.innerHTML = css + document.head.appendChild(style) + + let mode = localStorage.getItem('readerTranslatorMode') || 'full' + readerTranslatorMode(mode) +})() + +function readerTranslatorMode(mode) { + localStorage.setItem('readerTranslatorMode', mode) + let elm = document.querySelector('body') + elm.className = elm.className.replace('reader-mini', '') + + if(mode=='mini') { elm.className += " reader-mini" } +} diff --git a/ReaderTranslatorMobile/Views/BookmarksView.swift b/ReaderTranslatorMobile/Views/BookmarksView.swift index 4d47ded..1efab77 100644 --- a/ReaderTranslatorMobile/Views/BookmarksView.swift +++ b/ReaderTranslatorMobile/Views/BookmarksView.swift @@ -10,7 +10,7 @@ import SwiftUI struct BookmarksView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/CollinsView.swift b/ReaderTranslatorMobile/Views/CollinsView.swift index 8a547e4..66ea6c3 100644 --- a/ReaderTranslatorMobile/Views/CollinsView.swift +++ b/ReaderTranslatorMobile/Views/CollinsView.swift @@ -10,7 +10,7 @@ import SwiftUI struct CollinsView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/GTranslatorMiniView.swift b/ReaderTranslatorMobile/Views/GTranslatorMiniView.swift new file mode 100644 index 0000000..4d44144 --- /dev/null +++ b/ReaderTranslatorMobile/Views/GTranslatorMiniView.swift @@ -0,0 +1,26 @@ +// +// GTranslatorView.swift +// ReaderTranslatorMobile +// +// Created by Viktor Kushnerov on 28/2/20. +// Copyright © 2020 Viktor Kushnerov. All rights reserved. +// + +import SwiftUI + +struct GTranslatorMiniView: View { + @ObservedObject private var store = Store.shared + + var body: some View { + GTranslatorRepresenter(selectedText: self.$store.translateAction) + .onAppear { + GTranslatorRepresenter.isMiniMode = true + } + } +} + +struct GTranslatorMiniView_Previews: PreviewProvider { + static var previews: some View { + GTranslatorMiniView() + } +} diff --git a/ReaderTranslatorMobile/Views/GTranslatorView.swift b/ReaderTranslatorMobile/Views/GTranslatorView.swift index fd1193b..8045c12 100644 --- a/ReaderTranslatorMobile/Views/GTranslatorView.swift +++ b/ReaderTranslatorMobile/Views/GTranslatorView.swift @@ -13,6 +13,9 @@ struct GTranslatorView: View { var body: some View { GTranslatorRepresenter(selectedText: self.$store.translateAction) + .onAppear { + GTranslatorRepresenter.isMiniMode = false + } } } diff --git a/ReaderTranslatorMobile/Views/LongmanView.swift b/ReaderTranslatorMobile/Views/LongmanView.swift index 25e1e98..636a20d 100644 --- a/ReaderTranslatorMobile/Views/LongmanView.swift +++ b/ReaderTranslatorMobile/Views/LongmanView.swift @@ -10,7 +10,7 @@ import SwiftUI struct LongmanView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/MacmillanView.swift b/ReaderTranslatorMobile/Views/MacmillanView.swift index 6d81462..b299997 100644 --- a/ReaderTranslatorMobile/Views/MacmillanView.swift +++ b/ReaderTranslatorMobile/Views/MacmillanView.swift @@ -10,7 +10,7 @@ import SwiftUI struct MacmillanView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/MerriamWebsterView.swift b/ReaderTranslatorMobile/Views/MerriamWebsterView.swift index 4294b9a..9a5e1b2 100644 --- a/ReaderTranslatorMobile/Views/MerriamWebsterView.swift +++ b/ReaderTranslatorMobile/Views/MerriamWebsterView.swift @@ -10,7 +10,7 @@ import SwiftUI struct MerriamWebsterView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/ReaderView_Pdf.swift b/ReaderTranslatorMobile/Views/ReaderView_Pdf.swift index 1a7becf..2608acf 100644 --- a/ReaderTranslatorMobile/Views/ReaderView_Pdf.swift +++ b/ReaderTranslatorMobile/Views/ReaderView_Pdf.swift @@ -10,7 +10,7 @@ import SwiftUI struct ReaderView_Pdf: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/ReaderView_Web.swift b/ReaderTranslatorMobile/Views/ReaderView_Web.swift index 7c3c81b..e457329 100644 --- a/ReaderTranslatorMobile/Views/ReaderView_Web.swift +++ b/ReaderTranslatorMobile/Views/ReaderView_Web.swift @@ -10,7 +10,7 @@ import SwiftUI struct ReaderView_Web: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/ReversoView.swift b/ReaderTranslatorMobile/Views/ReversoView.swift index 2320faa..5f54693 100644 --- a/ReaderTranslatorMobile/Views/ReversoView.swift +++ b/ReaderTranslatorMobile/Views/ReversoView.swift @@ -10,7 +10,7 @@ import SwiftUI struct ReversoView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/SafariView.swift b/ReaderTranslatorMobile/Views/SafariView.swift index f17b682..ef932a6 100644 --- a/ReaderTranslatorMobile/Views/SafariView.swift +++ b/ReaderTranslatorMobile/Views/SafariView.swift @@ -10,7 +10,7 @@ import SwiftUI struct SafariView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/StackExchangeView.swift b/ReaderTranslatorMobile/Views/StackExchangeView.swift index 7b38749..7add19b 100644 --- a/ReaderTranslatorMobile/Views/StackExchangeView.swift +++ b/ReaderTranslatorMobile/Views/StackExchangeView.swift @@ -10,7 +10,7 @@ import SwiftUI struct StackExchangeView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/WikipediaView.swift b/ReaderTranslatorMobile/Views/WikipediaView.swift index be3e0f9..db7ef8b 100644 --- a/ReaderTranslatorMobile/Views/WikipediaView.swift +++ b/ReaderTranslatorMobile/Views/WikipediaView.swift @@ -10,7 +10,7 @@ import SwiftUI struct WikipediaView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/ReaderTranslatorMobile/Views/YTranslatorView.swift b/ReaderTranslatorMobile/Views/YTranslatorView.swift index 826adfe..c7e9038 100644 --- a/ReaderTranslatorMobile/Views/YTranslatorView.swift +++ b/ReaderTranslatorMobile/Views/YTranslatorView.swift @@ -10,7 +10,7 @@ import SwiftUI struct YTranslatorView: View { var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + Text("Not implemented") } } diff --git a/files/Release_1.11.1_1.gif b/files/Release_1.11.1_1.gif new file mode 100644 index 0000000..33ee459 Binary files /dev/null and b/files/Release_1.11.1_1.gif differ