PageSourceSearch

https://static.mrxiao.net/usr/plugins/AliceStyle/static/js/app/as-tool.js

js mrxiao.net collected 2026-10-06 17:48:22 UTC 5,490 bytes, 174 lines download raw bytes

1
2// 获取URL GET参数
3function GetQueryString(name){
4    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
5    var r = window.location.search.substr(1).match(reg);
6    if(r!=null)return  unescape(r[2]); return null;
7}
8
9// 获取当前页面名称
10function strPage(){
11    
12    var strUrl = window.location.href;
13    var arrUrl = strUrl.split("/");
14    var strPage = arrUrl[arrUrl.length - 1];
15    
16    if (strPage.indexOf("?") > -1) {
17        var pageName = strPage.split("?");
18        strPage = pageName[0];
19    }
20    
21    return strPage;
22}
23
24// 根据屏幕分辨率
25function IsPhone(){
26	mobile_flag = false;
27	var screen_width = window.screen.width;
28	var screen_height = window.screen.height;
29	if(screen_width < 500 && screen_height < 820){
30		mobile_flag = true;
31	}
32	return mobile_flag;
33}
34
35// 根据操作系统
36function IsMobile() {
37    var isMobile = {
38        Android: function () {
39             return navigator.userAgent.match(/Android/i) ? true : false;
40        },
41        BlackBerry: function () {
42             return navigator.userAgent.match(/BlackBerry/i) ? true : false;
43        },
44        iOS: function () {
45             return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
46        },
47        Windows: function () {
48             return navigator.userAgent.match(/IEMobile/i) ? true : false;
49        },
50        any: function () {
51             return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
52        }
53     };
54     // 是移动设备
55     return isMobile.any(); 
56}
57
58// 将时间戳转换为人性化时间
59function AS_Time(timestamp) {
60    function zeroize(num) {
61        return (String(num).length == 1 ? '0': '') + num;
62    }
63    // 当前时间戳
64    let curTimestamp = parseInt(new Date().getTime() / 1000);
65    // 参数时间戳与当前时间戳相差秒数
66    let timestampDiff = curTimestamp - timestamp;
67    // 当前时间日期对象
68    let curDate = new Date(curTimestamp * 1000); 
69    // 参数时间戳转换成的日期对象
70    let tmDate = new Date(timestamp * 1000); 
71    let Y = tmDate.getFullYear(),
72    m = tmDate.getMonth() + 1,
73    d = tmDate.getDate();
74    let H = tmDate.getHours(),
75    i = tmDate.getMinutes(),
76    s = tmDate.getSeconds();
77
78    if (timestampDiff < 60) {
79        // 一分钟以内
80        return "刚刚";
81    } else if (timestampDiff < 3600) { 
82        // 一小时前之内
83        return Math.floor(timestampDiff / 60) + "分钟前";
84    } else if (curDate.getFullYear() == Y && curDate.getMonth() + 1 == m && curDate.getDate() == d) {
85        return '今天' + zeroize(H) + ':' + zeroize(i);
86    } else {
87        let newDate = new Date((curTimestamp - 86400) * 1000); 
88        // 参数中的时间戳加一天转换成的日期对象
89        if (newDate.getFullYear() == Y && newDate.getMonth() + 1 == m && newDate.getDate() == d) {
90            return '昨天' + zeroize(H) + ':' + zeroize(i);
91        } else if (curDate.getFullYear() == Y) {
92            return zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
93        } else {
94            return Y + '年' + zeroize(m) + '月' + zeroize(d) + '日 ' + zeroize(H) + ':' + zeroize(i);
95        }
96    }
97}
98
99// 响应耗时
100function AS_ResTime(){
101    
102    let ResTime = window.performance;
103    
104    function RAM(size) {
105        
106        return Math.floor(size / 1024 / 1024, 4) + 'MB';
107    };
108    
109    function consume(time) {
110        return time + 'ms';
111    };
112    
113    let data = {
114        'ram':RAM(ResTime.memory.usedJSHeapSize),
115        'tcp':consume(ResTime.timing.connectEnd - ResTime.timing.connectStart),
116        'res':consume(ResTime.timing.responseEnd - ResTime.timing.responseStart),
117    };
118    
119    // window.onload = function() {
120    //     console.log("dom渲染耗时:" + consume(ResTime.timing.domComplete - ResTime.timing.domLoading));
121    // };
122    
123    return data;
124}
125
126// 设置cookie
127function SetCookie(name, value) {
128    if (value) {
129        var Days = 365;
130        var exp = new Date();
131        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
132        document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString();
133    }
134}
135
136// 获取cookie
137function GetCookie(name) {
138    if (document.cookie.length > 0) {
139        var begin = document.cookie.indexOf(name + '=');
140        if (begin !== -1) {
141            // cookie值的初始位置
142            begin += name.length + 1;
143            // 结束位置
144            var end = document.cookie.indexOf(';', begin); 
145            if (end === -1) {
146                // 没有;则end为字符串结束位置
147                end = document.cookie.length; 
148            }
149            return unescape(document.cookie.substring(begin, end));
150        }
151    }
152    return null
153    // cookie不存在返回null
154}
155
156// 清除某个cookie
157function DelCookie(name) {
158    var exp = new Date();
159    exp.setTime(exp.getTime() - 1);
160    var cval = SetCookie(name);
161    if (cval && cval != null) {
162        document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString();
163    }
164}
165
166// 清除所有cookie
167function ClearCookie() {
168    var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
169    if (keys) {
170        for (var i = keys.length; i--;) {
171            document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString();
172        }
173    }
174}

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.