-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
110 lines (65 loc) · 2.39 KB
/
script.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const app = document.getElementById('root');
const logo = document.createElement('img');
logo.src = 'logo.png';
const container = document.createElement('div');
container.setAttribute('class', 'container');
const card = document.createElement('div');
card.setAttribute('class', 'card');
const h2 = document.createElement('h2');
const p = document.createElement('p');
app.appendChild(logo);
app.appendChild(container);
document.getElementById("searchTerm")
.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
document.getElementById("searchButton").click();
}
});
function myfunction(){
var mydata = document.getElementById("searchTerm").value;
if($.inArray(mydata , girlgrouplist) != -1){
console.log("Found");
}else{
container.innerHTML = " ";
logo.src = "random_not_found.jpg";
return;
}
var param = "&titles=" + mydata;
var url = "https://en.wikipedia.org/w/api.php?action=query&origin=*&format=json&prop=extracts&exintro=1";
var image_url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=pageimages&piprop=original";
var request = new XMLHttpRequest();
var image_request = new XMLHttpRequest();
request.open('GET', url+param , true);
image_request.open('GET', image_url+param , true);
image_request.onload = function(){
var image_data = JSON.parse(image_request.responseText);
var image_object = image_data.query.pages;
for(var image_prop in image_object){
var image_newdata = image_object[image_prop];
break;
}
var image_source = image_newdata.original;
logo.src = image_newdata.original['source'];
}
image_request.send();
h2.textContent = mydata;
request.onload = function () {
var data = JSON.parse(request.responseText);
var object = data.query.pages;
for(var prop in object){
var newdata = object[prop];
break;
}
/* const card = document.createElement('div');
card.setAttribute('class', 'card');
const h2 = document.createElement('h2');
h2.textContent = mydata;
const p = document.createElement('p'); */
p.innerHTML = newdata.extract;
container.appendChild(card);
card.appendChild(h2);
card.appendChild(p);
}
request.send();
}