2020-10-12 15:31:51 +00:00
|
|
|
var ext_api = (typeof browser === 'object') ? browser : chrome;
|
|
|
|
|
|
|
|
window.localStorage.clear();
|
|
|
|
sessionStorage.clear();
|
|
|
|
|
2022-01-13 16:22:38 +00:00
|
|
|
var cookie_domain = getCookieDomain(document.domain);
|
|
|
|
|
2020-10-12 15:31:51 +00:00
|
|
|
// send domain to background.js (to clear cookies)
|
|
|
|
ext_api.runtime.sendMessage({
|
2022-12-03 17:13:37 +00:00
|
|
|
request: 'clear_cookies_domain',
|
|
|
|
data: {
|
2021-12-30 19:36:01 +00:00
|
|
|
domain: cookie_domain
|
2022-12-03 17:13:37 +00:00
|
|
|
}
|
2020-10-12 15:31:51 +00:00
|
|
|
});
|
|
|
|
|
2022-01-13 16:22:38 +00:00
|
|
|
function getCookieDomain(hostname) {
|
|
|
|
let domain = hostname;
|
|
|
|
let n = 0;
|
|
|
|
let parts = hostname.split('.');
|
|
|
|
let str = '_gd' + (new Date()).getTime();
|
|
|
|
while (n < (parts.length - 1) && document.cookie.indexOf(str + '=' + str) == -1) {
|
|
|
|
domain = parts.slice(-1 - (++n)).join('.');
|
|
|
|
document.cookie = str + "=" + str + ";domain=" + domain + ";";
|
|
|
|
}
|
|
|
|
document.cookie = str + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";";
|
|
|
|
return domain;
|
|
|
|
}
|
|
|
|
|
2021-12-30 19:36:01 +00:00
|
|
|
var msg = "Cookies (and local storage) removed from " + cookie_domain;
|
2020-10-12 15:31:51 +00:00
|
|
|
showMessage(msg, 2000);
|
|
|
|
|
|
|
|
function showMessage(msg, duration) {
|
|
|
|
var el = document.createElement("div");
|
|
|
|
el.setAttribute("style", "position:fixed;top:40%;left:40%;z-index:99;padding:4px;font-family: Arial, sans-serif;font-size:18px;color:white;background-color:blue;");
|
|
|
|
el.innerText = msg;
|
|
|
|
setTimeout(function () {
|
|
|
|
el.parentNode.removeChild(el);
|
|
|
|
}, duration);
|
2021-02-26 16:43:36 +00:00
|
|
|
(document.body || document.head || document.documentElement).appendChild(el);
|
|
|
|
}
|