Skip to content

Commit

Permalink
Add $currentISODate$ to trusted-set-local-storage-item scriptlet
Browse files Browse the repository at this point in the history
Related feedback:
- uBlockOrigin/uAssets#19120 (comment)

Additionally, improve logging in `m3u-prune` scriptlet.
  • Loading branch information
gorhill committed Jul 22, 2023
1 parent da8fe2f commit 8ddad9e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions assets/resources/scriptlets.js
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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);
Expand All @@ -2447,26 +2450,33 @@ 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;
};
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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ddad9e

Please sign in to comment.