Skip to content

Commit 7d95c58

Browse files
committed
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'])
1 parent 359cb07 commit 7d95c58

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/js/resources/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ export function generateContentFn(trusted, directive) {
220220
warXHR.send();
221221
}).catch(( ) => '');
222222
}
223+
if ( directive.startsWith('join:') ) {
224+
const parts = directive.slice(7)
225+
.split(directive.slice(5, 7))
226+
.map(a => generateContentFn(trusted, a));
227+
return parts.some(a => a instanceof Promise)
228+
? Promise.all(parts).then(parts => parts.join(''))
229+
: parts.join('');
230+
}
223231
if ( trusted ) {
224232
return directive;
225233
}

0 commit comments

Comments
 (0)