From 2ccc3135c1777d109013722c9e9fd0454acc2a3e Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 5 May 2024 06:51:52 -0400 Subject: [PATCH] Improve `trusted-set-local-storage-item` scriptlet Related discussion: https://github.com/uBlockOrigin/uAssets/commit/df1041c616e3bd92263928d5d64f288197fcdf98#commitcomment-141265533 --- assets/resources/scriptlets.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 08553ef467ca2..ae1ab436261da 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -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();