Add support to remove values in `set-local-storage-item` scriptlet

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/discussions/2697#discussioncomment-6278359

When using the special value `$remove$`, the scriptlet will remove
the item from the local storage.
This commit is contained in:
Raymond Hill 2023-06-30 09:03:17 -04:00
parent d54fad26b7
commit b283d6aa33
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 10 additions and 6 deletions

View File

@ -2838,7 +2838,8 @@ function setLocalStorageItem(
'undefined', 'null',
'false', 'true',
'yes', 'no',
'{}', '[]', "''",
'{}', '[]', '""',
'$remove$',
];
let actualValue;
if ( validValues.includes(value) ) {
@ -2851,10 +2852,10 @@ function setLocalStorageItem(
}
try {
if ( actualValue !== undefined ) {
self.localStorage.setItem(key, `${actualValue}`);
} else {
if ( actualValue === '$remove$' ) {
self.localStorage.removeItem(key);
} else {
self.localStorage.setItem(key, `${actualValue}`);
}
} catch(ex) {
}
@ -3024,7 +3025,6 @@ function trustedSetLocalStorageItem(
value = ''
) {
if ( key === '' ) { return; }
if ( value === '' ) { return; }
let actualValue = value;
if ( value === '$now$' ) {
@ -3034,7 +3034,11 @@ function trustedSetLocalStorageItem(
}
try {
self.localStorage.setItem(key, `${actualValue}`);
if ( actualValue === '$remove$' ) {
self.localStorage.removeItem(key);
} else {
self.localStorage.setItem(key, `${actualValue}`);
}
} catch(ex) {
}
}