PageSourceSearch

https://www.farma.it/static/version1789421831/frontend/DNAFactory/…/Scalapay_Scalapay/js/scalapay_widget.js

js farma.it collected 2026-10-09 18:26:29 UTC 3,585 bytes, 85 lines download raw bytes

1window.addEventListener('init-external-scripts', () => {
2    // init scalapay configurations object in case it is undefined
3    if (!window.scalapayConfigurations || typeof window.scalapayConfigurations === 'undefined') {
4        window.scalapayConfigurations = {};
5    }
6
7    // instance scalapay widget observer
8    const scalapayWidgetObserver = new MutationObserver(() => {
9        // disable observer to avoid infinite loops caused by DOM changes
10        scalapayWidgetObserver.disconnect();
11
12        // loop each scalapay product configuration
13        if (Object.keys(window.scalapayConfigurations).length) {
14            for (let scalapayProduct of Object.keys(window.scalapayConfigurations)) {
15                // get current configuration
16                const currentConfiguration = window.scalapayConfigurations[scalapayProduct];
17
18                // check if amount selector exists
19                let amountSelectorExists = document.querySelector(currentConfiguration.amountSelectors);
20                if (!amountSelectorExists) {
21                    continue;
22                }
23
24                // get and check widget element
25                const widgetElement = document.querySelector(currentConfiguration.productWidgetId);
26                if (!widgetElement) {
27                    continue;
28                }
29
30                // manage widget in product view and cart page
31                if (currentConfiguration.sectionType === 'product' || currentConfiguration.sectionType === 'cart') {
32                    // get and check reference node
33                    const referenceNode = document.querySelector(currentConfiguration.textPosition);
34                    if (!referenceNode) {
35                        continue;
36                    }
37
38                    // add the widget if it hasn't been added yet
39                    if (!referenceNode.parentNode.contains(widgetElement)) {
40                        // insert widget
41                        referenceNode.parentNode.insertBefore(widgetElement, referenceNode.nextSibling);
42
43                        // show the widget
44                        document.querySelector(currentConfiguration.productWidgetId).style.visibility = 'visible';
45                    }
46                }
47
48                // manage widget into the checkout
49                if (currentConfiguration.sectionType === 'checkout') {
50                    // get and check reference
51                    if (scalapayProduct === 'payin3') { scalapayProduct = 'scalapay'; }
52                    const referenceNode = document.querySelector('#' + scalapayProduct + '-widget-container');
53                    if (!referenceNode) {
54                        continue;
55                    }
56
57                    // add the widget if it hasn't been added yet
58                    if (!referenceNode.contains(widgetElement)) {
59                        // insert widget
60                        referenceNode.appendChild(widgetElement);
61
62                        // show the widget
63                        document.querySelector(currentConfiguration.productWidgetId).style.visibility = 'visible';
64                    }
65                }
66            }
67        }
68
69        // enable again observer
70        scalapayWidgetObserver.observe(document, {
71            attributes: true,
72            childList: true,
73            characterData: true,
74            subtree: true
75        });
76    });
77
78    // instance observer
79    scalapayWidgetObserver.observe(document, {
80        attributes: true,
81        childList: true,
82        characterData: true,
83        subtree: true
84    });
85});

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.