web-font/static/req.ts
2020-03-20 11:06:23 +08:00

36 lines
906 B
TypeScript

export const server='//'+location.host+location.pathname
export function get_font(font:string, text:string) {
return new Promise((rs, re) => {
var xhr = new XMLHttpRequest();
xhr.addEventListener('readystatechange', function() {
if (this.readyState === 4) {
rs(JSON.parse(this.responseText)[0]);
}
});
xhr.open(
'GET',
`${server}fontmin?font=${encodeURIComponent(
font,
)}&text=${encodeURIComponent(text)}`,
);
xhr.onerror=re
xhr.send();
})
}
export function get_font_list(font:string, text:string) {
return new Promise((rs, re) => {
var xhr = new XMLHttpRequest();
xhr.addEventListener('readystatechange', function() {
if (this.readyState === 4) {
rs(JSON.parse(this.responseText));
}
});
xhr.open(
'GET',
`${server}font_list`,
);
xhr.onerror=re
xhr.send();
})
}