-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (22 loc) · 1 KB
/
script.js
File metadata and controls
27 lines (22 loc) · 1 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
document.getElementById("linkBtn").addEventListener("click", function() {
const linkInput = document.getElementById("linkInput").value;
const textOutput = document.getElementById("textContainer");
const data = null;
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener('readystatechange', function () {
if (this.readyState === this.DONE) {
if (this.status >= 200 && this.status < 300) {
textOutput.textContent = this.responseText;
} else {
textOutput.textContent = `Request failed with status: ${this.status} ${this.statusText}`;
}
}
});
const encodedLink = encodeURIComponent(linkInput);
const apiUrl = `https://extract-news.p.rapidapi.com/v0/article?url=${encodedLink}`;
xhr.open('GET', apiUrl);
xhr.setRequestHeader('x-rapidapi-key', 'YOUR_API_KEY_HERE');
xhr.setRequestHeader('x-rapidapi-host', 'extract-news.p.rapidapi.com');
xhr.send(data);
});