buildDialogueDismisserJs function
Builds the JavaScript dialogue dismisser injected into the main frame of
every page (at document start) for the enabled presets.
The script scans for candidate overlay elements on DOM ready, on timed
retries (500ms / 1500ms / 3000ms — consent banners are often injected
late) and via a light MutationObserver for dialog-role insertions. A
candidate is dismissed ONLY when its text content matches the keyword
patterns of an enabled preset (mirror of the Dart-side
DialogueDismissRules); non-matching sticky/fixed elements (price
banners, nav bars, chat widgets) are never touched. Each dismissal is
reported through the __zikzakDialogueDismissed__ JavaScript handler;
events fired before the Dart side has registered its handler are buffered
in-page and flushed when the dismisser calls
window.__zikzakDialogueDismisser__.ready().
Implementation
String buildDialogueDismisserJs(Set<DialogueDismissPreset> presets) {
final expanded = DialogueDismissRules.expandPresets(presets);
final patternMap = <String, List<String>>{
for (final preset in DialogueDismissRules.concretePresets)
if (expanded.contains(preset))
preset.name: DialogueDismissRules.keywordPatterns[preset]!,
};
return dialogueDismisserJsTemplate.replaceFirst(
'__PRESET_PATTERNS__',
jsonEncode(patternMap),
);
}