musescore-downloader/src/gm.ts

23 lines
790 B
TypeScript
Raw Normal View History

/**
* UserScript APIs
*/
declare const GM: {
2020-12-06 06:28:56 +00:00
/** https://www.tampermonkey.net/documentation.php#GM_info */
info: Record<string, any>;
/** https://www.tampermonkey.net/documentation.php#GM_registerMenuCommand */
registerMenuCommand (name: string, fn: () => any, accessKey?: string): Promise<number>;
/** https://github.com/Tampermonkey/tampermonkey/issues/881#issuecomment-639705679 */
addElement<K extends keyof HTMLElementTagNameMap> (tagName: K, properties: Record<string, any>): Promise<HTMLElementTagNameMap[K]>;
}
2020-12-06 17:32:13 +00:00
export const _GM = (typeof GM === 'object' ? GM : undefined) as GM
type GM = typeof GM
2020-12-06 06:28:56 +00:00
export const isGmAvailable = (requiredMethod: keyof GM = 'info'): boolean => {
return typeof GM !== 'undefined' &&
2020-12-06 06:28:56 +00:00
typeof GM[requiredMethod] !== 'undefined'
}