-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
36 lines (32 loc) · 929 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
29
30
31
32
33
34
35
36
function clearAllCookies(domain) {
chrome.cookies.getAll({domain}, function (cookies) {
for (var i in cookies) {
removeCookie(cookies[i]);
}
});
}
function removeCookie(cookie) {
var url =
'http' + (cookie.secure ? 's' : '') + '://' + cookie.domain + cookie.path;
chrome.cookies.remove({url: url, name: cookie.name});
}
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.url) {
const Url = changeInfo.url;
const mediumRegex = /^http[s]?:\/\/.*[.]?medium.com\/.*/;
var currentURL = new URL(tab.url);
var domain = currentURL.hostname;
if (mediumRegex.test(Url)) {
clearAllCookies(domain);
}
}
});
window.onload = function () {
var clear_Cookies = document.getElementById('clear_cookies');
clearAllCookies();
if (clear_Cookies) {
clear_Cookies.addEventListener('click', function () {
clearAllCookies();
});
}
};