-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
99 lines (75 loc) · 3.49 KB
/
Copy pathscript.js
File metadata and controls
99 lines (75 loc) · 3.49 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var tagAction = () => {
var button = document.querySelector("#createHashTags .tags_button");
// console.log(button);
button.addEventListener('click', (event) => {
event.preventDefault();
var tagsArea = document.querySelector("#createHashTags #tags").value;
var tagsResultArea = document.querySelector("#createHashTags #tags-result");
// console.log(tagsArea, tagsResultArea);
var myArray1 = tagsArea.split(/\r?\n/).map((currentValue) => {
currentValue = currentValue.replace(/\s/g, '_').replace(/-/g, '_');
// for (var i = 0; i < str.length; i++) {
// alert(str.charAt(i));
// }
return currentValue.charAt(0) != "#" ? "#" + currentValue: currentValue;
}).filter((el) => {
return el != "#";//пустой элемент
// return true;
});
var myArray2 = tagsArea.split(/\r?\n/).map((currentValue) => {
currentValue = currentValue.replace(/\s/g, '').replace(/-/g, '');
// + '\n\n\n' + currentValue.replace(/\s/g, '');
return currentValue.charAt(0) != "#" ? "#" + currentValue: currentValue;
}).filter((el) => {
return el != "#";//пустой элемент
// return true;
});
var result = myArray1.join('\n') + '\n\n\n' + myArray2.join('\n');
tagsResultArea.value = result;
// console.log(result);
});
}
tagAction();
//-----------------------------------------------------------
// Need to run node server C:\Users\Admin\OneDrive\Рабочий стол\кам\сервисы\script>node index.js
//-------------------------------------------------------------
var googleKeysAction = () => {
var button = document.querySelector("#parseGoogleKeys .tags_button");
// console.log(button);
button.addEventListener('click', (event) => {
event.preventDefault();
console.log(button);
//Get words to array
var tagsArea = document.querySelector("#parseGoogleKeys #tags").value;
var tagsResultArea = document.querySelector("#parseGoogleKeys #tags-result");
tagsResultArea.value = "Загрузка...";
// console.log(tagsArea, tagsResultArea);
// const i = 1;
var wordsArray = tagsArea.split(/\r?\n/).map((word, index) => {
if(!word) return;
word = word.replace(/\s/g, '+');
fetch('http://localhost:2020/key/'+word,{headers: { 'Content-Type': 'text/plain; charset=utf-8' }})
.then(response => response.json()
// {
// console.log(response.json());
// // let res = response.json();
// // let keys = res.keys;
// // let text = keys.join('\n');
// // tagsResultArea.value = text;
// }
)
.then((res) => {
if(tagsResultArea.value == "Загрузка...") tagsResultArea.value = "";
let keys = res.result.keys;
let text = keys.map((item) => {
return item.k;
}).join('\n');
console.log(text);
tagsResultArea.value += text+'\n';
})
.catch(err => console.error(err));
// i++;
});
});
}
googleKeysAction();