diff --git a/src/dictionaries/hjenglishCore.js b/src/dictionaries/hjenglishCore.js index e491bb6..4626461 100644 --- a/src/dictionaries/hjenglishCore.js +++ b/src/dictionaries/hjenglishCore.js @@ -46,8 +46,50 @@ export default async (fetchPromise) => { })), }) ), + groupsEn: Array.from(i.querySelectorAll(".enen-groups > dl")).map( + (i) => ({ + partOfSpeech: i.querySelector("dt").textContent.trim(), + definitions: Array.from(i.querySelectorAll("dd")).map((i) => ({ + summary: i.textContent?.trim(), + })), + }) + ), + analytics: Array.from( + i.querySelectorAll( + ".word-details-item.analyzes > .word-details-item-content > *" + ) + ).reduce( + ({ result, title }, current) => { + if (current.classList.contains("analyzes-title")) + return { result, title: current.textContent }; + if (current.classList.contains("analyzes-items")) { + const items = Array.from(current.querySelectorAll("li")).map( + (i) => ({ + primary: i.querySelector("a")?.textContent, + secondary: i.querySelector("p")?.textContent, + }) + ); + result.push({ title, items }); + return { result, title: "" }; + } + }, + { result: [] } + ).result, + phrases: Array.from(i.querySelectorAll(".phrase-items > li")).map( + (i) => ({ + from: i.querySelector("span:first-child")?.textContent?.trim(), + to: i.querySelector("span.phrase-def")?.textContent?.trim(), + }) + ), + inflections: Array.from( + i.querySelectorAll(".inflections-items > li") + ).map((i) => ({ + name: i.querySelector("span:first-child")?.textContent?.trim(), + value: i.querySelector("a:last-child")?.textContent?.trim(), + })), }) ); + console.log(panes); if (panes.length === 0) return null; return (
@@ -77,6 +119,73 @@ export default async (fetchPromise) => {
))} + {i.phrases.length > 0 && ( +
+
片語
+
    + {i.phrases.map((i, index) => ( +
  1. + {i.from} +
    + {i.to} +
  2. + ))} +
+
+ )} + {i.groupsEn.length > 0 && ( +
+
英英釋義
+ {i.groupsEn.map((i, index) => ( +
+
{i.partOfSpeech}
+
    + {i.definitions.map((i, index) => ( +
  1. {i.summary}
  2. + ))} +
+
+ ))} +
+ )} + {i.analytics.length > 0 && ( +
+
詞意分析
+ +
+ )} + {i.inflections.length > 0 && ( +
+
詞性變化
+ + + {i.inflections.map((i, index) => ( + + + + + ))} + +
{i.name}{i.value}
+
+ )} ))} diff --git a/src/dictionaries/hjenglishEn.js b/src/dictionaries/hjenglishEn.js new file mode 100644 index 0000000..6f5e4a5 --- /dev/null +++ b/src/dictionaries/hjenglishEn.js @@ -0,0 +1,11 @@ +import hjenglishCore from "./hjenglishCore"; + +const hjenglishEn = async (query) => + hjenglishCore( + fetch(`https://dict.hjenglish.com/w/${encodeURIComponent(query)}`) + ); + +hjenglishEn.displayName = "滬江小D英文"; +hjenglishEn.fullName = "滬江小D 英漢字典"; + +export default hjenglishEn; diff --git a/src/dictionaries/index.js b/src/dictionaries/index.js index 9069809..1b503a3 100644 --- a/src/dictionaries/index.js +++ b/src/dictionaries/index.js @@ -10,6 +10,7 @@ import thesaurus from "dictionaries/thesaurus"; import hjenglish from "dictionaries/hjenglish"; import hjenglishKo from "dictionaries/hjenglishKo"; import hjenglishFr from "dictionaries/hjenglishFr"; +import hjenglishEn from "dictionaries/hjenglishEn"; export default { yahoo, @@ -24,4 +25,5 @@ export default { hjenglish, hjenglishKo, hjenglishFr, + hjenglishEn, }; diff --git a/stories/components/Dictionary.stories.js b/stories/components/Dictionary.stories.js index 0d903df..f4cd94e 100644 --- a/stories/components/Dictionary.stories.js +++ b/stories/components/Dictionary.stories.js @@ -14,6 +14,7 @@ import thesaurus from "dictionaries/thesaurus"; import hjenglish from "dictionaries/hjenglish"; import hjenglishKo from "dictionaries/hjenglishKo"; import hjenglishFr from "dictionaries/hjenglishFr"; +import hjenglishEn from "dictionaries/hjenglishEn"; const DictContainer = ({ query, dict }) => { const [content, setContent] = useState(null); @@ -86,6 +87,9 @@ export const HjenglishKo = () => ( export const HjenglishFr = () => ( ); +export const HjenglishEn = () => ( + +); export default { title: "Dictionary",