-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
56 lines (52 loc) · 2.21 KB
/
Copy pathutils.js
File metadata and controls
56 lines (52 loc) · 2.21 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
function escHtml(str) {
if (typeof document === 'undefined') {
return (str || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
}
const div = document.createElement('div');
div.textContent = str || '';
return div.innerHTML;
}
function timeAgo(dateStr) {
if (!dateStr) return '';
const seconds = Math.floor((Date.now() - new Date(dateStr).getTime()) / 1000);
if (seconds < 60) return 'just now';
const minutes = Math.floor(seconds / 60);
if (minutes < 60) return `${minutes}m ago`;
const hours = Math.floor(minutes / 60);
if (hours < 24) return `${hours}h ago`;
const days = Math.floor(hours / 24);
return `${days}d ago`;
}
async function getConfig() {
const data = await chrome.storage.local.get(['baseUrl', 'projectName']);
return {
baseUrl: (data.baseUrl || '').replace(/\/+$/, ''),
projectName: data.projectName || ''
};
}
function loadingDotsSVG(size) {
if (size === 'large') {
return `<svg width="56" height="16" viewBox="0 0 56 16" xmlns="http://www.w3.org/2000/svg">
<circle class="loading-dot loading-dot-1" cx="6" cy="8" r="6" fill="#0066B1"/>
<circle class="loading-dot loading-dot-2" cx="22" cy="8" r="6" fill="#522DAE"/>
<circle class="loading-dot loading-dot-3" cx="38" cy="8" r="6" fill="#F40000"/>
<circle class="loading-dot loading-dot-4" cx="54" cy="8" r="6" fill="currentColor" stroke="#9CA3AF"/>
</svg>`;
}
return `<svg width="28" height="8" viewBox="0 0 28 8" xmlns="http://www.w3.org/2000/svg">
<circle class="loading-dot loading-dot-1" cx="3" cy="4" r="3" fill="#0066B1"/>
<circle class="loading-dot loading-dot-2" cx="11" cy="4" r="3" fill="#522DAE"/>
<circle class="loading-dot loading-dot-3" cx="19" cy="4" r="3" fill="#F40000"/>
<circle class="loading-dot loading-dot-4" cx="27" cy="4" r="3" fill="currentColor" stroke="#9CA3AF"/>
</svg>`;
}
function showToast(message, type) {
type = type || 'info';
const container = document.getElementById('toast-container');
if (!container) return;
const toast = document.createElement('div');
toast.className = `toast toast-${type}`;
toast.textContent = message;
container.appendChild(toast);
setTimeout(() => toast.remove(), 4000);
}