From cd1587448051b2b0a06f784420af21b7cb182238 Mon Sep 17 00:00:00 2001 From: fthvgb1 Date: Sun, 26 Jan 2020 11:13:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=AD=E6=97=A5=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E6=9F=A5=E8=AF=A2=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++---- translate/translate-dictionary.js | 28 ++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5779b08..b12a8ae 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## 日语划词词典 ver0.3 +## 日语划词词典 @@ -21,14 +21,13 @@ fork https://github.com/barrer/tampermonkey-script 修改的,并参考了http: ### 功能 * 只调用沪江小D查询日语,可以点击语音按钮发音 +* 默认是日中查询,没有结果时自动使用中日查询,日中查询有结果有添加主动中日查询的按钮 * 有多个发音时,可以点击切换 * 支持浏览器:Google Chrome、Firefox、Safari、Firefox for Android(无拖动) * 支持图标拖动 * 支持面板自动调整位置 - - -下个版本实现 日->中|中->日的切换 +下个版本使例句可以折叠 ### 其它 diff --git a/translate/translate-dictionary.js b/translate/translate-dictionary.js index 8a74fb9..eb0f79d 100644 --- a/translate/translate-dictionary.js +++ b/translate/translate-dictionary.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 日语划词词典 // @namespace http://tampermonkey.net/ -// @version 0.3.3 +// @version 0.4 // @description 调用沪江小D进行日语划词查询 // @author https://github.com/fthvgb1 // @match http://*/* @@ -986,7 +986,7 @@ //查日语没有结果时,查中日词典 - function cj(rst, time, tex, audio) { + function cj(time, tex, audio) { ajax('https://dict.hjenglish.com/jp/cj/' + encodeURIComponent(tex), function (rst) { putEngineResult(ids.HJENGLISH, function (rst, time, text, audio) { var dom = document.createElement('div'); @@ -1064,7 +1064,7 @@ /**沪江小D排版*/ - function parseHjenglish(rst, time, tex, that) { + function parseHjenglish(rst, time, tex) { var audio = new AudioPlayer(); var dom = document.createElement('div'); dom.setAttribute('class', ids.HJENGLISH); @@ -1072,7 +1072,7 @@ //content = doc.documentElement; content = doc.getElementsByClassName('word-details')[0]; if (!content) { - return cj(rst, time, tex, audio, that); + return cj(time, tex, audio); } dom.appendChild(content); //添加音频按钮 @@ -1148,6 +1148,26 @@ }, true) } } + if (/[\u4e00-\u9fa5]/.test(tex) || /[^\x00-\xff]/.test(tex)) { + var img = icon.querySelector('img'); + var im = document.createElement('span'); + im.style = ` + font-size: 14px; + line-height: 20px; + color: #999; + cursor: pointer; + margin-left: 10rem; +`; + im.classList.add('langs-cj'); + im.textContent = '中日'; + im.onclick = function () { + im.parentNode.removeChild(im) + contentList.querySelector('tr-engine').setAttribute('data-id', ids.HJENGLISH); + return cj(time, tex, audio); + }; + img.parentNode.insertBefore(im, img.nextSibling) + } + //var uls = dom.querySelectorAll('.detail-groups'); //debugger return dom;