-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
97 lines (56 loc) · 2.13 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
85
86
87
88
89
90
91
92
93
94
95
96
97
// console.log("Hi background");
let arrayofCookies;
let url;
chrome.runtime.onMessage.addListener(gotMessage);
function gotMessage(message, sender, sendResponse) {
// if the message is the start from content.js => This mean the content.js said to the background Start Your Work :)
if (message.start === "true") {
url = message.url;
chrome.action.setBadgeBackgroundColor({ color: [255, 0, 0, 255] });
chrome.action.setBadgeText({text: "0" });
//get all cookies with function getAll
chrome.cookies.getAll({"url": url}, function(allcookies) {
console.log('thank you from background all the cookies was send here is'+ allcookies)
arrayofCookies = allcookies;
//Send All The Cookies to content.js
let msg = {
Cookies_all: allcookies
};
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, msg);
});
})
}
// notifecation of how many reflected Cookie found
if (message.note) {
let numbers = message.note
let num = numbers.toString();
chrome.action.setBadgeBackgroundColor({ color: [255, 0, 0, 255] });
chrome.action.setBadgeText({text: num });
}
// Recieve Cookie name from popup , Which will change it
if (message.updateCookie) {
console.log('Thank you we recieved your Cookie name to change it and is ' + message.nameed)
chrome.cookies.set({
"url": url,
"name": message.nameed,
// "domain": message.domained,
// "expirationDate": expdate,
"httpOnly": message.httpOnlycookie,
"path": message.pathed,
"sameSite": message.sameSited,
"secure": message.securecookie,
// "storeId": message.storeIded,
"value": message.payload
}, function (cookie) {
console.log('Ok we update the value of cookie'+message.nameed+'from'+message.valueCookie+'to Value' + message.payload);
// when update the cookie value send to the content.js to reload the page
let msg = {
reload: "true"
};
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, msg);
});
});
}
}