diff --git a/Easydict/objc/ViewController/View/WordResultView/EZWordResultView.m b/Easydict/objc/ViewController/View/WordResultView/EZWordResultView.m index 8d687d273..239175dc8 100644 --- a/Easydict/objc/ViewController/View/WordResultView/EZWordResultView.m +++ b/Easydict/objc/ViewController/View/WordResultView/EZWordResultView.m @@ -542,7 +542,7 @@ - (void)refreshWithResult:(EZQueryResult *)result { // 同义词 if (result.wordResult.synonyms.count) { - lastView = [self buildSynonymsAndAntonymsView:NSLocalizedString(@"synonyms", nil) + lastView = [self createSectionViewForSynonymsOrAntonyms:NSLocalizedString(@"synonyms", nil) parts:result.wordResult.synonyms textColor:typeTextColor typeTextFont:typeTextFont @@ -552,7 +552,7 @@ - (void)refreshWithResult:(EZQueryResult *)result { // 反义词 if (result.wordResult.antonyms.count) { - lastView = [self buildSynonymsAndAntonymsView:NSLocalizedString(@"antonyms", nil) + lastView = [self createSectionViewForSynonymsOrAntonyms:NSLocalizedString(@"antonyms", nil) parts:result.wordResult.antonyms textColor:typeTextColor typeTextFont:typeTextFont @@ -562,7 +562,7 @@ - (void)refreshWithResult:(EZQueryResult *)result { // 搭配 if (result.wordResult.collocation.count) { - lastView = [self buildSynonymsAndAntonymsView:NSLocalizedString(@"collocation", nil) + lastView = [self createSectionViewForSynonymsOrAntonyms:NSLocalizedString(@"collocation", nil) parts:result.wordResult.collocation textColor:typeTextColor typeTextFont:typeTextFont @@ -890,18 +890,18 @@ - (void)setupBottomToolBarButtons:(EZQueryResult *)result lastView:(NSView *)las } } -- (NSView *)buildSynonymsAndAntonymsView:(NSString *)title - parts:(NSArray *)parts - textColor:(NSColor *)typeTextColor - typeTextFont:(NSFont *)typeTextFont - height:(CGFloat *)height - lastView:(NSView *)lastView { +- (NSView *)createSectionViewForSynonymsOrAntonyms:(NSString *)sectionTitle + parts:(NSArray *)parts + textColor:(NSColor *)typeTextColor + typeTextFont:(NSFont *)typeTextFont + height:(CGFloat *)height + lastView:(NSView *)lastView { __block NSView *rtnView = lastView; EZLabel *synonymsTitle = [[EZLabel alloc] init]; [self addSubview:synonymsTitle]; synonymsTitle.font = typeTextFont; synonymsTitle.textForegroundColor = typeTextColor; - synonymsTitle.text = title; + synonymsTitle.text = sectionTitle; [synonymsTitle mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(kHorizontalMargin_8); if (rtnView) { @@ -919,7 +919,7 @@ - (NSView *)buildSynonymsAndAntonymsView:(NSString *)title }]; rtnView = synonymsTitle; - mm_weakify(self) + mm_weakify(self); [parts enumerateObjectsUsingBlock:^(EZTranslatePart *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) { if (obj.means.count == 0) return; @@ -1195,21 +1195,21 @@ - (void)updateWebViewBackgroundColorWithDarkMode:(BOOL)isDark { - (NSString *)jsCodeOfUpdateAllIframeTextColor:(NSString *)color backgroundColor:(NSString *)backgroundColor { NSString *jsCode = [NSString stringWithFormat:@"" - "var iframes = document.querySelectorAll('iframe');" - "for (var i = 0; i < iframes.length; i++) {" - " iframes[i].contentDocument.body.style.webkitTextFillColor = '%@';" - " iframes[i].contentDocument.body.style.backgroundColor = '%@';" - "};", - color, backgroundColor]; + "var iframes = document.querySelectorAll('iframe');" + "for (var i = 0; i < iframes.length; i++) {" + " iframes[i].contentDocument.body.style.webkitTextFillColor = '%@';" + " iframes[i].contentDocument.body.style.backgroundColor = '%@';" + "};", + color, backgroundColor]; return jsCode; } - (NSString *)jsCodeOfUpdateBodyTextColor:(NSString *)color backgroundColor:(NSString *)backgroundColor { NSString *jsCode = [NSString stringWithFormat:@"" - @"document.body.style.webkitTextFillColor='%@';" - @"document.body.style.backgroundColor='%@';", - color, backgroundColor]; + @"document.body.style.webkitTextFillColor='%@';" + @"document.body.style.backgroundColor='%@';", + color, backgroundColor]; return jsCode; } @@ -1221,8 +1221,8 @@ - (NSString *)jsCodeOfUpdateStyleHeight:(CGFloat)height { - (NSString *)jsCodeOfOptimizeScrollableWebView { NSString *showScrollbarBriefly = @"" - @"window.scrollTo(0, 1);" - @"setTimeout(function () { window.scrollTo(0, 0); }, 0);"; + @"window.scrollTo(0, 1);" + @"setTimeout(function () { window.scrollTo(0, 0); }, 0);"; NSString *jsCode = [NSString stringWithFormat:@"%@", showScrollbarBriefly]; return jsCode; @@ -1247,13 +1247,13 @@ - (void)evaluateJavaScript:(NSString *)jsCode completionHandler:(void (^_Nullabl - (void)fetchWebViewAllIframeText:(void (^_Nullable)(NSString *text))completionHandler { NSString *jsCode = @"" - "var iframes = document.querySelectorAll('iframe');" - "var text = '';" - "for (var i = 0; i < iframes.length; i++) {" - " text += iframes[i].contentDocument.body.innerText;" - " text += '\\n\\n';" - "};" - "text;"; + "var iframes = document.querySelectorAll('iframe');" + "var text = '';" + "for (var i = 0; i < iframes.length; i++) {" + " text += iframes[i].contentDocument.body.innerText;" + " text += '\\n\\n';" + "};" + "text;"; [self evaluateJavaScript:jsCode completionHandler:^(id _Nullable result, NSError *_Nullable error) { if (!error && [result isKindOfClass:[NSString class]]) { @@ -1266,18 +1266,18 @@ - (void)fetchWebViewAllIframeText:(void (^_Nullable)(NSString *text))completionH - (void)getTextWithHref:(NSString *)href completionHandler:(void (^_Nullable)(NSString *text))completionHandler { NSString *jsCode = [NSString stringWithFormat: - @"var iframes = document.querySelectorAll('iframe');" - @"var linkText = '';" - @"for (var i = 0; i < iframes.length; i++) {" - @" var iframe = iframes[i];" - @" var linkElement = iframe.contentWindow.document.querySelector('a[href=\"%@\"]');" - @" if (linkElement) {" - @" linkText = linkElement.innerText;" - @" break;" - @" }" - @"}" - @"linkText;", - href]; + @"var iframes = document.querySelectorAll('iframe');" + @"var linkText = '';" + @"for (var i = 0; i < iframes.length; i++) {" + @" var iframe = iframes[i];" + @" var linkElement = iframe.contentWindow.document.querySelector('a[href=\"%@\"]');" + @" if (linkElement) {" + @" linkText = linkElement.innerText;" + @" break;" + @" }" + @"}" + @"linkText;", + href]; [self evaluateJavaScript:jsCode completionHandler:^(id result, NSError *error) { if (!error) {