Work on supporting different text sources
This commit is contained in:
parent
4e46f4bded
commit
6099de71d8
@ -22,7 +22,7 @@ class Client {
|
|||||||
this.popup = new Popup();
|
this.popup = new Popup();
|
||||||
this.audio = {};
|
this.audio = {};
|
||||||
this.lastMousePos = null;
|
this.lastMousePos = null;
|
||||||
this.lastRange = null;
|
this.lastTextSource = null;
|
||||||
this.activateKey = 16;
|
this.activateKey = 16;
|
||||||
this.activateBtn = 2;
|
this.activateBtn = 2;
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
@ -87,31 +87,35 @@ class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textSourceFromPoint(point) {
|
||||||
|
return Range.fromPoint(point);
|
||||||
|
}
|
||||||
|
|
||||||
searchAt(point) {
|
searchAt(point) {
|
||||||
const range = Range.fromPoint(point);
|
const textSource = this.textSourceFromPoint(point);
|
||||||
if (range === null || !range.containsPoint(point)) {
|
if (textSource === null || !textSource.containsPoint(point)) {
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lastRange !== null && this.lastRange.compareOrigin(range) === 0) {
|
if (this.lastTextSource !== null && this.lastTextSource.compareOrigin(textSource) === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
range.setLength(this.options.scanLength);
|
textSource.setLength(this.options.scanLength);
|
||||||
bgFindTerm(range.text(), ({definitions, length}) => {
|
bgFindTerm(textSource.text(), ({definitions, length}) => {
|
||||||
if (length === 0) {
|
if (length === 0) {
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
} else {
|
} else {
|
||||||
const sequence = ++this.sequence;
|
const sequence = ++this.sequence;
|
||||||
range.setLength(length);
|
textSource.setLength(length);
|
||||||
|
|
||||||
bgRenderText(
|
bgRenderText(
|
||||||
{definitions, root: this.fgRoot, options: this.options, sequence},
|
{definitions, root: this.fgRoot, options: this.options, sequence},
|
||||||
'term-list.html',
|
'term-list.html',
|
||||||
(content) => {
|
(content) => {
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
this.showPopup(range, content);
|
this.showPopup(textSource, content);
|
||||||
|
|
||||||
bgCanAddDefinitions(definitions, ['vocab_kanji', 'vocab_kana'], (states) => {
|
bgCanAddDefinitions(definitions, ['vocab_kanji', 'vocab_kana'], (states) => {
|
||||||
if (states !== null) {
|
if (states !== null) {
|
||||||
@ -124,24 +128,24 @@ class Client {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showPopup(range, content) {
|
showPopup(textSource, content) {
|
||||||
this.popup.showNextTo(range.getRect(), content);
|
this.popup.showNextTo(textSource.getRect(), content);
|
||||||
|
|
||||||
if (this.options.selectMatchedText) {
|
if (this.options.selectMatchedText) {
|
||||||
range.select();
|
textSource.select();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastRange = range;
|
this.lastTextSource = textSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
hidePopup() {
|
hidePopup() {
|
||||||
this.popup.hide();
|
this.popup.hide();
|
||||||
|
|
||||||
if (this.options.selectMatchedText && this.lastRange !== null) {
|
if (this.options.selectMatchedText && this.lastTextSource !== null) {
|
||||||
this.lastRange.deselect();
|
this.lastTextSource.deselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastRange = null;
|
this.lastTextSource = null;
|
||||||
this.definitions = null;
|
this.definitions = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,13 @@
|
|||||||
"background": {"page": "bg/background.html"},
|
"background": {"page": "bg/background.html"},
|
||||||
"content_scripts": [{
|
"content_scripts": [{
|
||||||
"matches": ["*://*/*"],
|
"matches": ["*://*/*"],
|
||||||
"js": ["fg/js/range.js", "fg/js/popup.js", "fg/js/api.js", "fg/js/client.js"],
|
"js": [
|
||||||
|
"fg/js/source-range.js",
|
||||||
|
"fg/js/source-image.js",
|
||||||
|
"fg/js/popup.js",
|
||||||
|
"fg/js/api.js",
|
||||||
|
"fg/js/client.js"
|
||||||
|
],
|
||||||
"css": ["fg/css/client.css"]
|
"css": ["fg/css/client.css"]
|
||||||
}],
|
}],
|
||||||
"minimum_chrome_version": "45.0.0.0",
|
"minimum_chrome_version": "45.0.0.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user