-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
85 lines (69 loc) · 2.86 KB
/
api.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
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let current_url = tabs[0].url;
// use `url` here inside the callback because it's asynchronous!
// var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
// var theUrl = "http://127.0.0.1:5000";
// xmlhttp.open("POST", theUrl);
// xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
// let data = xmlhttp.send(JSON.stringify({ "url": current_url}));
// const test = document.getElementById('test');
// test.innerHTML = data;
// import fetch from "node-fetch";
const test = document.getElementById('test');
test.innerHTML = "Fetching data...";
let URL = "http://127.0.0.1:5000";
const data = {
"url": current_url
};
// Send a post request
fetch(URL, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(
function(u) { return u.json(); }
)
.then(
function(json) {
if (json["flag"] == 1) {
test.innerHTML = "Invalid website or No reviews available";
}
else {
test.innerHTML = "Applying ML model...";
URL = "http://127.0.0.1:7000";
fetch(URL, {
method: "POST",
body: JSON.stringify({"name": json["test"]}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(
function(u) { return u.json(); }
)
.then(
function(json) {
test.innerHTML = "Authenticity score is " + json["val"];
let circularProgress = document.querySelector(".circular-progress"),
progressValue = document.querySelector(".progress-value");
var authenticity_score=Math.round(json["val"]);
let progressStartValue = 0,
progressEndValue = authenticity_score,
speed = 10;
let progress = setInterval(() => {
progressValue.textContent = `${progressStartValue}%`
circularProgress.style.background = `conic-gradient(#febd69 ${progressStartValue * 3.6}deg, #ededed 0deg)`
if(progressStartValue == progressEndValue){
clearInterval(progress);
}
progressStartValue++;
}, speed);
}
)
}
}
)
});