PageSourceSearch

https://divinebox.fr/wp-content/cache/wpfc-minified/mkrrxfru/af913.js

js divinebox.fr collected 2026-10-02 11:20:12 UTC 3,550 bytes, 154 lines download raw bytes

1// source --> https://divinebox.fr/wp-content/plugins/facebook-for-woocommerce/assets/js/facebook-for-woocommerce-signals.js?ver=3.7.6 
2/**
3 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
4 *
5 * This source code is licensed under the license found in the
6 * LICENSE file in the root directory of this source tree.
7 *
8 * @package FacebookCommerce
9 */
10
11/**
12 * Facebook for WooCommerce - Signals helper.
13 *
14 * Exposes `window.fbwcsignal` so a CMP or theme integration can hold or
15 * release signal delivery while keeping the plugin loaded.
16 *
17 * @package FacebookCommerce
18 */
19( function () {
20	'use strict';
21
22	var COOKIE_NAME = 'wc_facebook_signals_state';
23	var STATE_ACTIVE = 'active';
24	var STATE_HELD = 'held';
25
26	/**
27	 * Minimal cookie setter.
28	 *
29	 * @param {string} name
30	 * @param {string} value
31	 * @param {number} days
32	 */
33	function setCookie( name, value, days ) {
34		var d = new Date();
35		d.setTime( d.getTime() + days * 86400000 );
36		document.cookie =
37			name +
38			'=' +
39			encodeURIComponent( value ) +
40			';expires=' +
41			d.toUTCString() +
42			';path=/;SameSite=Lax';
43	}
44
45	/**
46	 * Read a cookie value.
47	 *
48	 * @param {string} name
49	 * @return {string|null}
50	 */
51	function getCookie( name ) {
52		var match = document.cookie.match(
53			new RegExp( '(?:^|;\\s*)' + name + '=([^;]*)' )
54		);
55		return match ? decodeURIComponent( match[ 1 ] ) : null;
56	}
57
58	/**
59	 * Update the stored signal state and sync it to PHP.
60	 *
61	 * @param {string} state `active` or `held`.
62	 * @return {Promise} Resolves with the backend response.
63	 */
64	function updateState( state ) {
65		setCookie( COOKIE_NAME, state, 365 );
66
67		var params = wc_facebook_signals_params; // localized by PHP.
68
69		return new Promise( function ( resolve, reject ) {
70			var xhr = new XMLHttpRequest();
71			xhr.open( 'POST', params.ajax_url, true );
72			xhr.setRequestHeader(
73				'Content-Type',
74				'application/x-www-form-urlencoded; charset=UTF-8'
75			);
76			xhr.onload = function () {
77				if ( xhr.status >= 200 && xhr.status < 300 ) {
78					try {
79						var data = JSON.parse( xhr.responseText );
80						resolve( data );
81					} catch ( e ) {
82						reject( e );
83					}
84				} else {
85					reject( new Error( 'AJAX failed: ' + xhr.status ) );
86				}
87			};
88			xhr.onerror = function () {
89				reject( new Error( 'Network error' ) );
90			};
91			xhr.send(
92				'action=' +
93					encodeURIComponent( params.action ) +
94					'&security=' +
95					encodeURIComponent( params.nonce ) +
96					'&state=' +
97					encodeURIComponent( state )
98			);
99		} );
100	}
101
102	/**
103	 * Hold browser/server signals for subsequent requests.
104	 *
105	 * @return {Promise}
106	 */
107	function hold() {
108		return updateState( STATE_HELD );
109	}
110
111	/**
112	 * Release held signals and flush any queued browser events.
113	 *
114	 * @return {Promise}
115	 */
116	function release() {
117		return updateState( STATE_ACTIVE ).then( function ( data ) {
118			if (
119				window.FacebookSignals &&
120				window.FacebookSignals._held
121			) {
122				return window.FacebookSignals.release().then(
123					function () {
124						return data;
125					},
126					function () {
127						return data;
128					}
129				);
130			}
131
132			return data;
133		} );
134	}
135
136	/**
137	 * Read the current signal state from the cookie.
138	 *
139	 * @return {string|null} `active`, `held`, or `null`.
140	 */
141	function getState() {
142		var val = getCookie( COOKIE_NAME );
143		if ( val === null ) {
144			return null;
145		}
146
147		return val === STATE_ACTIVE ? STATE_ACTIVE : STATE_HELD;
148	}
149
150	window.fbwcsignal = window.fbwcsignal || {};
151	window.fbwcsignal.hold = hold;
152	window.fbwcsignal.release = release;
153	window.fbwcsignal.getState = getState;
154} )();

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.