send automatically

This commit is contained in:
Jörn-Michael Miehe 2023-12-28 21:40:08 +00:00
parent eb97f4b5f0
commit e7bd55a0b2

View file

@ -1,4 +1,4 @@
const emote_regex = /bttv:([^\s]+)/g; const emote_regex = /bttv:([^\s]+)/gi;
type Emote = { type Emote = {
code: string; code: string;
@ -74,6 +74,11 @@ async function process_text(text: string): Promise<string> {
const cb_form = document.querySelector("#mgc_cb_evo_form"); const cb_form = document.querySelector("#mgc_cb_evo_form");
if (!(cb_form instanceof HTMLFormElement)) return; if (!(cb_form instanceof HTMLFormElement)) return;
const cb_send = document.querySelector(
"#mgc_cb_evo_form > input[type=image]:nth-child(2)",
);
if (!(cb_send instanceof HTMLInputElement)) return;
const bttv_btn = (() => { const bttv_btn = (() => {
const btn = document.createElement("a"); const btn = document.createElement("a");
btn.style.setProperty("cursor", "pointer"); btn.style.setProperty("cursor", "pointer");
@ -81,24 +86,24 @@ async function process_text(text: string): Promise<string> {
const img = document.createElement("img"); const img = document.createElement("img");
img.setAttribute("src", chrome.runtime.getURL("img/sb_button.png")); img.setAttribute("src", chrome.runtime.getURL("img/sb_button.png"));
img.setAttribute("alt", "bttv emotes ersetzen und absenden");
img.setAttribute("title", "bttv:* emotes ersetzen und absenden");
img.style.setProperty("vertical-align", "middle"); img.style.setProperty("vertical-align", "middle");
btn.addEventListener("click", async (event) => { btn.addEventListener("click", async () => {
const cb_input = document.querySelector("#mgc_cb_evo_input"); const cb_input = document.querySelector("#mgc_cb_evo_input");
if (!(cb_input instanceof HTMLInputElement)) return; if (!(cb_input instanceof HTMLInputElement)) return;
cb_input.value = await process_text(cb_input.value); cb_input.value = await process_text(cb_input.value);
cb_input.focus(); cb_input.focus();
cb_send.click();
}); });
btn.appendChild(img); btn.appendChild(img);
return btn; return btn;
})(); })();
cb_form.insertBefore( cb_form.insertBefore(bttv_btn, cb_send);
bttv_btn,
document.querySelector("#mgc_cb_evo_form > input[type=image]:nth-child(2)"),
);
console.log("done."); console.log("done.");
})(); })();