anki/ts/lib/bridgecommand.ts

24 lines
712 B
TypeScript
Raw Normal View History

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { registerPackage } from "./register-package";
2021-01-26 01:25:22 +01:00
declare global {
interface Window {
bridgeCommand<T>(command: string, callback?: (value: T) => void): void;
}
}
/// HTML <a> tag pointing to a bridge command.
export function bridgeLink(command: string, label: string): string {
return `<a href="javascript:bridgeCommand('${command}')">${label}</a>`;
}
2021-01-26 01:25:22 +01:00
export function bridgeCommand<T>(command: string, callback?: (value: T) => void): void {
window.bridgeCommand<T>(command, callback);
}
registerPackage("anki/bridgecommand", {
bridgeCommand,
});