Skip to content

Commit

Permalink
fix: rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Oct 23, 2024
1 parent 48b27df commit 11cdce4
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions Easydict/objc/ViewController/View/WordResultView/EZWordResultView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -890,18 +890,18 @@ - (void)setupBottomToolBarButtons:(EZQueryResult *)result lastView:(NSView *)las
}
}

- (NSView *)buildSynonymsAndAntonymsView:(NSString *)title
parts:(NSArray<EZTranslatePart *> *)parts
textColor:(NSColor *)typeTextColor
typeTextFont:(NSFont *)typeTextFont
height:(CGFloat *)height
lastView:(NSView *)lastView {
- (NSView *)createSectionViewForSynonymsOrAntonyms:(NSString *)sectionTitle
parts:(NSArray<EZTranslatePart *> *)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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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]]) {
Expand All @@ -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) {
Expand Down

0 comments on commit 11cdce4

Please sign in to comment.