-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
59 lines (44 loc) · 1.71 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
//fetch('http://localhost/new/try.php')
//.then(response => response.json())
//.then(response => console.log(response.status));
// chrome.runtime.onMessage.addListener((request,sender,callback)=>
// {
// console.log(request.msg);
// //let response= await fetch(`http://localhost/new/try.php/?url${message.url}`);
// // chrome.tabs.sendMessage(tabId,{status: response.status});
// });
// const checkValidity = async (url) => {
// console.log(url);
// const response = await fetch(`http://localhost/new/try.php/?url=${url}`);
//}
const validities={};
let checkValidity= async (URL,tab_id)=>{
console.log("message received by background.js");
let queryString="";
for (let url_id of URL){
queryString+=`&url[]=${url_id}`;}
let response= await fetch(`http://localhost/new/try.php/?${queryString}`);
console.log("sent to php file");
let data= await response.json();
console.log("message received from php");
//console.log(data);
// if (typeof validities[tab_id] === 'undefined') {
// validities[tab_id] = {};
// }
validities[tab_id] = data;
console.log(validities);
chrome.tabs.sendMessage(tab_id,validities[tab_id]);
return;
//return data;
}
const messageHandler = (request, sender, callback) => {
//console.log(sender);
checkValidity(request.url, sender.tab.id);
return true;
};
chrome.runtime.onMessage.addListener(messageHandler);
// fetch('http://localhost/new/try.php')
// .then(response => response.json())
// .then(response => console.log(response.status));
// var x="hey";
// chrome.runtime.sendMessage({heyy:x});