PageSourceSearch

https://xyhjjh.shcmusic.edu.cn/_js/jquery.sudy.wp.visitcount.js

js shcmusic.edu.cn collected 2026-10-02 07:44:26 UTC 7,873 bytes, 226 lines download raw bytes

1/**
2 * 主要为了实现文章评价功能
3 * add by lcfeng
4 */
5$(document).ready(function() {
6
7    $.fn.WPVisitCount = function (options) {
8        var defaults = {};
9        var options = $.extend(defaults, options);
10        $(this).each(function (index) {
11            var url = $(this).attr("url");
12            if (url) {
13                initVisitCount(url, index);
14            }
15        });
16
17        //初始化访问次数
18        function initVisitCount(url, obj) {
19            $.ajax({
20                type: "post",
21                dataType: "text",
22                url: url,
23                success: function (result) {
24                    const targetEl = $('.WP_VisitCount')?.eq(obj)
25                    if (targetEl && result !== '' && result !== '0' && result !== '<span>0</span>') {
26                        targetEl.html(result);
27                        targetEl.show();
28                    }
29                },
30                error: function (error) {
31                }
32            });
33        }
34    };
35
36    $.fn.WPColListVisitCount = function(options) {
37        var defaults = {};
38        var options = $.extend(defaults, options);
39        var colId = new Array();
40        var colIds = "";
41        $(this).each(function() {
42            var id = $(this).attr("colId");
43            var siteId = $(this).attr("siteId");
44            id += "_" + siteId;
45            colId.push(id);
46            colId = unique(colId);
47        });
48        colIds = colId.join(",");
49        if (colIds == "") {
50            return;
51        }
52        var url = "";
53        var con = $("script[sudy-wp-context]").attr("sudy-wp-context");
54        if (con) {
55            con = "/" + con;
56            url += con;
57        }
58//        url += "/_visitcountdisplay?columnIds=" + colIds;
59        url += "/_visitcountdisplay?funType=0";
60        var type = $("span[class=WP_ColsVisitCount]").attr("type");
61        if (type) {
62            url += "&type=" + type;
63        }
64//        url += "&funType=0";
65        initColListVisitCount(url, colIds);
66    };
67
68    function initColListVisitCount(url, colIds) {
69        $.ajax({
70            url: url,
71            dataType: 'json',
72            type: 'post',
73            data: {columnIds: colIds},
74            success: function(result) {
75                if (result !== '' && result !== null) {
76                    $.each(result, function(n, value) {
77                        var listVisitCount = $("span[colListVisitCountId=wp_colListVisitCount_" + value.columnId + "]");
78                        var oldCount = listVisitCount.html();
79                        var num = oldCount > value.count ? (oldCount - value.count) : (value.count - oldCount);
80                        var total = value.count + num;
81                        listVisitCount.html(total);
82                        listVisitCount.css('visibility', 'visible');
83                    });
84                }
85            }
86        });
87    }
88    ;
89
90    $.fn.WPArticleReadStatus = function(options) {
91        var defaults = {};
92        var options = $.extend(defaults, options);
93        var artId = new Array();
94        var articleIds = "";
95        $(this).each(function() {
96            var id = $(this).attr("artId");
97            artId.push(id);
98            artId = unique(artId);
99        });
100        articleIds = artId.join(",");
101        if (articleIds != null && articleIds != '') {
102            var url = "";
103            var con = $("script[sudy-wp-context]").attr("sudy-wp-context");
104            if (con) {
105                con = "/" + con;
106                url += con;
107            }
108            url += "/_visitcountdisplay?articleIds=" + articleIds;
109            var siteId = $("script[sudy-wp-siteId]").attr("sudy-wp-siteId");
110            if (siteId) {
111                url += "&siteId=" + siteId;
112            }
113            url += "&funType=1";
114            initReadStatus(url);
115        }
116    };
117
118    function unique(arr) {
119        var res = [];
120        var json = {};
121        for (var i = 0; i < arr.length; i++) {
122            if (!json[arr[i]]) {
123                res.push(arr[i]);
124                json[arr[i]] = 1;
125            }
126        }
127        return res;
128    }
129
130    function initReadStatus(url) {
131        $.ajax({
132            url: url,
133            dataType: 'text',
134            type: "post",
135            success: function(result) {
136                if (result !== "") {
137                    var artIds = result.split(",");
138                    for (var i = 0; i < artIds.length; i++) {
139                        $("span[readStatusId=wp_artReadStauts_" + artIds[i] + "]").addClass("wp_artReadStatus_unread");
140                    }
141                }
142            }
143        });
144    }
145    ;
146
147    $.fn.WPListVisitCount = function(options) {
148        var defaults = {};
149        var options = $.extend(defaults, options);
150        var artId = new Array();
151        var articleIds = "";
152        $(this).each(function() {
153            var id = $(this).attr("artId");
154            artId.push(id);
155            artId = unique(artId);
156        });
157        articleIds = artId.join(",");
158        if (articleIds != null && articleIds != '') {
159            var url = "";
160            var con = $("script[sudy-wp-context]").attr("sudy-wp-context");
161            if (con) {
162                con = "/" + con;
163                url += con;
164            }
165            url += "/_visitcountdisplay?articleIds=" + articleIds;
166            var siteId = $("script[sudy-wp-siteId]").attr("sudy-wp-siteId");
167            if (siteId) {
168                url += "&siteId=" + siteId;
169            }
170            var type = $("span[class=wp_listVisitCount]").attr("type");
171            if (type) {
172                url += "&type=" + type;
173            }
174            url += "&funType=0";
175            initListVisitCount(url);
176        }
177    };
178
179    function initListVisitCount(url) {
180        $.ajax({
181            url: url,
182            dataType: 'json',
183            type: 'post',
184            success: function(result) {
185                if (result !== '' && result !== null) {
186                    $.each(result, function(n, value) {
187                        var listVisitCount = $("span[listVisitCountId=wp_listVisitCount_" + value.articleId + "]");
188                        listVisitCount.html(value.count);
189                        listVisitCount.css('visibility', 'visible');
190                    });
191                }
192            }
193        });
194    };
195
196
197    if ($('.WP_VisitCount').hasClass('WP_VisitCount')) {
198        $('.WP_VisitCount').WPVisitCount();
199    }
200    if ($('.wp_artReadStatus').hasClass('wp_artReadStatus')) {
201        $('.wp_artReadStatus').WPArticleReadStatus();
202    }
203    if ($('.wp_listVisitCount').hasClass('wp_listVisitCount')) {
204        $('.wp_listVisitCount').WPListVisitCount();
205    }
206    if ($('.WP_ColsVisitCount').hasClass('WP_ColsVisitCount')) {
207        $('.WP_ColsVisitCount').WPColListVisitCount();
208    }
209}); 
210
211//下面这个根据ip获取地址的接口坏了,如果要使用,需要另找接口
212//$().ready(function() {
213//    $.ajax({
214//        type: 'get',
215//        dataType: 'jsonp',
216//        //url: "http://ip.chinaz.com/ajaxsync.aspx?at=ip&ip=" + ip, //这里是url
217//        url: "http://ip.chinaz.com/getip.aspx",//调用URL返回ip和来访地址 返回值{ip:'xxx.xxx.xxx.xxx',address:'江苏省南京市 电信'}
218//        success: function(data) {
219//            var address = data.address.replace("电信", "").replace("移动","").replace("联通","");//取出地址并且将里面的运营商去掉
220//            document.cookie = "ipAddressName=" + escape(address) + ";path=/; ";//将地址信息塞入cookie
221//        },
222//        error: function() {
223//       
224//        }
225//    });
226//})

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.