forked from blikenoother/ClearCookieAndReload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
28 lines (23 loc) · 894 Bytes
/
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
// triggered when user clicks on installed extention icon
chrome.browserAction.onClicked.addListener(function(tab) {
// retrive domain from active tab
var url = tab.url;
var matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
var d = matches && matches[1].replace('www.','');
d = '.'+d;
// get all cookies for domain
chrome.cookies.getAll({domain: d}, function (cookies) {
// iterate on cookie to get cookie detail
for (var i=0; i<cookies.length; i++) {
var url = "http" + (cookies[i].secure ? "s" : "") + "://" + cookies[i].domain + cookies[i].path;
var cname = cookies[i].name;
// delete cookie
chrome.cookies.remove({
"url": url,
"name": cname
});
}
// reload currect active tab
chrome.tabs.reload();
});
});