Improve trusted-set-local-storage-item scriptlet

Related discussion:
df1041c616 (commitcomment-141265533)
This commit is contained in:
Raymond Hill 2024-05-05 06:51:52 -04:00
parent f0cfc77170
commit 2ccc3135c1
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -1052,12 +1052,14 @@ function setLocalStorageItemFn(
];
if ( trusted ) {
if ( value === '$now$' ) {
value = Date.now();
} else if ( value === '$currentDate$' ) {
value = `${Date()}`;
} else if ( value === '$currentISODate$' ) {
value = (new Date()).toISOString();
if ( value.includes('$now$') ) {
value.replaceAll('$now$', Date.now());
}
if ( value.includes('$currentDate$') ) {
value.replaceAll('$currentDate$', `${Date()}`);
}
if ( value.includes('$currentISODate$') ) {
value.replaceAll('$currentISODate$', (new Date()).toISOString());
}
} else {
const normalized = value.toLowerCase();