1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

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.
This commit is contained in:
Raymond Hill 2023-07-22 07:57:47 -04:00
parent da8fe2f950
commit 8ddad9e39b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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;