-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmlGrab.js
83 lines (73 loc) · 2.92 KB
/
htmlGrab.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
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
var myValueObjects
function getTimeStamp() {
var today = new Date()
var date = today.getFullYear() + '-' + (today.getMonth(
) + 1) + '-' + today.getDate()
var time = today.getHours() + ":" + today.getMinutes(
) + ":" + today.getSeconds()
var dateTime = date + ' ' + time
return dateTime
}
function grabImage(device) {
try {
var xhr = new XMLHttpRequest()
let newSearchString = device.replace(" ", "+")
var bingImageSearch = "https://bing-image-search1.p.rapidapi.com/images/search?q="
+ newSearchString + "&count=" + maximumImageResults
var texto_html
var textFilter
xhr.withCredentials = true
xhr.open("GET", bingImageSearch, true)
xhr.setRequestHeader("x-rapidapi-host",
"bing-image-search1.p.rapidapi.com")
xhr.setRequestHeader(
"x-rapidapi-key",
"4e0a7247damsh80eefb6da7ce25ap1f6174jsn739f2d802cc5")
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
} else if (xhr.readyState === xhr.DONE) {
texto_html = xhr.responseText
textFilter = texto_html.replace(/[\\]/g, '')
runScript.debugNetGraber(textFilter)
jsonSpliter(textFilter, 0, 0)
loading_iamge_gif_visibility.text = "false"
}
}
xhr.send(data)
} catch (err) {
consoleLogLineNumbers++
consoleLog.text = consoleLog.text + '<p> ' + getTimeStamp(
) + ' - Error while search the image on internet</p>'
}
}
function jsonSpliter(myJson, request, picture) {
switch (request) {
case 0:
try {
var myObject = JSON.parse(myJson)
const myValueJson = JSON.stringify(myObject.value)
myValueObjects = JSON.parse(myValueJson)
grabResultImage.source = myValueObjects[0].contentUrl
consoleLogLineNumbers++
consoleLog.text = consoleLog.text + '<p> ' + getTimeStamp(
) + ' - Sucesso ao procurar imagem</p>'
} catch (e) {
searchBox.text = "Nada encontrado ... Tente novamente"
consoleLogLineNumbers++
consoleLog.text = consoleLog.text + '<p> ' + getTimeStamp(
) + ' - Nenhuma imagem encontrada</p>'
}
break
case 1:
try {
grabResultImage.source = myValueObjects[picture].contentUrl
consoleLogLineNumbers++
consoleLog.text = consoleLog.text + '<p> ' + getTimeStamp(
) + ' - Imagem carregada</p>'
} catch (err) {
consoleLogLineNumbers++
consoleLog.text = consoleLog.text + '<p> ' + getTimeStamp(
) + ' - Erro ao carregar a imagem</p>'
}
}
}