generated from pot-app/pot-app-collection-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
31 lines (28 loc) · 851 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
async function collection(source, _target, options = {}) {
const { config, utils } = options;
const { tauriFetch: fetch } = utils;
const { cookie } = config;
if (cookie === undefined || cookie.length === 0) {
throw "cookie not found";
}
let res = await fetch("https://dict.youdao.com/wordbook/webapi/v2/ajax/add", {
method: "POST",
headers: { "Cookie": cookie },
query: {
word: source,
lan: "en"
}
});
if (res.ok) {
const result = res.data;
if (result.code === 0) {
return true;
} else if (result.msg) {
throw result.msg;
} else {
throw JSON.stringify(result);
}
} else {
throw `Http Request Error\nHttp Status: ${res.status}\n${JSON.stringify(res.data)}`;
}
}