-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
35 lines (34 loc) · 1.31 KB
/
main.js
File metadata and controls
35 lines (34 loc) · 1.31 KB
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
const isJapanPoint = name => {
const regJapaneseplace = /[\p{sc=Hiragana}\p{sc=Han}]/u;
return regJapaneseplace.test(name);
}
const searchTransfer = () => {
const pointStr = document.querySelector("textarea").value;
const pointArray = pointStr.split("\n").map((point) => point.trim()).filter(point => point !== "");
if(pointArray.length < 2){
alert("不正な入力です。")
return;
}
//const text = pointArray.filter(point => point !== "") .join("\n| (徒歩)\n");
let text = "";
for(let i=0; i<pointArray.length; i+=1){
text += pointArray[i];
if(i === pointArray.length-1) break;
const transportation = isJapanPoint(pointArray[i]) === isJapanPoint(pointArray[i+1]) ? "徒歩" : "水泳";
text += `\n|(${transportation})\n`;
}
const output = document.querySelector("output");
const button = document.querySelector("button");
output.innerText = "検索中";
button.disabled = true;
const necessaryTime = 2000 + Math.random() * 3000;
const timerID = setInterval(() => {
output.innerText += ".";
}, 700);
setTimeout(() => {
output.innerText = `${text}\n\n合計金額0円`;
button.disabled = false;
button.textContent = "再検索";
clearInterval(timerID);
}, necessaryTime);
}