PageSourceSearch

https://anyi2.github.io/assets/js/analytics.js

js anyi2.github.io collected 2026-10-03 08:38:20 UTC 26,031 bytes, 841 lines download raw bytes

1// analytics.js
2
3// date range
4const establishedAt = new Date($('meta[name=established_at]').attr('content'));
5// function siteEstablishedDays() {
6//     let d = new Date();
7//     let today = new Date(d.getFullYear(), d.getMonth(), d.getDate());
8//     return Math.floor((today - establishedAt) / 86400000 + 1);
9// };
10
11// clock
12$('#established-at').countdown(establishedAt, {
13    elapse: true
14}).on('update.countdown', function (event) {
15    if (event.elapsed) {
16        $(this).html(event.strftime('<div class="ui label"><i class="rocket icon"></i>已上线</div><div class="ui label">%D<div class="detail">天</div></div><div class="ui label">%-H<div class="detail">小时</div></div><div class="ui label">%-M<div class="detail">分</div></div><div class="ui label">%-S<div class="detail">秒</div></div>'));
17    };
18});// visit
19var countUpOptions = {
20    useEasing: true,
21    useGrouping: true,
22    separator: ',',
23    decimal: '.',
24    prefix: '',
25    suffix: ''
26};
27var yesterdayVisitorsCountUp = new CountUp('yesterday-visitors-stat', 0, 0, 0, 2.5, countUpOptions);
28var yesterdayVisitsCountUp = new CountUp('yesterday-visits-stat', 0, 0, 0, 2.5, countUpOptions);
29var yesterdayActionsCountUp = new CountUp('yesterday-actions-stat', 0, 0, 0, 2.5, countUpOptions);
30// var totalActionsCountUp = new CountUp('total-actions', 0, 0, 0, 2.5, countUpOptions);
31var liveVisitorsCountUp = new CountUp('live-visitors-stat', 0, 0, 0, 2.5, countUpOptions);
32var todayVisitorsCountUp = new CountUp('today-visitors-stat', 0, 0, 0, 2.5, countUpOptions);
33var todayVisitsCountUp = new CountUp('today-visits-stat', 0, 0, 0, 2.5, countUpOptions);
34var todayActionsCountUp = new CountUp('today-actions-stat', 0, 0, 0, 2.5, countUpOptions);
35$.getJSON('https://navi.shudao.org/', {
36    'module': 'API',
37    'method': 'VisitsSummary.getUniqueVisitors',
38    'idSite': '1',
39    'period': 'day',
40    'date': 'yesterday',
41    'format': 'JSON',
42    'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
43}, function (data) {
44    yesterdayVisitorsCountUp.update(data.value);
45});
46$.getJSON('https://navi.shudao.org/', {
47    'module': 'API',
48    'method': 'VisitsSummary.getVisits',
49    'idSite': '1',
50    'period': 'day',
51    'date': 'yesterday',
52    'format': 'JSON',
53    'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
54}, function (data) {
55    yesterdayVisitsCountUp.update(data.value);
56});
57$.getJSON('https://navi.shudao.org/', {
58    'module': 'API',
59    'method': 'VisitsSummary.getActions',
60    'idSite': '1',
61    'period': 'day',
62    'date': 'yesterday',
63    'format': 'JSON',
64    'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
65}, function (data) {
66    yesterdayActionsCountUp.update(data.value);
67});
68(function updateVisit() {
69    if (!document.hidden) {
70        // $.getJSON('https://navi.shudao.org/', {
71        //     'module': 'API',
72        //     'method': 'VisitsSummary.getActions',
73        //     'idSite': '1',
74        //     'period': 'range',
75        //     'date': `last${siteEstablishedDays()}`,
76        //     'format': 'JSON',
77        //     'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
78        // }, function (data) {
79        //     totalActionsCountUp.update(data.value);
80        // });
81        $.getJSON('https://navi.shudao.org/', {
82            'module': 'API',
83            'method': 'Live.getCounters',
84            'idSite': '1',
85            'lastMinutes': '30',
86            'format': 'JSON',
87            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
88        }, function (data) {
89            liveVisitorsCountUp.update(data[0].visitors);
90        });
91        $.getJSON('https://navi.shudao.org/', {
92            'module': 'API',
93            'method': 'VisitsSummary.getUniqueVisitors',
94            'idSite': '1',
95            'period': 'day',
96            'date': 'today',
97            'format': 'JSON',
98            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
99        }, function (data) {
100            todayVisitorsCountUp.update(data.value);
101        });
102        $.getJSON('https://navi.shudao.org/', {
103            'module': 'API',
104            'method': 'VisitsSummary.getVisits',
105            'idSite': '1',
106            'period': 'day',
107            'date': 'today',
108            'format': 'JSON',
109            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
110        }, function (data) {
111            todayVisitsCountUp.update(data.value);
112        });
113        $.getJSON('https://navi.shudao.org/', {
114            'module': 'API',
115            'method': 'VisitsSummary.getActions',
116            'idSite': '1',
117            'period': 'day',
118            'date': 'today',
119            'format': 'JSON',
120            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
121        }, function (data) {
122            todayActionsCountUp.update(data.value);
123        });
124    };
125    setTimeout(function () {
126        updateVisit();
127    }, );
128})();
129
130// chart
131var visitSummaryChart = echarts.init(document.getElementById('visit-summary'), 'light');
132visitSummaryChart.setOption({
133    baseOption: {
134        title: {
135            text: '访客数据总览(过去90天)',
136            left: 'center'
137        },
138        legend: {
139            data: ['访客数', '访问次数', '浏览次数'],
140            right: 'center',
141            top: 30
142        },
143        tooltip: {
144            trigger: 'axis',
145            axisPointer: {
146                type: 'shadow'
147            }
148        },
149        toolbox: {
150            showTitle: false,
151            feature: {
152                restore: {},
153                magicType: {
154                    type: ['bar', 'line']
155                },
156                dataView: {
157                    readOnly: true
158                },
159                saveAsImage: {
160                    excludeComponents: ['toolbox', 'dataZoom']
161                }
162            }
163        },
164        dataZoom: [
165            {
166                type: 'slider',
167                show: true,
168                realtime: true,
169                xAxisIndex: [0],
170                start: 50,
171                end: 100
172            }
173        ],
174        xAxis: {
175            type : 'category',
176            data: []
177        },
178        yAxis: {
179            type: 'value'
180        },
181        series: [{
182            name: '访客数',
183            type: 'bar',
184            data: [],
185            animationDelay: function (idx) {
186                return idx * 10;
187            }
188        }, {
189            name: '访问次数',
190            type: 'bar',
191            data: [],
192            animationDelay: function (idx) {
193                return idx * 10 + 100;
194            }
195        }, {
196            name: '浏览次数',
197            type: 'bar',
198            data: [],
199            animationDelay: function (idx) {
200                return idx * 10 + 200;
201            }
202        }],
203        animationEasing: 'elasticOut',
204        animationDelayUpdate: function (idx) {
205            return idx * 5;
206        }
207    },
208    media: [{
209        query: {
210            maxWidth: 767
211        },
212        option: {
213            legend: {
214                orient: 'vertical'
215            },
216            grid: {
217                top: 110,
218                left: 40,
219                right: 10
220            },
221            toolbox: {
222                show: false
223            }
224        }
225    }]
226});
227(function updateVisitSummaryChart() {
228    if (!document.hidden) {
229        $.getJSON('https://navi.shudao.org/', {
230            'module': 'API',
231            'method': 'VisitsSummary.getUniqueVisitors',
232            'idSite': '1',
233            'period': 'day',
234            'date': 'last90',
235            'format': 'JSON',
236            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
237        }, function (data) {
238            var days = [];
239            var visitors = [];
240            for (var i in data) {
241                days.push(i);
242                visitors.push(data[i]);
243            };
244            visitSummaryChart.setOption({
245                xAxis: {
246                    data: days
247                },
248                series: [{
249                    name: '访客数',
250                    data: visitors
251                }]
252            });
253        });
254        $.getJSON('https://navi.shudao.org/', {
255            'module': 'API',
256            'method': 'VisitsSummary.getVisits',
257            'idSite': '1',
258            'period': 'day',
259            'date': 'last90',
260            'format': 'JSON',
261            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
262        }, function (data) {
263            var visits = [];
264            for (var i in data) {
265                visits.push(data[i]);
266            };
267            visitSummaryChart.setOption({
268                series: [{
269                    name: '访问次数',
270                    data: visits
271                }]
272            });
273        });
274        $.getJSON('https://navi.shudao.org/', {
275            'module': 'API',
276            'method': 'VisitsSummary.getActions',
277            'idSite': '1',
278            'period': 'day',
279            'date': 'last90',
280            'format': 'JSON',
281            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
282        }, function (data) {
283            var actions = [];
284            for (var i in data) {
285                actions.push(data[i]);
286            };
287            visitSummaryChart.setOption({
288                series: [{
289                    name: '浏览次数',
290                    data: actions
291                }]
292            });
293        });
294    };
295    setTimeout(function () {
296        updateVisitSummaryChart();
297    }, );
298})();
299
300var visitHourlyChart = echarts.init(document.getElementById('visit-hourly'), 'light');
301visitHourlyChart.setOption({
302    baseOption: {
303        title: {
304            text: '访客数据(7×24小时)',
305            left: 'center'
306        },
307        legend: {
308            data: ['访客数', '访问次数', '浏览次数'],
309            selectedMode: 'single',
310            right: 'center',
311            top: 30
312        },
313        tooltip: {
314            position: 'top',
315            formatter: function (params) {
316                return `${params.value[1]} ${params.value[0]}<br>${params.seriesName}: ${params.value[2]}`;
317            }
318        },
319        toolbox: {
320            showTitle: false,
321            feature: {
322                restore: {},
323                saveAsImage: {
324                    excludeComponents: ['toolbox']
325                }
326            }
327        },
328        xAxis: {
329            type: 'category',
330            data: ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'],
331            boundaryGap: false,
332            splitLine: {
333                show: true,
334                lineStyle: {
335                    type: 'dashed'
336                }
337            },
338            axisLine: {
339                show: false
340            }
341        },
342        yAxis: {
343            type: 'category',
344            data: [],
345            axisLine: {
346                show: false
347            }
348        },
349        series: [{
350            name: '访客数',
351            type: 'scatter',
352            data: [],
353            animationDelay: function (idx) {
354                return idx * 10 + 100;
355            }
356        },
357        {
358            name: '访问次数',
359            type: 'scatter',
360            data: [],
361            animationDelay: function (idx) {
362                return idx * 10 + 100;
363            }
364        },
365        {
366            name: '浏览次数',
367            type: 'scatter',
368            data: [],
369            animationDelay: function (idx) {
370                return idx * 10 + 100;
371            }
372        }]
373    },
374    media: [{
375        query: {
376            maxWidth: 767
377        },
378        option: {
379            legend: {
380                orient: 'vertical'
381            },
382            grid: {
383                top: 110,
384                left: 70,
385                right: 10
386            },
387            toolbox: {
388                show: false
389            }
390        }
391    }]
392});
393function normalizeSymbolSize(val, data, resize) {
394    if (val === 0) {
395        return 0;
396    } else {
397        if (resize) {
398            var max = 20;
399            var min = 5;
400        } else {
401            var max = 40;
402            var min = 10;
403        };
404        var data_max = Math.max(...data.map(function(item) {
405            return item[2];
406        }));
407        var data_min = Math.min(...data.map(function(item) {
408            return item[2];
409        }));
410        if (data_max === data_min) {
411            return (max - min) / 2 + min;
412        } else {
413            return (val - data_min) / (data_max - data_min) * (max - min) + min;
414        };
415    };
416};
417(function updateVisitHourlyChart() {
418    if (!document.hidden) {
419        $.getJSON('https://navi.shudao.org/', {
420            'module': 'API',
421            'method': 'VisitTime.getVisitInformationPerServerTime',
422            'idSite': '1',
423            'period': 'day',
424            'date': 'last7',
425            'format': 'JSON',
426            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
427        }, function (data) {
428            var days = [];
429            var visitors = [];
430            var visits = [];
431            var actions = [];
432            for (var day in data) {
433                days.unshift(day);
434                for (var hourNum in data[day]) {
435                    visitors.push([data[day][hourNum]['label'], day, data[day][hourNum]['nb_uniq_visitors']]);
436                    visits.push([data[day][hourNum]['label'], day, data[day][hourNum]['nb_visits']]);
437                    actions.push([data[day][hourNum]['label'], day, data[day][hourNum]['nb_actions']]);
438                };
439            };
440            visitHourlyChart.setOption({
441                baseOption: {
442                    yAxis: {
443                        data: days
444                    },
445                    series: [{
446                        name: '访客数',
447                        data: visitors,
448                        symbolSize: function (val) {
449                            return normalizeSymbolSize(val[2], visitors, false);
450                        }
451                    },
452                    {
453                        name: '访问次数',
454                        data: visits,
455                        symbolSize: function (val) {
456                            return normalizeSymbolSize(val[2], visits, false);
457                        }
458                    },
459                    {
460                        name: '浏览次数',
461                        data: actions,
462                        symbolSize: function (val) {
463                            return normalizeSymbolSize(val[2], actions, false);
464                        }
465                    }]
466                },
467                media: [{
468                    query: {
469                        maxWidth: 767
470                    },
471                    option: {
472                        series: [{
473                            name: '访客数',
474                            data: visitors,
475                            symbolSize: function (val) {
476                                return normalizeSymbolSize(val[2], visitors, true);
477                            }
478                        },
479                        {
480                            name: '访问次数',
481                            data: visits,
482                            symbolSize: function (val) {
483                                return normalizeSymbolSize(val[2], visits, true);
484                            }
485                        },
486                        {
487                            name: '浏览次数',
488                            data: actions,
489                            symbolSize: function (val) {
490                                return normalizeSymbolSize(val[2], actions, true);
491                            }
492                        }]
493                    }
494                }]
495            });
496        });
497    };
498    setTimeout(function () {
499        updateVisitHourlyChart();
500    }, );
501})();
502
503var visitMapChart = echarts.init(document.getElementById('visit-map'), 'light');
504visitMapChart.setOption({
505    baseOption: {
506        title: {
507            text: '本月访客来源',
508            left: 'center'
509        },
510        legend: {
511            data: ['访客数', '访问次数', '浏览次数'],
512            selectedMode: 'single',
513            right: 'center',
514            top: 30
515        },
516        tooltip: {
517            trigger: 'item',
518            formatter: function (params) {
519                var value = params.value;
520                if (!value) {
521                    value = 0;
522                };
523                return `${params.seriesName}: ${value}`;
524            }
525        },
526        toolbox: {
527            showTitle: false,
528            feature: {
529                restore: {},
530                saveAsImage: {
531                    excludeComponents: ['toolbox']
532                }
533            }
534        },
535        visualMap: {
536            min: 0,
537            max: 5000,
538            text:['High','Low'],
539            calculable: true
540        },
541        series: [{
542            name: '访客数',
543            type: 'map',
544            mapType: 'world',
545            showLegendSymbol: false,
546            itemStyle: {
547                emphasis: {
548                    label: {
549                        show:true
550                    }
551                }
552            },
553            data:[]
554        },
555        {
556            name: '访问次数',
557            type: 'map',
558            mapType: 'world',
559            showLegendSymbol: false,
560            itemStyle: {
561                emphasis: {
562                    label: {
563                        show:true
564                    }
565                }
566            },
567            data:[]
568        },
569        {
570            name: '浏览次数',
571            type: 'map',
572            mapType: 'world',
573            showLegendSymbol: false,
574            itemStyle: {
575                emphasis: {
576                    label: {
577                        show:true
578                    }
579                }
580            },
581            data:[]
582        }]
583    },
584    media: [{
585        query: {
586            maxWidth: 767
587        },
588        option: {
589            legend: {
590                orient: 'vertical'
591            },
592            toolbox: {
593                show: false
594            }
595        }
596    }]
597});
598(function updateVisitMapChart() {
599    if (!document.hidden) {
600        $.getJSON('https://navi.shudao.org/', {
601            'module': 'API',
602            'method': 'UserCountry.getCountry',
603            'idSite': '1',
604            'period': 'month',
605            'date': 'today',
606            'format': 'JSON',
607            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
608        }, function (data) {
609            var visitors = [];
610            var visits = [];
611            var actions = [];
612            var visitorsChina = 0;
613            var visitsChina = 0;
614            var actionsChina = 0;
615            for (var i in data) {
616                if (data[i]['label'] == 'China') {
617                    var visitorsChina = visitorsChina + data[i]['sum_daily_nb_uniq_visitors'];
618                    var visitsChina = visitsChina + data[i]['nb_visits'];
619                    var actionsChina = actionsChina + data[i]['nb_actions'];
620                } else if (data[i]['label'] == 'Hong Kong SAR China') {
621                    var visitorsChina = visitorsChina + data[i]['sum_daily_nb_uniq_visitors'];
622                    var visitsChina = visitsChina + data[i]['nb_visits'];
623                    var actionsChina = actionsChina + data[i]['nb_actions'];
624                } else if (data[i]['label'] == 'Taiwan') {
625                    var visitorsChina = visitorsChina + data[i]['sum_daily_nb_uniq_visitors'];
626                    var visitsChina = visitsChina + data[i]['nb_visits'];
627                    var actionsChina = actionsChina + data[i]['nb_actions'];
628                } else if (data[i]['label'] == 'Unknown') {
629                    var visitorsChina = visitorsChina + data[i]['sum_daily_nb_uniq_visitors'];
630                    var visitsChina = visitsChina + data[i]['nb_visits'];
631                    var actionsChina = actionsChina + data[i]['nb_actions'];
632                } else {
633                    visitors.push({
634                        'name': data[i]['label'],
635                        'value': data[i]['sum_daily_nb_uniq_visitors']
636                    });
637                    visits.push({
638                        'name': data[i]['label'],
639                        'value': data[i]['nb_visits']
640                    });
641                    actions.push({
642                        'name': data[i]['label'],
643                        'value': data[i]['nb_actions']
644                    });
645                };
646            };
647            visitors.push({
648                'name': 'China',
649                'value': visitorsChina
650            });
651            visits.push({
652                'name': 'China',
653                'value': visitsChina
654            });
655            actions.push({
656                'name': 'China',
657                'value': actionsChina
658            });
659            visitMapChart.setOption({
660                series: [{
661                    name: '访客数',
662                    data: visitors
663                },
664                {
665                    name: '访问次数',
666                    data: visits
667                },
668                {
669                    name: '浏览次数',
670                    data: actions
671                }]
672            });
673        });
674    };
675    setTimeout(function () {
676        updateVisitMapChart();
677    }, );
678})();
679
680var visitCalendarChart = echarts.init(document.getElementById('visit-calendar'), 'light');
681// var firstYear = establishedAt.getFullYear();
682const thisYear = new Date().getUTCFullYear();
683const firstYear = thisYear - 4;
684const secondYear = thisYear - 3;
685const thirdYear = thisYear - 2;
686const fourthYear = thisYear - 1;
687visitCalendarChart.setOption({
688    baseOption: {
689        title: {
690            text: '历年浏览数据',
691            left: 'center'
692        },
693        tooltip: {
694            position: 'top',
695            formatter: function (p) {
696                return `${echarts.format.formatTime('yyyy-MM-dd', p.data[0])} 浏览次数:${p.data[1]}`;
697            }
698        },
699        toolbox: {
700            showTitle: false,
701            feature: {
702                restore: {},
703                saveAsImage: {
704                    excludeComponents: ['toolbox']
705                }
706            }
707        },
708        visualMap: {
709            min: 50,
710            max: 1000,
711            calculable: true,
712            orient: 'horizontal',
713            top: 'top',
714            left: 0
715        },
716        calendar: [{
717            range: firstYear,
718            right: 5
719        }, {
720            range: secondYear,
721            right: 5,
722            top: 240
723        }, {
724            range: thirdYear,
725            right: 5,
726            top: 420
727        }, {
728            range: fourthYear,
729            right: 5,
730            top: 600
731        }, {
732            range: thisYear,
733            right: 5,
734            top: 780
735        }],
736        series: [{
737            type: 'heatmap',
738            coordinateSystem: 'calendar',
739            calendarIndex: 0,
740            data: []
741        }, {
742            type: 'heatmap',
743            coordinateSystem: 'calendar',
744            calendarIndex: 1,
745            data: []
746        }, {
747            type: 'heatmap',
748            coordinateSystem: 'calendar',
749            calendarIndex: 2,
750            data: []
751        }, {
752            type: 'heatmap',
753            coordinateSystem: 'calendar',
754            calendarIndex: 3,
755            data: []
756        }, {
757            type: 'heatmap',
758            coordinateSystem: 'calendar',
759            calendarIndex: 4,
760            data: []
761        }]
762    },
763    media: [{
764        query: {
765            maxWidth: 767
766        },
767        option: {
768            toolbox: {
769                show: false
770            },
771            visualMap: {
772                orient: 'vertical'
773            },
774            calendar: [{
775                orient: 'vertical',
776                left: 'center',
777                top: 90
778            }, {
779                orient: 'vertical',
780                left: 'center',
781                top: 1220
782            }, {
783                orient: 'vertical',
784                left: 'center',
785                top: 2350
786            }, {
787                orient: 'vertical',
788                left: 'center',
789                top: 3480
790            }, {
791                orient: 'vertical',
792                left: 'center',
793                top: 4610
794            }]
795        }
796    }]
797});
798(function updateVisitCalendarChart() {
799    if (!document.hidden) {
800        $.getJSON('https://navi.shudao.org/', {
801            'module': 'API',
802            'method': 'VisitsSummary.getActions',
803            'idSite': '1',
804            'period': 'day',
805            // 'date': `last${siteEstablishedDays()}`,
806            'date': 'last1825',
807            'format': 'JSON',
808            'token_auth': 'bb72e1b78aa69d034f10f8351e5dc98f'
809        }, function (data) {
810            var cursorYear = firstYear;
811            var series = [{
812                calendarIndex: cursorYear - firstYear,
813                data: []
814            }];
815            for (var i in data) {
816                if (data[i] !== 0) {
817                    year = Number(i.slice(0, 4));
818                    if (year > cursorYear && year <= thisYear) {
819                        cursorYear = year;
820                        series.push({
821                            calendarIndex: cursorYear - firstYear,
822                            data: []
823                        });
824                    } else if (year < firstYear || year > thisYear) {
825                        continue;
826                    };
827                    series[cursorYear - firstYear].data.push([
828                        echarts.format.formatTime('yyyy-MM-dd', i),
829                        data[i]
830                    ]);
831                };
832            };
833            visitCalendarChart.setOption({
834                series: series
835            });
836        });
837    };
838    setTimeout(function () {
839        updateVisitCalendarChart();
840    }, );
841})();

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.