PageSourceSearch

https://www.blogsoestado.com/danielmatos/wp-content/plugins/wordpress-popular-posts/assets/js/wpp.js?ver=7.3.6

js blogsoestado.com collected 2026-09-24 21:28:35 UTC 5,508 bytes, 163 lines download raw bytes

1'use strict';
2
3const wpp_params = document.currentScript.dataset;
4const WordPressPopularPosts = (() => {
5    const noop = () => {};
6
7    const get = (url, params, callback = noop, additional_headers) => {
8        ajax('GET', url, params, callback, additional_headers);
9    };
10
11    const post = (url, params, callback = noop, additional_headers) => {
12        ajax('POST', url, params, callback, additional_headers);
13    };
14
15    const ajax = (method, url, params, callback, additional_headers) => {
16        const valid_methods = ['GET', 'POST'];
17        const headers = {
18            'X-Requested-With': 'XMLHttpRequest',
19            ...additional_headers
20        };
21
22        if ( ! valid_methods.includes(method) ) {
23            method = 'GET';
24        }
25
26        fetch(url + (method === 'GET' ? '?' + params : ''), {
27            method,
28            headers,
29            body: method === 'POST' ? params : null
30        })
31        .then(response => {
32            if ( ! response.ok ) {
33                throw new Error('Network response was not ok');
34            }
35            return response.text();
36        })
37        .then(data => callback(data))
38        .catch(error => console.error('Fetch error:', error));
39    };
40
41    const theme = (wpp_list) => {
42        const base_styles = document.createElement('style'),
43            dummy_list = document.createElement('ul');
44
45        dummy_list.innerHTML = '<li><a href="#"></a></li>';
46        wpp_list.parentNode.appendChild(dummy_list);
47
48        const dummy_list_item_styles = getComputedStyle(dummy_list.querySelector('li')),
49            dummy_link_item_styles = getComputedStyle(dummy_list.querySelector('li a'));
50
51        base_styles.innerHTML = `.wpp-list li {font-size: ${dummy_list_item_styles.fontSize}}`;
52        base_styles.innerHTML += `.wpp-list li a {color: ${dummy_link_item_styles.color}}`;
53
54        wpp_list.parentNode.removeChild(dummy_list);
55
56        const wpp_list_sr = wpp_list.attachShadow({mode: "open"});
57
58        wpp_list_sr.append(base_styles);
59
60        while (wpp_list.firstElementChild) {
61            wpp_list_sr.append(wpp_list.firstElementChild);
62        }
63    };
64
65    return {
66        get,
67        post,
68        ajax,
69        theme
70    };
71
72})();
73
74(() => {
75    if ( ! Object.keys(wpp_params).length ) {
76        console.error('WPP params not found, if you are using a JS minifier tool please add wpp.min.js to its exclusion list');
77        return;
78    }
79
80    const post_id = Number(wpp_params.postId);
81    let do_request = true;
82
83    if ( post_id ) {
84        if ( '1' == wpp_params.sampling ) {
85            const num = Math.floor(Math.random() * wpp_params.samplingRate) + 1;
86            do_request = ( 1 === num );
87        }
88
89        if ( 'boolean' === typeof window.wpp_do_request ) {
90            do_request = window.wpp_do_request;
91        }
92
93        if ( do_request ) {
94            WordPressPopularPosts.post(
95                `${wpp_params.apiUrl}/v2/views/${post_id}`,
96                `sampling=${wpp_params.sampling}&sampling_rate=${wpp_params.samplingRate}`,
97                ( response ) => {
98                    if ( wpp_params.debug && window.console ) {
99                        console.log(JSON.parse(response));
100                    }
101                },
102                {
103                    'Content-Type': 'application/x-www-form-urlencoded',
104                    'X-WP-Nonce': wpp_params.token
105                }
106            );
107        }
108    }
109})();
110
111document.addEventListener('DOMContentLoaded', () => {
112    if ( ! Object.keys(wpp_params).length ) {
113        return;
114    }
115
116    const widget_placeholders = document.querySelectorAll('.wpp-widget-block-placeholder, .wpp-shortcode-placeholder');
117    widget_placeholders.forEach((widget_placeholder) => fetchWidget(widget_placeholder));
118
119    const sr = document.querySelectorAll('.popular-posts-sr');
120    sr.forEach((s) => WordPressPopularPosts.theme(s));
121
122    function fetchWidget(widget_placeholder) {
123        let params = '';
124        const json_tag = widget_placeholder.parentNode.querySelector('script[type="application/json"]');
125
126        if ( json_tag ) {
127            const args = JSON.parse(json_tag.textContent.replace(/[\n\r]/g, ''));
128            params = JSON.stringify(args);
129        }
130
131        WordPressPopularPosts.post(
132            `${wpp_params.apiUrl}/v2/widget?is_single=${wpp_params.postId}${wpp_params.lang ? `&lang=${wpp_params.lang}` : ''}`,
133            params,
134            response => renderWidget(response, widget_placeholder),
135            {
136                'Content-Type': 'application/json',
137                'X-WP-Nonce': wpp_params.token
138            }
139        );
140    }
141
142    function renderWidget(response, widget_placeholder) {
143        widget_placeholder.insertAdjacentHTML('afterend', JSON.parse(response).widget);
144
145        const parent = widget_placeholder.parentNode,
146            sr = parent.querySelector('.popular-posts-sr'),
147            json_tag = parent.querySelector('script[type="application/json"]');
148
149        if ( json_tag ) {
150            parent.removeChild(json_tag);
151        }
152
153        parent.removeChild(widget_placeholder);
154        parent.classList.add('wpp-ajax');
155
156        if ( sr ) {
157            WordPressPopularPosts.theme(sr);
158        }
159
160        const event = new Event('wpp-onload', { bubbles: true, cancelable: false });
161        parent.dispatchEvent(event);
162    }
163});

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.