PageSourceSearch

https://www.faria.org/wp-content/plugins/faria-elevenlabs-agent-context/assets/js/agent-context.js?ver=1.2.0

js faria.org collected 2026-09-24 09:34:28 UTC 2,035 bytes, 81 lines download raw bytes

1/**
2 * Sync ElevenLabs #faria-agent page_* dynamic-variables after soft navigations.
3 * Does not create the element or load the widget — GTM owns injection.
4 */
5(function () {
6	'use strict';
7
8	var AGENT_ID = 'faria-agent';
9	var ATTR = 'dynamic-variables';
10	var TOPIC_SEL = 'meta[name="faria:topic"]';
11
12	function readTopic() {
13		try {
14			var meta = document.querySelector(TOPIC_SEL);
15			var content = meta && meta.getAttribute('content');
16			if (typeof content === 'string' && content.trim()) {
17				return content.trim();
18			}
19		} catch (e) {
20			/* ignore */
21		}
22		return 'unknown';
23	}
24
25	function parseVars(raw) {
26		if (raw == null || String(raw).trim() === '') {
27			return {};
28		}
29		try {
30			var parsed = JSON.parse(String(raw));
31			if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
32				return parsed;
33			}
34		} catch (e) {
35			/* malformed */
36		}
37		return {};
38	}
39
40	function sync() {
41		var el = document.getElementById(AGENT_ID);
42		if (!el) {
43			return;
44		}
45		try {
46			var vars = parseVars(el.getAttribute(ATTR));
47			vars.page_url = location.href;
48			vars.page_title = document.title || '';
49			vars.page_context = readTopic();
50			el.setAttribute(ATTR, JSON.stringify(vars));
51		} catch (e) {
52			/* never throw into page lifecycle */
53		}
54	}
55
56	function onReady(fn) {
57		if (document.readyState === 'loading') {
58			document.addEventListener('DOMContentLoaded', fn, { once: true });
59		} else {
60			fn();
61		}
62	}
63
64	onReady(function () {
65		// Full page loads: GTM may inject later; one delayed pass after typical GTM delay.
66		sync();
67		window.setTimeout(sync, 3000);
68		window.setTimeout(sync, 8000);
69
70		window.addEventListener('pageshow', sync);
71		window.addEventListener('popstate', sync);
72
73		// Soft navigations used by some WP stacks / page builders.
74		document.addEventListener('turbo:load', sync);
75		document.addEventListener('pjax:end', sync);
76		document.addEventListener('breakdance_frontend_loaded', sync);
77	});
78
79	// Expose for manual QA in the console.
80	window.fariaSyncElevenLabsAgentContext = sync;
81})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.