utility.js
917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var blinkInterval;
var docTitle = document.title;
/**
* 检查是否支持 websocket
* @returns {boolean}
*/
exports.isSupport = function() {
return !!window.WebSocket;
};
/**
* 添加闪烁提醒
* @returns {boolean}
*/
exports.addBlinkAlert = function() {
if (blinkInterval) {
clearInterval(blinkInterval);
}
blinkInterval = setInterval(function() {
document.title = '您有新消息';
setTimeout(function() {
document.title = docTitle;
}, 300);
}, 600);
};
/**
* 去除闪烁提醒
* @returns {boolean}
*/
exports.removeBlinkAlert = function() {
if (blinkInterval) {
clearInterval(blinkInterval);
document.title = docTitle;
}
};
/**
* 链接自适应协议
* @author: lq <qi.li@yoho.cn>
* @date: 2017/04/06
*/
exports.autoProtocol = function(src) {
return (src || '').replace(/^(http:|https:)/, '');
};