mirror of
https://github.com/koloml/furbooru-tagging-assistant.git
synced 2025-12-24 07:12:57 +00:00
Added AMD loader initialization as separate entry, autoload everything
This commit is contained in:
22
src/content/deps/amd.ts
Normal file
22
src/content/deps/amd.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { amdLite } from "amd-lite";
|
||||
|
||||
const originalDefine = amdLite.define;
|
||||
|
||||
amdLite.define = (name, dependencies, originalCallback) => {
|
||||
return originalDefine(name, dependencies, function () {
|
||||
const callbackResult = originalCallback(...arguments);
|
||||
|
||||
// Workaround for the entry script not returning anything causing AMD-Lite to send warning about modules not
|
||||
// being loaded/not existing.
|
||||
return typeof callbackResult !== 'undefined' ? callbackResult : {};
|
||||
})
|
||||
}
|
||||
|
||||
amdLite.init({
|
||||
publicScope: window
|
||||
});
|
||||
|
||||
// We don't have anything asynchronous, so it's safe to execute everything on the next frame.
|
||||
requestAnimationFrame(() => {
|
||||
amdLite.resolveDependencies(Object.keys(amdLite.waitingModules))
|
||||
});
|
||||
23
src/types/amd-lite.d.ts
vendored
Normal file
23
src/types/amd-lite.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Types for the small untyped AMD loader. These types do not cover all the functions available in the package, only
|
||||
// parts required for content scripts in extension to work.
|
||||
declare module 'amd-lite' {
|
||||
interface AMDLiteInitOptions {
|
||||
publicScope: any;
|
||||
verbosity: number;
|
||||
}
|
||||
|
||||
interface AMDLite {
|
||||
waitingModules: Record<string, any>;
|
||||
readyModules: Record<string, any>;
|
||||
|
||||
init(options: Partial<AMDLiteInitOptions>): void;
|
||||
|
||||
define(name: string, dependencies: string[], callback: function): void;
|
||||
|
||||
resolveDependency(dependencyPath: string);
|
||||
|
||||
resolveDependencies(dependencyNames: string[], from?: string);
|
||||
}
|
||||
|
||||
export const amdLite: AMDLite;
|
||||
}
|
||||
Reference in New Issue
Block a user