Refactor kantine.js into modular ES6 structure
Moved `kantine.js` into a `src/` directory with multiple modularized files: - `api.js`: All API calls and constants - `state.js`: State management (auth, cache, theme, tags, etc.) - `utils.js`: Helpers for UI and Date formatting - `ui.js`: DOM manipulation logic - `events.js`: Initial DOM event listeners and logic hooks - `actions.js`: Data fetching actions, local processing logic - `ui_helpers.js`: UI helper functions (rendering modals, handling DOM injections) Updated the `build-bookmarklet.sh` to compile with Webpack via newly created `webpack.config.js`. Updated all relevant test scripts to use the new output `dist/kantine.bundle.js` and modified logic to work within Webpack scopes. Co-authored-by: TauNeutrino <1600410+TauNeutrino@users.noreply.github.com>
This commit is contained in:
38
src/index.js
Normal file
38
src/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { injectUI } from './ui.js';
|
||||
import { bindEvents } from './events.js';
|
||||
import { updateAuthUI, cleanupExpiredFlags, loadMenuCache, isCacheFresh, loadMenuDataFromAPI, startPolling } from './actions.js';
|
||||
import { checkForUpdates } from './ui_helpers.js';
|
||||
import { authToken } from './state.js';
|
||||
|
||||
if (window.__KANTINE_LOADED) {
|
||||
console.log("Kantine Wrapper already loaded.");
|
||||
} else {
|
||||
window.__KANTINE_LOADED = true;
|
||||
|
||||
injectUI();
|
||||
bindEvents();
|
||||
updateAuthUI();
|
||||
cleanupExpiredFlags();
|
||||
|
||||
const hadCache = loadMenuCache();
|
||||
if (hadCache) {
|
||||
document.getElementById('loading').classList.add('hidden');
|
||||
if (!isCacheFresh()) {
|
||||
console.log('Cache stale or incomplete – refreshing from API');
|
||||
loadMenuDataFromAPI();
|
||||
} else {
|
||||
console.log('Cache fresh & complete – skipping API refresh');
|
||||
}
|
||||
} else {
|
||||
loadMenuDataFromAPI();
|
||||
}
|
||||
|
||||
if (authToken) {
|
||||
startPolling();
|
||||
}
|
||||
|
||||
checkForUpdates();
|
||||
setInterval(checkForUpdates, 60 * 60 * 1000);
|
||||
|
||||
console.log('Kantine Wrapper loaded ✅');
|
||||
}
|
||||
Reference in New Issue
Block a user