Created
September 15, 2018 07:07
-
-
Save Edenharder/18a663c29d51e2504d8e2c06ab7fe905 to your computer and use it in GitHub Desktop.
translation from German to English
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global api */ | |
class fren_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 'deen_Collins'; | |
} | |
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-top: 3px; | |
} | |
.sense .re { | |
font-size: 100%; | |
margin-left: 0; | |
} | |
.sense .sense { | |
border: initial; | |
border-color: initial; | |
border-radius: initial; | |
padding: initial; | |
margin-top: initial; | |
} | |
a { | |
color: #000; | |
text-decoration: none; | |
} | |
* { | |
word-wrap: break-word; | |
box-sizing: border-box; | |
} | |
</style>`; | |
return css; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment