Compare commits

..

No commits in common. "9eb0976b355a2b7a1558da57dd086dfc801cbf0d" and "87f2833a3a8fac2a84d4c5512953e6325e135a9d" have entirely different histories.

View file

@ -2,33 +2,13 @@ const emote_regex = /bttv:([^\s]+)/g;
type Emote = {
code: string;
url?: string;
};
type BTTV_Emote = {
id: string;
code: string;
imageType: string;
animated: boolean;
user: any;
url: string;
};
async function bttv_get_url(code: string): Promise<Emote> {
const res = await fetch(
`https://api.betterttv.net/3/emotes/shared/search?query=${code}&offset=0&limit=50`,
);
const content = await res.json();
if (!Array.isArray(content)) return { code: code };
const matches = (content as BTTV_Emote[]).filter(
(be) => be.code.toLowerCase() == code.toLowerCase(),
);
if (matches.length <= 0) return { code: code };
return {
code: code,
url: `https://cdn.betterttv.net/emote/${matches[0].id}/1x.${matches[0].imageType}`,
url: `result_${code}`,
};
}
@ -39,12 +19,11 @@ async function get_emotes(codes: Iterable<string>): Promise<EmoteMap> {
// queue emote jobs
const queue = [...codes_set].map((code) => bttv_get_url(code));
console.log("[lmlfc-bttv] queueing", queue.length, "jobs");
// run
const result: EmoteMap = {};
for (const job of await Promise.all(queue)) {
if (job.url) result[job.code] = job.url;
result[job.code] = job.url;
}
return result;
@ -57,16 +36,14 @@ async function process_text(text: string): Promise<string> {
for (const emote of matches.reverse()) {
const [match, code] = emote;
const index = emote.index ?? 0;
if (!(code in emotes)) continue;
text =
text.substring(0, index) +
`[not]${emotes[code]}[/not]` +
emotes[code] +
text.substring(index + match.length);
}
text = text.replace(/\[\/not\]\s+\[not\]/g, "[/not][not]");
console.log(text);
return text;
}
@ -87,8 +64,10 @@ async function process_text(text: string): Promise<string> {
const cb_input = document.querySelector("#mgc_cb_evo_input");
if (!(cb_input instanceof HTMLInputElement)) return;
cb_input.value = await process_text(cb_input.value);
cb_input.focus();
await process_text("bttv:foo bttv:bar bttv:foo");
// await process_text(cb_input.value);
// cb_input.focus();
});
btn.appendChild(img);