mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-07 03:22:17 -08:00
feat: add AniList character dictionary sync
This commit is contained in:
@@ -720,6 +720,24 @@ export class DictionaryController {
|
||||
modal.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} dictionaryTitle
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async deleteDictionaryNow(dictionaryTitle) {
|
||||
const dictionaries = await this._settingsController.getDictionaryInfo();
|
||||
if (!dictionaries.some((dictionary) => dictionary.title === dictionaryTitle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this._deleteDictionary(dictionaryTitle);
|
||||
|
||||
const remaining = await this._settingsController.getDictionaryInfo();
|
||||
if (remaining.some((dictionary) => dictionary.title === dictionaryTitle)) {
|
||||
throw new Error(`Dictionary still present after delete: ${dictionaryTitle}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} dictionaryTitle
|
||||
* @returns {Promise<string[]>}
|
||||
|
||||
@@ -452,6 +452,25 @@ export class DictionaryImportController {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} archiveContent
|
||||
* @param {string} fileName
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async importDictionaryArchiveContent(archiveContent, fileName='dictionary.zip') {
|
||||
const file = new File([archiveContent], fileName, {type: 'application/zip'});
|
||||
const importProgressTracker = new ImportProgressTracker(this._getFileImportSteps(), 1);
|
||||
const errors = await this._importDictionaries(
|
||||
this._arrayToAsyncGenerator([file]),
|
||||
null,
|
||||
null,
|
||||
importProgressTracker,
|
||||
);
|
||||
if (errors.length > 0) {
|
||||
throw errors[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string[]} urls
|
||||
* @param {import('dictionary-worker').ImportProgressCallback} onProgress
|
||||
@@ -532,9 +551,10 @@ export class DictionaryImportController {
|
||||
* @param {import('settings-controller').ProfilesDictionarySettings} profilesDictionarySettings
|
||||
* @param {import('settings-controller').ImportDictionaryDoneCallback} onImportDone
|
||||
* @param {ImportProgressTracker} importProgressTracker
|
||||
* @returns {Promise<Error[]>}
|
||||
*/
|
||||
async _importDictionaries(dictionaries, profilesDictionarySettings, onImportDone, importProgressTracker) {
|
||||
if (this._modifying) { return; }
|
||||
if (this._modifying) { return [new Error('Dictionary import already in progress.')]; }
|
||||
|
||||
const statusFooter = this._statusFooter;
|
||||
const progressSelector = '.dictionary-import-progress';
|
||||
@@ -588,6 +608,7 @@ export class DictionaryImportController {
|
||||
this._triggerStorageChanged();
|
||||
if (onImportDone) { onImportDone(); }
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -113,6 +113,21 @@ await Application.main(true, async (application) => {
|
||||
const dictionaryImportController = new DictionaryImportController(settingsController, modalController, statusFooter);
|
||||
dictionaryImportController.prepare();
|
||||
|
||||
globalThis.__subminerYomitanSettingsAutomation = {
|
||||
ready: false,
|
||||
importDictionaryArchiveBase64: async (archiveBase64, fileName='dictionary.zip') => {
|
||||
const binary = atob(archiveBase64);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let i = 0; i < binary.length; ++i) {
|
||||
bytes[i] = binary.charCodeAt(i);
|
||||
}
|
||||
await dictionaryImportController.importDictionaryArchiveContent(bytes.buffer, fileName);
|
||||
},
|
||||
deleteDictionary: async (dictionaryTitle) => {
|
||||
await dictionaryController.deleteDictionaryNow(dictionaryTitle);
|
||||
},
|
||||
};
|
||||
|
||||
const genericSettingController = new GenericSettingController(settingsController);
|
||||
preparePromises.push(setupGenericSettingController(genericSettingController));
|
||||
|
||||
@@ -184,5 +199,6 @@ await Application.main(true, async (application) => {
|
||||
|
||||
await Promise.all(preparePromises);
|
||||
|
||||
globalThis.__subminerYomitanSettingsAutomation.ready = true;
|
||||
document.documentElement.dataset.loaded = 'true';
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user