|
|
|
|
|
|
|
|
|
|
|
function initApiKeyManager() {
|
|
|
|
const platforms = JSON.parse(platformsData);
|
|
|
|
|
|
this.platformIds = platforms.map(platform => platform.id);
|
|
|
|
|
|
const savedView = localStorage.getItem('keyView');
|
|
if (savedView === 'valid' || savedView === 'invalid') {
|
|
this.currentView = savedView;
|
|
}
|
|
|
|
|
|
const stateKey = `platformStates_${this.currentView}`;
|
|
const savedPlatformStates = localStorage.getItem(stateKey);
|
|
const parsedPlatformStates = savedPlatformStates ? JSON.parse(savedPlatformStates) : {};
|
|
|
|
|
|
const savedPlatformFilters = localStorage.getItem('platformFilters');
|
|
const parsedPlatformFilters = savedPlatformFilters ? JSON.parse(savedPlatformFilters) : {};
|
|
|
|
|
|
|
|
platforms.forEach(platform => {
|
|
this.platformStates[platform.id] = parsedPlatformStates[platform.id] !== undefined
|
|
? parsedPlatformStates[platform.id]
|
|
: true;
|
|
|
|
this.platformFilters[platform.id] = parsedPlatformFilters[platform.id] !== undefined
|
|
? parsedPlatformFilters[platform.id]
|
|
: true;
|
|
});
|
|
|
|
|
|
this.allPlatformsSelected = platforms.every(platform =>
|
|
this.platformFilters[platform.id] === true
|
|
);
|
|
|
|
|
|
this.loadApiKeys();
|
|
|
|
|
|
new ClipboardJS('[data-clipboard-text]');
|
|
|
|
|
|
const lastPlatform = localStorage.getItem('lastSelectedPlatform');
|
|
if (lastPlatform) {
|
|
this.newKey.platform = lastPlatform;
|
|
}
|
|
|
|
|
|
|
|
|
|
window.addEventListener('open-add-modal', () => {
|
|
this.showAddModal = true;
|
|
|
|
setTimeout(() => {
|
|
document.getElementById('platform').focus();
|
|
}, 100);
|
|
});
|
|
|
|
|
|
document.addEventListener('keydown', (e) => {
|
|
|
|
if (e.altKey && e.key === 'Enter') {
|
|
if (this.showAddModal) {
|
|
e.preventDefault();
|
|
this.addApiKey();
|
|
} else if (this.showEditModal) {
|
|
e.preventDefault();
|
|
this.updateApiKey();
|
|
}
|
|
}
|
|
|
|
|
|
if (e.key === 'Escape') {
|
|
if (this.showAddModal) {
|
|
this.showAddModal = false;
|
|
} else if (this.showEditModal) {
|
|
this.showEditModal = false;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|