Improve generateContentFn helper scriptlet

New directive: `join:[separator][sub-directives]`

[separator] is an author-defined two-character string to be used to split
the following sub-directives string. The sub-directives are fed back into
the helper scriptlet to generate sub-content, which will be joined into
a single string. Example:

...##+js(trusted-prevent-fetch, propstomatch, join:--length:10-20--[some literal content]--length:80-100-- push['ads'])
This commit is contained in:
Raymond Hill 2026-01-30 11:05:57 -05:00
parent 359cb070eb
commit 7d95c58408
No known key found for this signature in database
GPG key ID: F5630CAE62A14316

View file

@ -220,6 +220,14 @@ export function generateContentFn(trusted, directive) {
warXHR.send(); warXHR.send();
}).catch(( ) => ''); }).catch(( ) => '');
} }
if ( directive.startsWith('join:') ) {
const parts = directive.slice(7)
.split(directive.slice(5, 7))
.map(a => generateContentFn(trusted, a));
return parts.some(a => a instanceof Promise)
? Promise.all(parts).then(parts => parts.join(''))
: parts.join('');
}
if ( trusted ) { if ( trusted ) {
return directive; return directive;
} }