forked from TheRealDuckers/hacktab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins.js
More file actions
48 lines (40 loc) · 1.53 KB
/
plugins.js
File metadata and controls
48 lines (40 loc) · 1.53 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
// plugins.js
// This file ensures Hackatime and GitHub integrations work consistently
// by exposing refresh functions globally and wiring them to settings changes.
(function () {
// Expose refresh functions from app.js to global scope if not already
if (typeof window.refreshHackatime !== 'function') {
window.refreshHackatime = function (username, apiKey) {
console.warn('refreshHackatime not defined yet. Did you load app.js first?');
};
}
if (typeof window.refreshGithub !== 'function') {
window.refreshGithub = function (username) {
console.warn('refreshGithub not defined yet. Did you load app.js first?');
};
}
// Helper: load settings from localStorage
function getSettings() {
return JSON.parse(localStorage.getItem('settings')) || {};
}
// Helper: apply integrations immediately when settings change
function applyIntegrations() {
const s = getSettings();
if (s.hackatimeUsername && s.hackatimeKey && typeof window.refreshHackatime === 'function') {
window.refreshHackatime(s.hackatimeUsername, s.hackatimeKey);
}
if (s.githubUsername && typeof window.refreshGithub === 'function') {
window.refreshGithub(s.githubUsername);
}
}
// Run integrations once DOM is ready
document.addEventListener('DOMContentLoaded', () => {
applyIntegrations();
// Listen for storage changes (e.g. when settings.js saves new values)
window.addEventListener('storage', (e) => {
if (e.key === 'settings') {
applyIntegrations();
}
});
});
})();