-
Notifications
You must be signed in to change notification settings - Fork 3
/
background.js
84 lines (70 loc) · 1.92 KB
/
background.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
console.log("background script is running!!!")
chrome.action.onClicked.addListener(buttonClicked)
function buttonClicked(tab){
//console.log(tab.url)
}
var currentUrl,previousUrl;
setInterval(function(){
chrome.tabs.query({active:true, currentWindow:true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {url:tabs[0].url }, function(response) {
currentUrl = tabs[0].url
if(currentUrl!=previousUrl)
{
//console.log(response.msg);
previousUrl = currentUrl
}
});
});
},1000)
var flag =0;
var finalRes
chrome.runtime.onMessage.addListener(
async function(request, sender, sendResponse) {
// console.log(request.textMsg)
fetch('http://127.0.0.1:8000/predict', {
method: 'POST',
body:JSON.stringify(request.textMsg)
})
.then(response => response.json())
.then(data => {
// state is "fulfilled" or "rejected
finalRes = data
})
console.log("res: ",finalRes, request.textMsg)
sendResponse({farewell:finalRes})
}
);
var finalResult
function sendResource(url,data) {
return fetch(url, {
method: 'POST',
body:JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
console.log(data) // state is "fulfilled" or "rejected
return data
})
}
// var flag =0;
// chrome.runtime.onMessage.addListener(
// function(request, sender, sendResponse) {
// // console.log(request.textMsg)
// var res = sendResource('http://127.0.0.1:8000/predict',request.textMsg).then((data)=>{console.log(data)
// return data
// })
// console.log("res: ",res)
// sendResponse({farewell:res})
// }
// );
// var finalResult
// function sendResource(url,data) {
// return fetch(url, {
// method: 'POST',
// body:JSON.stringify(data)
// })
// .then(response => response.json())
// .then(data => {
// return data;
// }
// )}