PageSourceSearch

https://hotel-riga.com/wp-content/plugins/hotelbox-connect/public/js/hb-chat-translate.js?ver=2.9.1

js hotel-riga.com collected 2026-10-08 10:32:51 UTC 2,410 bytes, 75 lines download raw bytes

1/**
2 * Translates the LeadConnector chat widget (open Shadow DOM Stencil component)
3 * using a dictionary supplied via wp_localize_script as window.hbChatTranslate.
4 * Only enqueued on the BG language version (see class-hb-chat-translate.php).
5 */
6( function () {
7	var data  = window.hbChatTranslate || {};
8	var pairs = Array.isArray( data.dict ) ? data.dict : [];
9	if ( ! pairs.length ) { return; }
10
11	// Normalize for matching: strip zero-width, nbsp->space, collapse whitespace, trim.
12	function norm( s ) {
13		return ( s || '' )
14			.replace( /[\u200B-\u200D\uFEFF]/g, '' )
15			.replace( /\u00A0/g, ' ' )
16			.replace( /\s+/g, ' ' )
17			.trim();
18	}
19
20	var DICT = {};
21	pairs.forEach( function ( p ) {
22		if ( p && p.source && p.target ) { DICT[ norm( p.source ) ] = p.target; }
23	} );
24	if ( ! Object.keys( DICT ).length ) { return; }
25
26	function apply( root ) {
27		if ( ! root ) { return; }
28		var walker = document.createTreeWalker( root, NodeFilter.SHOW_TEXT );
29		var n;
30		while ( ( n = walker.nextNode() ) ) {
31			var key = norm( n.nodeValue );
32			if ( DICT[ key ] && n.nodeValue !== DICT[ key ] ) {
33				n.nodeValue = DICT[ key ];
34			}
35		}
36		if ( root.querySelectorAll ) {
37			root.querySelectorAll( '*' ).forEach( function ( el ) {
38				if ( el.shadowRoot ) { apply( el.shadowRoot ); }
39			} );
40		}
41	}
42
43	var seen   = ( typeof WeakSet !== 'undefined' ) ? new WeakSet() : null;
44	var queued = false;
45	function run( host ) {
46		apply( host.shadowRoot || host );
47		function watch( root ) {
48			if ( ! root || ( seen && seen.has( root ) ) ) { return; }
49			if ( seen ) { seen.add( root ); }
50			new MutationObserver( function () {
51				if ( queued ) { return; }
52				queued = true;
53				requestAnimationFrame( function () { queued = false; run( host ); } );
54			} ).observe( root, { childList: true, subtree: true, characterData: true } );
55		}
56		watch( host.shadowRoot );
57		( host.shadowRoot || host ).querySelectorAll( '*' ).forEach( function ( el ) {
58			if ( el.shadowRoot ) { watch( el.shadowRoot ); }
59		} );
60	}
61
62	function start() {
63		var host = document.querySelector( 'chat-widget' );
64		if ( host && host.shadowRoot ) { run( host ); return true; }
65		return false;
66	}
67
68	// Widget mounts async — wait for it if not present yet.
69	if ( ! start() ) {
70		var bo = new MutationObserver( function () {
71			if ( start() ) { bo.disconnect(); }
72		} );
73		bo.observe( document.documentElement, { childList: true, subtree: true } );
74	}
75}() );

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.