Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义脚本导入无效 #340

Open
leuas opened this issue Aug 4, 2024 · 2 comments
Open

自定义脚本导入无效 #340

leuas opened this issue Aug 4, 2024 · 2 comments

Comments

@leuas
Copy link

leuas commented Aug 4, 2024

我用gist进行导入,但导入后,插件中并没有显示我导入的脚本,以下是导入用的链接:https://gist.githubusercontent.com/leuas/068299e32f5ead59a913ae53a6d34315/raw/7b88556dec384e58dd12d3d31086594b1679dd9a/fizh_GlosbeDictionary.js(我不清楚是不是链接的问题,之前导入的时候,也是用gist导入,成功了)

@ninja33
Copy link
Owner

ninja33 commented Aug 4, 2024

首先sample usage下面这段要删掉

// Example usage:
const dictionary = new finnZhDictionary({ maxExample: 2 });
dictionary.findTerm("mies").then(translations => {
    translations.forEach(translation => {
        console.log(`Word: ${translation.word}`);
        console.log(`POS: ${translation.pos}`);
        console.log(`Translation: ${translation.translationText}`);
        console.log(`IPA: ${translation.ipa}`);
        console.log(`Audio URL: ${translation.audioUrl}`);
        console.log();  // 分隔翻译
    });
}).catch(error => {
    console.error(error);
});

其次constructor 里那个options不可用,因为loadscript的时候并没有传进去,这是为什么后来又搞了个setOptions来额外传options
所以下面这句应该注释掉

this.maxexample = options.maxexample || 2;

改完后,词典列表里就可以看到了。比如你试试我这个
https://gist.githubusercontent.com/ninja33/18c271c7192444a784e06717a86ce59f/raw/428807d6808898be705c90ec948816e1c16801a5/fizh_GlosbeDictionary.js

但是这个脚本依然不可以用, 因为他会报错说 axios 这个object找不到,所以不知道你自定义脚本里axios 那里来的,又没有定义。你自己再调试一下吧。

@leuas
Copy link
Author

leuas commented Aug 4, 2024

谢谢!加载进去了,确实无法正确运行,问题应该处在最后的AI改写上,很抱歉还得麻烦您再帮我确定一下怎么调试?(看看方向有没有错?)
问题:我确保了抓取脚本(两个版本)都可以正常运行,所以应该是进一步的AI改写出了问题(不能直接转换?)。而这个抓取代码如果我没有想错,我的抓取版本脚本已经完成了您开发指南上第一,第二点,之后我应该开始完善第三点(元素选择器之类的),最后再把转成开发指南里模板的格式?

背景:
由于我基本上不会代码,只看得懂一点python,所以我的代码是用AI写了了python的抓取脚本,再让它转成JavaScript的,最后在让AI把JavaScript版的抓取代码补完您开发指南上的要求,也让他模仿一个英汉词典的插件中内置脚本(也就是您看到的版本)。
python版的抓取代码:https://gist.githubusercontent.com/leuas/3b8d0466d03de428d4293e1210bfc7a9/raw/f61caf902dbc3790ac539609a6bddef9a81ecded/python%25E6%258A%2593%25E5%258F%2596.py

JavaScript版本的抓取代码:https://gist.githubusercontent.com/leuas/618763bb8e205c595dc96f4ec72c8d9e/raw/5f234d9367647dd9e9e54a892a7fd03075851ffa/JavaScript%25E6%258A%2593%25E5%258F%2596.js

抓取的网站:
https://www.sanakirja.fi/

值得注意的是,这个抓取的网站的token(即在脚本里面的Authorization部分),似乎每隔几小时就得重新再改(需要登录后去原网站f12页面的network里找token,再复制上去),不然运行不了。(目前网站api似乎暂时还拿不到)

所以以下输出供您参考:(可能有用?两个版本的输出几乎一样,所以只粘贴了python的)
抓取的词汇:kiitos
输出:
Word: kiitos
Part of Speech: noun
Sentence ID: motkiina-k-fizh-3841-s-1
Created: 2021-10-25T12:09:54.321893
Example: Kiitos!
Example Created: 2021-10-25T12:09:54.322192
Translation: 谢谢
IPA: xièxie!
Audio URL:

Example: Kiitoksia!
Example Created: 2021-10-25T12:09:54.322811
Translation: 太谢谢了
IPA: tài xièxie le!
Audio URL:

Example: Suurkiitos!
Example Created: 2021-10-25T12:09:54.323456
Translation: 大大感谢
IPA: dàdà gǎnxiè!
Audio URL:

Word: kiitos
Part of Speech: noun
Sentence ID: motkiina-k-fizh-3841-s-2
Created: 2021-10-25T12:09:54.324619
Example: Kiitoksen kipeä
Example Created: 2021-10-25T12:09:54.324915
Translation: 急切要(别人)赞扬
IPA: jíqiè yào (biérén) zànyáng
Audio URL:

Example: Tavoitella kiitosta
Example Created: 2021-10-25T12:09:54.325612
Translation: 追求赞扬
IPA: zhuīqiú zànyáng
Audio URL:

Example: Hän ansaitsee työstä täyden,kaiken kiitoksen
Example Created: 2021-10-25T12:09:54.326261
Translation: 由于他的工作应当给予他一切赞扬
IPA: Yóuyú tā de gōngzuò yīngdāng jǐyǔ tā yíqiè zànyáng
Audio URL:

Word: kiitos
Part of Speech: noun
Sentence ID: motkiina-k-fizh-3841-s-3
Created: 2021-10-25T12:09:54.328304
Example: Pääsi pulasta kiitos ystävien
Example Created: 2021-10-25T12:09:54.32866
Translation: 多亏了朋友才摆脱困境
IPA: duōkuīle péngyou cái bǎituō kùnjìng
Audio URL:

Example: Kiitos nopean toiminnan vahingoilta vältyttiin
Example Created: 2021-10-25T12:09:54.329483
Translation: 由于行动迅速才避免了损失
IPA: yóuyú xíngdòng xùnsù cái bìmiǎn le sǔnshī
Audio URL:

Example: Potilas on nyt huonompi kiitos huolimattoman hoidon
Example Created: 2021-10-25T12:09:54.333144
Translation: 由于治疗马虎病人病情加重
IPA: yóuyú zhìliáo mǎhu bìngrén bìngqíng jiāzhòng
Audio URL:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants