PageSourceSearch

https://arquivo.pt/js/init.js

js arquivo.pt collected 2026-10-01 10:14:58 UTC 2,977 bytes, 91 lines download raw bytes

1// Common procedures to run on every page load
2$(function(){
3    //make sure we have a modal div
4    let modal = $('#modal');
5    if(!modal.length){
6        $('body').append('<div id="modal" onclick="closeReplayRightMenuNav()"></div>');
7    }
8
9    //disable links inside elements with "blockUrl" class
10    $('a.blockUrl').click((e) => e.preventDefault());
11
12    //load ajax content:
13    const loadingSection = $('#loading-section');
14    if(loadingSection.length){
15        let afterReplace = () => {}
16        if(!!loadingSection.attr('onloadmessage')){
17            const message = loadingSection.attr('onloadmessage');
18            afterReplace = () => {
19                window.postMessage({
20                    'arquivo_type': 'section-loaded',
21                    message: message
22                });
23            };
24        }
25        const loadingForm = $('#loading-form');
26        $.ajax({
27            url: document.location.origin + loadingForm.attr('action')+'?'+loadingForm.serialize(),
28            success: function (data) {
29                loadingSection.replaceWith(data);
30                afterReplace();
31            }
32        });
33    }
34
35    $('body').on('submit',(e) => {
36        let form = $(e.target);
37        let trackingIdInput = form.find('input[name=trackingId]');
38        if(form.attr('action').includes('search') && !trackingIdInput.length){
39            trackingIdInput = $('<input>')
40            .attr('type','hidden')
41            .attr('name','trackingId')
42            .val(getClientId() + '_' + generateId()); //searchId_userId
43            form.append(trackingIdInput);
44        } 
45        return true;
46    })
47});
48
49
50const generateId = function (len=20) {
51    function dec2hex(dec) {
52        return ('0' + dec.toString(16)).substr(-2)
53    }
54    var arr = new Uint8Array((len || 40) / 2)
55    window.crypto.getRandomValues(arr)
56    return Array.from(arr, dec2hex).join('')
57}
58
59/*
60 * Get the client identification. If it didn't have any, generate a new one
61 * and save it to a cookie.
62 */
63const getClientId = function () {
64    function setCookie(cname, cvalue, exdays) {
65        var d = new Date();
66        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
67        var expires = "expires=" + d.toUTCString();
68        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
69    }
70    function getCookie(cname) {
71        var name = cname + "=";
72        var ca = document.cookie.split(';');
73        for (var i = 0; i < ca.length; i++) {
74            var c = ca[i];
75            while (c.charAt(0) == ' ') {
76                c = c.substring(1);
77            }
78            if (c.indexOf(name) == 0) {
79                return c.substring(name.length, c.length);
80            }
81        }
82        return "";
83    }
84    const clientIdCookieName = "client_id";
85    let client_id = getCookie(clientIdCookieName);
86    if (client_id.length == 0) {
87        client_id = generateId(20);
88        setCookie(clientIdCookieName, client_id, 1);
89    }
90    return client_id;
91}

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.