forked from Zie619/n8n-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
209 lines (189 loc) · 6.42 KB
/
Copy pathapp.js
File metadata and controls
209 lines (189 loc) · 6.42 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* Main application script for N8N Workflow Collection
* Handles additional UI interactions and utilities
*/
class WorkflowApp {
constructor() {
this.init();
}
init() {
this.setupThemeToggle();
this.setupKeyboardShortcuts();
this.setupAnalytics();
this.setupServiceWorker();
}
setupThemeToggle() {
// Add theme toggle functionality if needed
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (prefersDark) {
document.documentElement.classList.add('dark-theme');
}
}
setupKeyboardShortcuts() {
document.addEventListener('keydown', (e) => {
// Focus search on '/' key
if (e.key === '/' && !e.ctrlKey && !e.metaKey && !e.altKey) {
e.preventDefault();
const searchInput = document.getElementById('search-input');
if (searchInput) {
searchInput.focus();
}
}
// Clear search on 'Escape' key
if (e.key === 'Escape') {
const searchInput = document.getElementById('search-input');
if (searchInput && searchInput.value) {
searchInput.value = '';
searchInput.dispatchEvent(new Event('input'));
}
}
});
}
setupAnalytics() {
// Basic analytics for tracking popular workflows
this.trackEvent = (category, action, label) => {
// Could integrate with Google Analytics or other tracking
console.debug('Analytics:', { category, action, label });
};
// Track search queries
const searchInput = document.getElementById('search-input');
if (searchInput) {
searchInput.addEventListener('input', this.debounce((e) => {
if (e.target.value.length > 2) {
this.trackEvent('Search', 'query', e.target.value);
}
}, 1000));
}
// Track workflow downloads
document.addEventListener('click', (e) => {
if (e.target.matches('a[href*=".json"]')) {
const filename = e.target.href.split('/').pop();
this.trackEvent('Download', 'workflow', filename);
}
});
}
setupServiceWorker() {
// Register service worker for offline functionality (if needed)
if ('serviceWorker' in navigator) {
// Uncomment when service worker is implemented
// navigator.serviceWorker.register('/service-worker.js');
}
}
debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
}
// Utility functions for the application
window.WorkflowUtils = {
/**
* Format numbers with appropriate suffixes
*/
formatNumber(num) {
if (num >= 1000000) {
return (num / 1000000).toFixed(1) + 'M';
}
if (num >= 1000) {
return (num / 1000).toFixed(1) + 'K';
}
return num.toString();
},
/**
* Debounce function for search input
*/
debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
},
/**
* Copy text to clipboard
*/
async copyToClipboard(text) {
try {
await navigator.clipboard.writeText(text);
return true;
} catch (err) {
// Fallback for older browsers
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
const success = document.execCommand('copy');
document.body.removeChild(textArea);
return success;
}
},
/**
* Show temporary notification
*/
showNotification(message, type = 'info', duration = 3000) {
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: ${type === 'success' ? '#48bb78' : type === 'error' ? '#f56565' : '#4299e1'};
color: white;
padding: 1rem 1.5rem;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 1000;
opacity: 0;
transform: translateX(100%);
transition: all 0.3s ease;
`;
notification.textContent = message;
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.style.opacity = '1';
notification.style.transform = 'translateX(0)';
}, 10);
// Animate out and remove
setTimeout(() => {
notification.style.opacity = '0';
notification.style.transform = 'translateX(100%)';
setTimeout(() => {
if (notification.parentNode) {
document.body.removeChild(notification);
}
}, 300);
}, duration);
}
};
// Initialize app when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
new WorkflowApp();
// Add helpful hints
const searchInput = document.getElementById('search-input');
if (searchInput) {
searchInput.setAttribute('title', 'Press / to focus search, Escape to clear');
}
});
// Handle page visibility changes
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
// Refresh data if page has been hidden for more than 5 minutes
const lastRefresh = localStorage.getItem('lastRefresh');
const now = Date.now();
if (!lastRefresh || now - parseInt(lastRefresh) > 5 * 60 * 1000) {
// Could refresh search index here if needed
localStorage.setItem('lastRefresh', now.toString());
}
}
});