-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathalert.js
More file actions
50 lines (42 loc) · 1.52 KB
/
alert.js
File metadata and controls
50 lines (42 loc) · 1.52 KB
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
49
50
// Alert rules page script
document.addEventListener('DOMContentLoaded', function() {
updateAlertRule();
// 初始化 Material UI 交互
if (typeof initMaterialUI === 'function') {
initMaterialUI();
}
});
function updateAlertRule() {
const type = document.getElementById('alertType').value;
const min = document.getElementById('alertMin').value;
const max = document.getElementById('alertMax').value;
const duration = document.getElementById('alertDuration').value;
const cover = document.getElementById('alertCover').checked ? 1 : 0;
const ignoreInput = document.getElementById('alertIgnore').value;
const ignore = {};
if (ignoreInput) {
ignoreInput.split(',').forEach(id => {
const t = id.trim();
if (t) ignore[t] = true;
});
}
const obj = { type };
if (min) obj.min = Number(min);
if (max) obj.max = Number(max);
obj.duration = Number(duration);
obj.cover = cover;
if (Object.keys(ignore).length) obj.ignore = ignore;
const json = JSON.stringify([obj], null, 2);
document.getElementById('alertJson').value = json;
// 更新输入框状态
document.querySelectorAll('.md-text-field input').forEach(input => {
if (input.value) input.parentElement.classList.add('has-value');
});
}
function copyAlertCode(event) {
if (event) event.stopPropagation();
const textarea = document.getElementById('alertJson');
textarea.select();
document.execCommand('copy');
showToast();
}