Last active
April 15, 2023 03:18
-
-
Save ninja33/021c27dabfdd57c3dae39aa67b138b56 to your computer and use it in GitHub Desktop.
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 encn_TestDict { | |
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 'EN->CN Test Dictionary'; | |
} | |
setOptions(options) { | |
this.options = options; | |
this.maxexample = options.maxexample; | |
} | |
async findTerm(word) { | |
this.word = word; | |
if (!word) return null; | |
let base = 'http://some.online.dict.net/search/word='; | |
let url = base + encodeURIComponent(word); | |
try { | |
let notes = []; | |
// get online dictionary feedback here | |
// let terms = JSON.parse(await api.fetch(url)); | |
// but, as example, let's build the note by hand. | |
let content1=`<p>Chosen word:<span class='ERROR'>${word}</span> displayed in ERROR style</p>` | |
let content2=`<p>所选单词:<span class='INFO'>${word}</span>以INFO样式显示</p>` | |
let css = this.renderCSS(); | |
notes.push({ | |
css, | |
expression:word, | |
reading:`/${word}/`, | |
extrainfo:"extra informations", | |
definitions: [content1, content2], | |
audios:[] | |
}); | |
return notes; | |
} catch (err) { | |
return null; | |
} | |
} | |
renderCSS() { | |
// put your customized css style here | |
let css = ` | |
<style> | |
span.ERROR {background-color: #ff3366; color:white; margin: 0 2px; padding: 0 2px 2px;} | |
span.INFO {background-color: #44aaee; color:white; margin: 0 2px; padding: 0 2px 2px;} | |
</style>`; | |
return css; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment