-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
43 lines (37 loc) · 1.41 KB
/
popup.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
32
33
34
35
36
37
38
39
40
41
42
43
// HTMLのtextarea要素を取得
const textarea = document.getElementById("textarea");
// form要素を取得
const form = document.querySelector("form");
// form要素のsubmitイベントを検知して、イベントハンドラを実行する
form.addEventListener("submit", async event => {
// submitイベントのデフォルトの動作を止める
event.preventDefault();
// textarea要素のvalueプロパティにアクセスすることで、文字列を取得
const text = textarea.value;
let preprocessed_tokens = [];
const tokenizer = await new Promise((resolve, reject) => {
kuromoji.builder({ dicPath: "./dict" }).build(function (err, tokenizer) {
if (err) {
reject(err);
return;
}
resolve(tokenizer);
});
});
const tokens = tokenizer.tokenize(text);
console.log(tokens)
tokens.forEach((token) => {
if (token.pos === "名詞") {
preprocessed_tokens.push(token.surface_form); //名詞のみをarray: prepprocessed_tokensに格納
}
});
tokens.forEach((token) => {
if (token.pos === "動詞" && token.conjugated_form != "未然形") {
let verb = token.basic_form + "方法"
preprocessed_tokens.push(verb); //名詞のみをarray: prepprocessed_tokensに格納
}
});
let search_term = preprocessed_tokens.join(' ');
console.log(search_term);
window.open("https://www.google.com/search?q=" + search_term, "_blank");
});