PageSourceSearch

https://rarus.ru/local/templates/rarus.light/js/browser_history.js?17858436822958

js rarus.ru collected 2026-09-24 09:33:56 UTC 2,958 bytes, 98 lines download raw bytes

1//task#35843 - parkdm
2/* start session history */
3
4function getLocalIsoString(date) {
5    function pad(n) { return n < 10 ? '0' + n : n }
6    var localIsoString = date.getFullYear() + '-'
7        + pad(date.getMonth() + 1) + '-'
8        + pad(date.getDate()) + 'T'
9        + pad(date.getHours()) + ':'
10        + pad(date.getMinutes()) + ':'
11        + pad(date.getSeconds());
12    if(date.getTimezoneOffset() == 0) {
13        localIsoString += 'Z';
14    }
15    return localIsoString;
16}
17
18function getTimeZone(date) {
19    var offset = date.getTimezoneOffset(), o = Math.abs(offset);
20    return (offset < 0 ? "+" : "-") + ("00" + Math.floor(o / 60)).slice(-2) + ":" + ("00" + (o % 60)).slice(-2);
21}
22
23function isServicePath(url) {
24    try {
25        const path = (url && url.indexOf('://') !== -1) ? new URL(url).pathname : url;
26        return path.indexOf('/bitrix/') === 0 || path.indexOf('/local/') === 0;
27    } catch (e) {
28        return false;
29    }
30}
31
32function computeReferrer() {
33    const ref = document.referrer;
34    if (!ref) {
35        return '';
36    }
37    if (isServicePath(ref)) {
38        return '';
39    }
40    if (ref.indexOf('rarus.ru') !== -1) {
41        return '';
42    }
43    return ref;
44}
45
46if (typeof browserHistory === 'undefined') {
47    var browserHistory = {};
48}
49
50browserHistory.getLastUrls = function (count = 40) {
51    return JSON.stringify(browserHistory.pages.slice(-count));
52};
53
54browserHistory.appendCurrentUrl = function () {
55    var date = new Date();
56    const page = {
57        'date': getLocalIsoString(date) + getTimeZone(date),
58        'page': window.location.href,
59        'session': typeof bxauth !== 'undefined' ? bxauth.sessid : typeof BX !== 'undefined' ? BX.bitrix_sessid() : '',
60        'referrer': ''
61    };
62    browserHistory.appendUrl(page);
63};
64
65browserHistory.appendUrl = function (page) {
66    const key = 'browser_history';
67
68    if (isServicePath(page.page)) {
69        return;
70    }
71
72    if (tempBrowserHistory === undefined){
73        var tempBrowserHistory = JSON.parse(localStorage.getItem(key));
74    }
75
76    if (tempBrowserHistory !== null && tempBrowserHistory.pages !== undefined) {
77        const lastPageInHistory = tempBrowserHistory.pages[tempBrowserHistory.pages.length - 1];
78        const isNewSession = page.session !== lastPageInHistory.session;
79        if ((lastPageInHistory.page !== page.page) || isNewSession) {
80            if (isNewSession) {
81                page.referrer = computeReferrer();
82            }
83            tempBrowserHistory.pages.push(page);
84            tempBrowserHistory.pages = tempBrowserHistory.pages.slice(-tempBrowserHistory.limit);
85        }
86    } else {
87        page.referrer = computeReferrer();
88        tempBrowserHistory = {
89            "pages": [page]
90        };
91        browserHistory.limit = 60;
92    }
93    browserHistory.pages = tempBrowserHistory.pages;
94    localStorage.setItem(key, JSON.stringify(browserHistory));
95};
96
97browserHistory.appendCurrentUrl();
98/* end session history*/

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.