Skip to content

Commit

Permalink
fix: 修复一些已知的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxunwei committed Aug 27, 2022
1 parent ca2b9d3 commit da1aa40
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 39 deletions.
2 changes: 1 addition & 1 deletion background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;(function() {
'use strict';

var host = 'http://localhost:8080';
var host = 'http://43.142.135.24:8080';
var baicizhanHelper = {};

/**
Expand Down
20 changes: 17 additions & 3 deletions content.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
@font-face {
font-family: "Glyphicons Halflings";
src: url("./libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.eot");
src: url("./libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.eot?#iefix") format("embedded-opentype"), url("./libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.woff2") format("woff2"), url("./libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.woff") format("woff"), url("./libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.ttf") format("truetype"), url("./libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular") format("svg");
src: url("chrome-extension://__MSG_@@extension_id__/libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.eot");
src: url("chrome-extension://__MSG_@@extension_id__/libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.eot?#iefix") format("embedded-opentype"),
url("chrome-extension://__MSG_@@extension_id__/libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.woff2") format("woff2"),
url("chrome-extension://__MSG_@@extension_id__/libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.woff") format("woff"),
url("chrome-extension://__MSG_@@extension_id__/libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.ttf") format("truetype"),
url("chrome-extension://__MSG_@@extension_id__/libs/bootstrap-3.4.1-dist/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular") format("svg");
}
.glyphicon {
position: relative;
Expand Down Expand Up @@ -35,7 +39,7 @@
font-size: 16px;
font-weight: bold;
line-height: 16px;
color: #000000;
color: silver;
text-shadow: 0 1px 0 #fff;
text-decoration: none;
}
Expand All @@ -47,6 +51,16 @@
position: relative;
}

.webui-popover-inner .word {
color: black;
font-size: medium;
display: block;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
}

.accent {
opacity: 0.6;
cursor: pointer;
Expand Down
45 changes: 25 additions & 20 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}

// 只翻译英文
if (!/^[a-zA-Z\\-\s]+$/.test(selectedContent)) {
if (!/^[a-zA-Z\\-\s']+$/.test(selectedContent)) {
return;
}

Expand All @@ -62,8 +62,10 @@
updateAuxiliaryElementPosition();

if (!iconTips) {
var imgFullPath = 'chrome-extension://' + chrome.runtime.id + '/images/baicizhan-helper.png';

$auxiliaryEl.iconTips({
imgSrc: './images/baicizhan-helper.png',
imgSrc: imgFullPath,
onClick: function($el) {
$auxiliaryEl.iconTips('hide');

Expand Down Expand Up @@ -94,20 +96,21 @@
var data = response.data.dict_wiki.dict;

// 显示辅助元素以保证弹窗定位准确
$auxiliaryEl.css('display', 'block')
.webuiPopover({
title: data.word_basic_info.word,
content: generateContentHtml(data),
trigger: 'click',
template: POPOVER_TEMPLATE,
onHide: function($el) {
clearPopover($el);
},
onShow: function($el) {
initialPopoverElementEvent($el, data);
}
});
$auxiliaryEl.css('display', 'block');
$auxiliaryEl.webuiPopover({
title: data.word_basic_info.word,
content: generateContentHtml(data),
trigger: 'click',
template: POPOVER_TEMPLATE,
onHide: function($el) {
clearPopover($el);
},
onShow: function($el) {
initialPopoverElementEvent($el, data);
}
});

// 触发 popover 显示
setTimeout(function() {
$auxiliaryEl.trigger('click');
}, 100);
Expand All @@ -122,8 +125,8 @@
var rect = range.getBoundingClientRect();

$auxiliaryEl.css('display', 'block')
.css('top', rect.top + document.body.scrollTop)
.css('left', rect.left + document.body.scrollLeft)
.css('top', rect.top + window.scrollY)
.css('left', rect.left + window.scrollX)
.css('height', rect.height)
.css('width', rect.width);
}
Expand All @@ -141,9 +144,9 @@
var accentHtml;

if (ukAccent == usaAccent) {
accentHtml = '<p>' + ukAccent + '<span class="glyphicon glyphicon-volume-up accent"></span></p>';
accentHtml = '<p class="word">' + ukAccent + '<span class="glyphicon glyphicon-volume-up accent"></span></p>';
} else {
accentHtml = '<p>' + ukAccent + '<span class="glyphicon glyphicon-volume-up accent"></span>' +
accentHtml = '<p class="word">' + ukAccent + '<span class="glyphicon glyphicon-volume-up accent"></span>' +
'&nbsp;' + usaAccent + '<span class="glyphicon glyphicon-volume-up accent"></span></p>';
}

Expand All @@ -161,7 +164,7 @@

var meansHtml = Object.entries(group)
.map(function(e) {
return '<p>' + e[0] + '&nbsp;' + e[1].join(';') + '</p>';
return '<p class="word">' + e[0] + '&nbsp;' + e[1].join(';') + '</p>';
})
.join('\n');

Expand Down Expand Up @@ -200,6 +203,8 @@
RESOURCE_HOST + data.word_basic_info.accent_usa_audio_uri :
RESOURCE_HOST + data.word_basic_info.accent_uk_audio_uri);

// TODO 修复部分网站由于 csp 而出现音频加载失败的问题
// 使用 ajax 或 fetch 加载音频文件
$icon.click(function() {
audio.play();
});
Expand Down
10 changes: 5 additions & 5 deletions icon-tips.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
};

IconTips.prototype.calcutePosition = function() {
var elRect = this.$el[0].getBoundingClientRect();
var elTop = elRect.top + document.body.scrollTop;
var elLeft = elRect.left + document.body.scrollLeft;
var elHeight = elRect.height;
var elWidth = elRect.width;
var position = this.$el.position();
var elTop = position.top;
var elLeft = position.left;
var elHeight = this.$el.height();
var elWidth = this.$el.width();
var pageHeight = document.body.clientHeight + document.body.scrollTop;
var margin = 3;
var iconHeight = 25;
Expand Down
1 change: 1 addition & 0 deletions libs/webui-popover/jquery.webui-popover.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
position: relative;
}
.webui-popover-title {
color: black;
padding: 8px 14px;
margin: 0;
font-size: 18px;
Expand Down
14 changes: 5 additions & 9 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,12 @@
],
"web_accessible_resources": [
{
"resources": [
"resources": [
"libs/**",
"*.js",
"options.html",
"libs/bootstrap-3.4.1-dist/css/bootstrap.css",
"libs/growl/jquery.growl.css",
"options.css",
"libs/jquery-3.6.0/jquery-3.6.0.js",
"libs/growl/jquery.growl.js",
"options.js",
"login.js",
"setting.js"
"*.css",
"images/baicizhan-helper.png"
],
"matches": ["<all_urls>"]
}
Expand Down
2 changes: 1 addition & 1 deletion options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

var baicizhanHelper = {
// 代理服务器主机地址
'PROXY_HOST': 'http://localhost:8080',
'PROXY_HOST': 'http://43.142.135.24:8080',
};

function initial() {
Expand Down

0 comments on commit da1aa40

Please sign in to comment.