-
Notifications
You must be signed in to change notification settings - Fork 0
/
deen_Collins.js
88 lines (80 loc) · 2.41 KB
/
deen_Collins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* global api */
class enfr_Collins {
constructor(options) {
this.options = options;
this.maxexample = 2;
this.word = '';
}
async displayName() {
let locale = await api.locale();
if (locale.indexOf('CN') != -1) return '柯林斯英法词典';
if (locale.indexOf('TW') != -1) return '柯林斯英法词典';
return 'Collins DE->EN Dictionary';
}
setOptions(options) {
this.options = options;
this.maxexample = options.maxexample;
}
async findTerm(word) {
this.word = word;
return await this.findCollins(word);
}
async findCollins(word) {
if (!word) return null;
let base = 'https://www.collinsdictionary.com/dictionary/german-english/';
let url = base + encodeURIComponent(word);
let doc = '';
try {
let data = await api.fetch(url);
let parser = new DOMParser();
doc = parser.parseFromString(data, 'text/html');
} catch (err) {
return null;
}
let content = doc.querySelector('.content') || '';
if (!content) return null;
let css = this.renderCSS();
return css + content.innerHTML;
}
renderCSS() {
let css = `
<style>
.copyright{
display:none;
}
.orth {
font-size: 100%;
font-weight: bold;
}
.quote {
font-style: normal;
color: #1683be;
}
.colloc {
font-style: italic;
font-weight: normal;
}
.sense {
/*border: 1px solid;*/
/*border-color: #e5e6e9 #dfe0e4 #d0d1d5;*/
border-radius: 3px;
padding: 5px;
margin: 5px 0;
background-color: #f6f6f6;
}
.sense .re {
font-size: 100%;
margin-left: 0;
}
a {
color: #000;
text-decoration: none;
}
* {
word-wrap: break-word;
box-sizing: border-box;
}
</style>`;
return css;
}
}