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.
40 lines
1.0 KiB
40 lines
1.0 KiB
function getBaseUrl() {
|
|
var ishttps = 'https:' == document.location.protocol ? true : false;
|
|
var url = window.location.host;
|
|
if (ishttps) {
|
|
url = 'https://' + url;
|
|
} else {
|
|
url = 'http://' + url;
|
|
}
|
|
return url;
|
|
}
|
|
function getWsBaseUrl() {
|
|
var ishttps = 'https:' == document.location.protocol ? true : false;
|
|
var url = window.location.host;
|
|
if (ishttps) {
|
|
url = 'wss://' + url;
|
|
} else {
|
|
url = 'ws://' + url;
|
|
}
|
|
return url;
|
|
}
|
|
function notify(title, options, callback) {
|
|
// 先检查浏览器是否支持
|
|
if (!window.Notification) {
|
|
return;
|
|
}
|
|
var notification;
|
|
// 检查用户曾经是否同意接受通知
|
|
if (Notification.permission === 'granted') {
|
|
notification = new Notification(title, options); // 显示通知
|
|
|
|
} else {
|
|
var promise = Notification.requestPermission();
|
|
}
|
|
|
|
if (notification && callback) {
|
|
notification.onclick = function(event) {
|
|
callback(notification, event);
|
|
}
|
|
}
|
|
} |