From 8ddad9e39b353106a93fb4f3f1954f35dd5396ef Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 22 Jul 2023 07:57:47 -0400 Subject: [PATCH] Add `$currentISODate$` to `trusted-set-local-storage-item` scriptlet Related feedback: - https://github.com/uBlockOrigin/uAssets/issues/19120#issuecomment-1646524557 Additionally, improve logging in `m3u-prune` scriptlet. --- assets/resources/scriptlets.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 28310d590..a844fb2de 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -782,6 +782,8 @@ function setLocalStorageItemCore( value = Date.now(); } else if ( value === '$currentDate$' ) { value = `${Date()}`; + } else if ( value === '$currentISODate$' ) { + value = (new Date()).toISOString(); } } else { if ( trustedValues.includes(value.toLowerCase()) === false ) { @@ -2429,6 +2431,7 @@ function m3uPrune( const options = getExtraArgs(Array.from(arguments), 2); const logLevel = shouldLog(options); const safe = safeSelf(); + const uboLog = logLevel ? ((...args) => safe.uboLog(...args)) : (( ) => { }); const regexFromArg = arg => { if ( arg === '' ) { return /^/; } const match = /^\/(.+)\/([gms]*)$/.exec(arg); @@ -2447,17 +2450,22 @@ function m3uPrune( if ( lines[i].startsWith('#EXT-X-CUE:TYPE="SpliceOut"') === false ) { return false; } + uboLog('m3u-prune: discarding', `\n\t${lines[i]}`); lines[i] = undefined; i += 1; if ( lines[i].startsWith('#EXT-X-ASSET:CAID') ) { + uboLog(`\t${lines[i]}`); lines[i] = undefined; i += 1; } if ( lines[i].startsWith('#EXT-X-SCTE35:') ) { + uboLog(`\t${lines[i]}`); lines[i] = undefined; i += 1; } if ( lines[i].startsWith('#EXT-X-CUE-IN') ) { + uboLog(`\t${lines[i]}`); lines[i] = undefined; i += 1; } if ( lines[i].startsWith('#EXT-X-SCTE35:') ) { + uboLog(`\t${lines[i]}`); lines[i] = undefined; i += 1; } return true; @@ -2465,8 +2473,10 @@ function m3uPrune( const pruneInfBlock = (lines, i) => { if ( lines[i].startsWith('#EXTINF') === false ) { return false; } if ( reM3u.test(lines[i+1]) === false ) { return false; } + uboLog('m3u-prune: discarding', `\n\t${lines[i]}, \n\t${lines[i+1]}`); lines[i] = lines[i+1] = undefined; i += 2; if ( lines[i].startsWith('#EXT-X-DISCONTINUITY') ) { + uboLog(`\t${lines[i]}`); lines[i] = undefined; i += 1; } return true; @@ -2503,11 +2513,9 @@ function m3uPrune( } text = before.trim() + '\n' + after.trim(); reM3u.lastIndex = before.length + 1; - if ( logLevel ) { - safe.uboLog('m3u-prune: discarding\n', - discard.split(/\n+/).map(s => `\t${s}`).join('\n') - ); - } + uboLog('m3u-prune: discarding\n', + discard.split(/\n+/).map(s => `\t${s}`).join('\n') + ); if ( reM3u.global === false ) { break; } } return text;