Skip to content

Commit

Permalink
update words search
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanMo committed Dec 20, 2023
1 parent 95bbbd2 commit 62ed8ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LexiBridge",
"version": "1.2.0",
"version": "1.2.1",
"description": "LexiBridge 帮助您在浏览网页时学习新词汇,提升阅读流畅度。",
"manifest_version": 3,
"author": "chan.mo@outlook.com",
Expand Down
33 changes: 22 additions & 11 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,30 @@
var ranges = [];
nodes.map(node => {
let content = node.textContent.toLowerCase();
keys.map((text, index) => {
const matches = content.match(new RegExp(text, "i"));
if(matches) {
for(const match of matches) {
const range = document.createRange();
ranges.push({'word': text, 'range': range, 'value': words[index][1]});
const startOffset = content.indexOf(text);
range.setStart(node, startOffset);
range.setEnd(node, startOffset + text.length);
highlight.add(range);
}
let textList = content.split(' ');
textList.map((text, index) => {
if(keys.includes(text)) {
const range = document.createRange();
const startOffset = content.indexOf(text);
range.setStart(node, startOffset);
range.setEnd(node, startOffset + text.length);
ranges.push({'word': text, 'range': range, 'value': words[keys.indexOf(text)][1]});
highlight.add(range);
}
});
// keys.map((text, index) => {
// const matches = content.match(new RegExp(text, "i"));
// if(matches) {
// for(const match of matches) {
// const range = document.createRange();
// ranges.push({'word': text, 'range': range, 'value': words[index][1]});
// const startOffset = content.indexOf(text);
// range.setStart(node, startOffset);
// range.setEnd(node, startOffset + text.length);
// highlight.add(range);
// }
// }
// });
});

// apply highlight css
Expand Down

0 comments on commit 62ed8ee

Please sign in to comment.