You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

layui.define(["jquery"], function (exports) {
// 引入jQuery库并赋值给变量$
var $ = layui.$;
// 定义一个名为miniTongji的对象
var miniTongji = {
/**
* 初始化
* @param options
*/
render: function (options) {
// 设置 options.specific 的默认值为 false
options.specific = options.specific || false;
// 设置 options.domains 的默认值为空数组
options.domains = options.domains || [];
// 获取当前窗口的主机名
var domain = window.location.hostname;
// 如果 options.specific 为 false或者 options.specific 为 true 且域名在 options.domains 中
if (options.specific === false || (options.specific === true && options.domains.indexOf(domain) >=0)) {
// 调用 miniTongji 对象的 listen 方法
miniTongji.listen();
}
},
/**
* 监听统计代码
*/
listen: function () {
// 定义一个变量_hmt如果_hmt未定义则初始化为空数组
var _hmt = _hmt || [];
(function () {
// 创建一个新的script元素
var hm = document.createElement("script");
// 设置script元素的src属性为百度统计的脚本URL
hm.src = "https://hm.baidu.com/hm.js?d97abf6d61c21d773f97835defbdef4e";
// 获取文档中第一个script标签
var s = document.getElementsByTagName("script")[0];
// 将新创建的script元素插入到第一个script标签之前
s.parentNode.insertBefore(hm, s);
})();
}
};
// 导出名为 "miniTongji" 的函数,供其他模块使用
exports("miniTongji", miniTongji);
});