fix i18n and lit initialize

This commit is contained in:
k1kimosha
2026-02-04 20:33:45 +03:00
parent 30ea3dfb48
commit f6efe421a9
3 changed files with 28 additions and 28 deletions

View File

@@ -1,14 +1,27 @@
const INJECT_ID = "__otm_button_script__"; const INJECT_ID = "__otm_button_script__";
import { t } from "../shared/i18n";
async function inject() { const contentScan = t("content.scan");
if (document.getElementById(INJECT_ID)) return;
const script = document.createElement("script"); const observer = new MutationObserver(() => {
script.id = INJECT_ID; if (!document.getElementById(INJECT_ID)) {
script.type = "module"; const script = document.createElement("script");
script.src = chrome.runtime.getURL("src/content/page.js"); script.id = INJECT_ID;
script.type = "module";
script.src = chrome.runtime.getURL("src/content/page.js");
document.documentElement.appendChild(script); document.documentElement.appendChild(script);
} } else {
inject(); const target = document.querySelector(".Layout-sc-1xcs6mc-0.foHQyB");
if (target && !document.getElementById("__otm_button__")) {
const el = document.createElement("twitch-button");
el.id = "__otm_button__";
el.setAttribute("contentscan", contentScan);
target.appendChild(el);
}
}
});
observer.observe(document.body, { childList: true, subtree: true });

View File

@@ -1,9 +1,9 @@
import { LitElement, html, css } from "lit"; import { LitElement, html, css } from "lit";
import { customElement } from "lit/decorators.js"; import { property } from "lit/decorators.js";
import { t } from "../shared/i18n";
@customElement("twitch-button")
class TwitchButton extends LitElement { class TwitchButton extends LitElement {
@property({type: String, attribute: "contentscan"}) contentScan = "";
static styles = css` static styles = css`
:host { :host {
display: flex; display: flex;
@@ -28,21 +28,9 @@ class TwitchButton extends LitElement {
render() { render() {
return html` return html`
<p>${t("content.scan")}</p> <p>${this.contentScan}</p>
`; `;
} }
} }
customElements.define("twitch-button", TwitchButton); customElements.define("twitch-button", TwitchButton);
const observer = new MutationObserver(() => {
const target = document.querySelector(".Layout-sc-1xcs6mc-0.foHQyB");
const button = document.getElementById("__otm_button__");
if (target && !button) {
const el = document.createElement("twitch-button");
el.id = "__otm_button__";
target.appendChild(el);
}
});
observer.observe(document.body, { childList: true, subtree: true });

View File

@@ -1,9 +1,8 @@
import { LitElement, html, css } from "lit"; import { LitElement, html, css } from "lit";
import { customElement, state } from "lit/decorators.js"; import { state } from "lit/decorators.js";
import Browser from "webextension-polyfill"; import Browser from "webextension-polyfill";
import { t } from "../shared/i18n"; import { t } from "../shared/i18n";
@customElement("popup-app")
class PopupApp extends LitElement { class PopupApp extends LitElement {
@state() @state()
private isTwitch = false; private isTwitch = false;