-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
105 lines (88 loc) · 3.31 KB
/
Copy pathutils.js
File metadata and controls
105 lines (88 loc) · 3.31 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function extractTextFromHtml(htmlString) {
const tempDiv = document.createElement('div');
tempDiv.innerHTML = htmlString;
return tempDiv.textContent || tempDiv.innerText || '';
}
function debounce(func, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}
function convertToLocalTime(dateString) {
// 将日期字符串解析为 Date 对象
const date = new Date(dateString);
// 转换为系统当前时区的可读时间
const localTime = date.toLocaleString(); // 默认格式,包含日期和时间
const localDate = date.toLocaleDateString(); // 仅日期
const localTimeOnly = date.toLocaleTimeString(); // 仅时间
return {
localTime, // 完整的本地时间
localDate, // 本地日期
localTimeOnly // 本地时间
};
}
/**
* 切换暗黑模式。
*
* 此函数用于在页面中切换暗黑模式。它会检查包含 '.container' 类的元素是否已应用 'dark-mode' 类。
* 如果已应用,则移除该类并重置滤镜效果;如果未应用,则添加该类并应用滤镜效果以实现暗黑模式。
*
* @function toggleDarkMode
* @returns {void}
*/
function toggleDarkMode() {
// 获取.container元素
const container = document.querySelector('body');
// 检查.container是否包含'dark-mode'类
if (container.classList.contains('dark-mode')) {
container.classList.remove('dark-mode');
} else {
container.classList.add('dark-mode');
}
applyDarkMode();
}
function applyDarkMode() {
// 获取.container元素
const container = document.querySelector('body');
if (container.classList.contains('dark-mode')) {
container.style.filter = 'invert(0.9) hue-rotate(180deg)'; // 或者使用其他您喜欢的颜色变换效果
const images = container.querySelectorAll('img');
images.forEach(img => img.style.filter = 'invert(1) hue-rotate(180deg)');
} else {
container.style.filter = 'none'; // 或者 'hue-rotate(0deg)'
const images = container.querySelectorAll('img');
images.forEach(img => img.style.filter = 'none');
}
}
function showCenteredConfirm(message, onConfirm, onCancel) {
const confirmContainer = document.createElement('div');
confirmContainer.className = 'confirm-dialog';
const messageElement = document.createElement('p');
messageElement.className = 'confirm-message';
messageElement.textContent = message;
const buttonContainer = document.createElement('div');
buttonContainer.className = 'confirm-button-container';
const confirmButton = document.createElement('button');
confirmButton.className = 'confirm-button';
confirmButton.textContent = '确认';
const cancelButton = document.createElement('button');
cancelButton.className = 'cancel-button';
cancelButton.textContent = '取消';
confirmButton.addEventListener('click', () => {
document.body.removeChild(confirmContainer);
if (onConfirm) onConfirm();
});
cancelButton.addEventListener('click', () => {
document.body.removeChild(confirmContainer);
if (onCancel) onCancel();
});
buttonContainer.appendChild(confirmButton);
buttonContainer.appendChild(cancelButton);
confirmContainer.appendChild(messageElement);
confirmContainer.appendChild(buttonContainer);
document.body.appendChild(confirmContainer);
}