Files
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

34 lines
960 B
TypeScript

export interface ITunesResult {
artworkUrl100: string;
trackName: string;
wrapperType?: string;
kind?: string;
[key: string]: unknown;
}
export interface ITunesResponse {
resultCount: number;
results: ITunesResult[];
}
/**
* Type-safe JSONP callback registration via Object.defineProperty,
* avoiding `(window as any)` while still setting a global callback
* that JSONP script tags can invoke.
*/
export function setJsonpCallback<T = unknown>(name: string, fn: (data: T) => void): void {
Object.defineProperty(window, name, { value: fn, configurable: true, writable: true });
}
export function removeJsonpCallback(name: string): void {
const noop = () => {
Reflect.deleteProperty(window, name);
};
Object.defineProperty(window, name, { value: noop, configurable: true, writable: true });
window.setTimeout(() => {
if (Reflect.get(window, name) === noop) {
Reflect.deleteProperty(window, name);
}
}, 30000);
}