Compare commits
No commits in common. "49adf851b1358573d3ceb80114f055c826692cff" and "ffb5a3b4972da89844ab171631464c0084154a13" have entirely different histories.
49adf851b1
...
ffb5a3b497
5 changed files with 29 additions and 19 deletions
|
@ -1,6 +1,5 @@
|
||||||
# lmlfc-bttv
|
# lmlfc-bttv
|
||||||
|
|
||||||
- install deps: `yarn`
|
- install deps `yarn install --production=false`
|
||||||
- more verbose but same: `yarn install --production=false`
|
- make "dist" dir: `yarn build`
|
||||||
- compile extension (into "dist" dir): `yarn build`
|
- pack "dist" dir: `yarn build-ext`
|
||||||
- pack "dist" dir (runs web-ext): `yarn build-ext`
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
"author": "Jörn-Michael Miehe <joern-michael.miehe@lenaisten.de>",
|
"author": "Jörn-Michael Miehe <joern-michael.miehe@lenaisten.de>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build-debug": "webpack --mode=development",
|
"build": "webpack --mode=development",
|
||||||
"build": "webpack --mode=production",
|
"build-release": "webpack --mode=production",
|
||||||
"lint-ext": "web-ext lint --source-dir=dist",
|
"lint-ext": "web-ext lint --source-dir=dist",
|
||||||
"build-ext": "web-ext build --source-dir=dist --artifacts-dir=dist --overwrite-dest"
|
"build-ext": "web-ext build --source-dir=dist --artifacts-dir=dist --overwrite-dest"
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,9 +13,12 @@ type BTTV_Emote = {
|
||||||
* Query BTTV API for an emote graphic
|
* Query BTTV API for an emote graphic
|
||||||
*
|
*
|
||||||
* @param code string associated with the emote graphic (often called "emote" itself)
|
* @param code string associated with the emote graphic (often called "emote" itself)
|
||||||
* @returns `null` iff no emote found or error, else URL to a BTTV emote graphic
|
* @returns `null` iff no emote found or error,
|
||||||
|
* else `[code, url]` tuple where `url` is the URL to a BTTV emote graphic
|
||||||
*/
|
*/
|
||||||
export async function bttv_get_url(code: string): Promise<string | null> {
|
export async function bttv_get_url(
|
||||||
|
code: string,
|
||||||
|
): Promise<[string, string] | null> {
|
||||||
// search for emotes
|
// search for emotes
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`https://api.betterttv.net/3/emotes/shared/search?query=${code}&offset=0&limit=50`,
|
`https://api.betterttv.net/3/emotes/shared/search?query=${code}&offset=0&limit=50`,
|
||||||
|
@ -34,5 +37,8 @@ export async function bttv_get_url(code: string): Promise<string | null> {
|
||||||
if (matches.length <= 0) return null;
|
if (matches.length <= 0) return null;
|
||||||
|
|
||||||
// return first emote's URL
|
// return first emote's URL
|
||||||
return `//cdn.betterttv.net/emote/${matches[0].id}/1x.${matches[0].imageType}`;
|
return [
|
||||||
|
code,
|
||||||
|
`//cdn.betterttv.net/emote/${matches[0].id}/1x.${matches[0].imageType}`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Async function mapping some `input` to an `[input, output]` tuple or a `null` if no output exists
|
||||||
|
*/
|
||||||
|
type MapFunction<In, Out> = (input: In) => Promise<[In, Out] | null>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Concurrently create some mapping of input to output elements.
|
* Concurrently create some mapping of input to output elements.
|
||||||
*
|
*
|
||||||
|
@ -7,13 +12,13 @@
|
||||||
*/
|
*/
|
||||||
export async function map_concurrent<In, Out>(
|
export async function map_concurrent<In, Out>(
|
||||||
inputs: Iterable<In>,
|
inputs: Iterable<In>,
|
||||||
map_fn: (input: In) => Promise<Out | null>,
|
map_fn: MapFunction<In, Out>,
|
||||||
): Promise<Map<In, Out | null>> {
|
): Promise<Map<In, Out>> {
|
||||||
// apply map_fn to inputs
|
// apply map_fn to inputs
|
||||||
const outputs = await Promise.all([...inputs].map((input) => map_fn(input)));
|
const queue = [...inputs].map((input) => map_fn(input));
|
||||||
|
|
||||||
// create map object
|
// wait for calls to finish
|
||||||
return new Map<In, Out | null>(
|
return new Map<In, Out>(
|
||||||
[...inputs].map((input, index) => [input, outputs[index]]),
|
(await Promise.all(queue)).filter((job): job is [In, Out] => job !== null),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,13 @@ async function process_text(text: string): Promise<string> {
|
||||||
for (const emote of matches.reverse()) {
|
for (const emote of matches.reverse()) {
|
||||||
const [match, code] = emote;
|
const [match, code] = emote;
|
||||||
|
|
||||||
// ensure emote exists
|
if (!emotes.has(code)) continue;
|
||||||
|
// emote exists
|
||||||
const url = emotes.get(code);
|
const url = emotes.get(code);
|
||||||
if (url == null) continue;
|
|
||||||
|
|
||||||
// ensure position in input string is known
|
if (emote.index == undefined) continue;
|
||||||
|
// position in input string is known
|
||||||
const index = emote.index;
|
const index = emote.index;
|
||||||
if (index == undefined) continue;
|
|
||||||
|
|
||||||
text =
|
text =
|
||||||
text.substring(0, index) +
|
text.substring(0, index) +
|
||||||
|
|
Loading…
Reference in a new issue