mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Improve remove-cookie scriptlet
Related discussion:
afc6ff52ff (commitcomment-160172503)
This commit is contained in:
parent
33b92f91cb
commit
0a8ea58bb7
1 changed files with 19 additions and 8 deletions
|
|
@ -137,8 +137,9 @@ export function setCookieFn(
|
|||
if ( options.domain ) {
|
||||
let domain = options.domain;
|
||||
if ( /^\/.+\//.test(domain) ) {
|
||||
const baseURL = new URL(document.baseURI);
|
||||
const reDomain = new RegExp(domain.slice(1, -1));
|
||||
const match = reDomain.exec(document.location.hostname);
|
||||
const match = reDomain.exec(baseURL.hostname);
|
||||
domain = match ? match[0] : undefined;
|
||||
}
|
||||
if ( domain ) {
|
||||
|
|
@ -369,6 +370,13 @@ export function removeCookie(
|
|||
fn();
|
||||
}, ms);
|
||||
};
|
||||
const baseURL = new URL(document.baseURI);
|
||||
let targetDomain = extraArgs.domain;
|
||||
if ( targetDomain && /^\/.+\//.test(targetDomain) ) {
|
||||
const reDomain = new RegExp(targetDomain.slice(1, -1));
|
||||
const match = reDomain.exec(baseURL.hostname);
|
||||
targetDomain = match ? match[0] : undefined;
|
||||
}
|
||||
const remove = ( ) => {
|
||||
safe.String_split.call(document.cookie, ';').forEach(cookieStr => {
|
||||
const pos = cookieStr.indexOf('=');
|
||||
|
|
@ -376,16 +384,19 @@ export function removeCookie(
|
|||
const cookieName = cookieStr.slice(0, pos).trim();
|
||||
if ( reName.test(cookieName) === false ) { return; }
|
||||
const part1 = cookieName + '=';
|
||||
const part2a = '; domain=' + document.location.hostname;
|
||||
const part2b = '; domain=.' + document.location.hostname;
|
||||
const part2a = `; domain=${baseURL.hostname}`;
|
||||
const part2b = `; domain=.${baseURL.hostname}`;
|
||||
let part2c, part2d;
|
||||
const domain = document.domain;
|
||||
if ( domain ) {
|
||||
if ( domain !== document.location.hostname ) {
|
||||
part2c = '; domain=.' + domain;
|
||||
if ( targetDomain ) {
|
||||
part2c = `; domain=${targetDomain}`;
|
||||
part2d = `; domain=.${targetDomain}`;
|
||||
} else if ( document.domain ) {
|
||||
const domain = document.domain;
|
||||
if ( domain !== baseURL.hostname ) {
|
||||
part2c = `; domain=.${domain}`;
|
||||
}
|
||||
if ( domain.startsWith('www.') ) {
|
||||
part2d = '; domain=' + domain.replace('www', '');
|
||||
part2d = `; domain=${domain.replace('www', '')}`;
|
||||
}
|
||||
}
|
||||
const part3 = '; path=/';
|
||||
|
|
|
|||
Loading…
Reference in a new issue