mirror of
https://codeberg.org/vlw/stadia-avatar.git
synced 2025-09-13 23:23:40 +02:00
Separated client- and server-side features into seperate root folders. Since Stadia Avatar now has two versions (Userscript and Chrome extension). Added core extension functionality. Created a page constructor for extension popup. High probability that I will create a seperate repo for this feature, as it's pretty neat and very useful for future extensions.
33 lines
No EOL
984 B
JavaScript
33 lines
No EOL
984 B
JavaScript
import { AvatarURL } from "./popup_modules/ChangeAvatar.mjs";
|
|
|
|
// Localize by replacing __MSG_***__ strings in DOM
|
|
function localizePage() {
|
|
for (var i = 0; i < document.body.children.length; i++) {
|
|
const element = document.body.children[i];
|
|
|
|
let valStrH = element.innerHTML.toString();
|
|
const valNewH = valStrH.replace(/__MSG_(\w+)__/g, (match,key) => {
|
|
return key ? chrome.i18n.getMessage(key) : "";
|
|
});
|
|
|
|
if(valNewH != valStrH) {
|
|
element.innerHTML = valNewH;
|
|
}
|
|
}
|
|
}
|
|
|
|
function eventHandler(event) {
|
|
const target = event.target.closest("[button]");
|
|
switch(target.getAttribute("button")) {
|
|
case "avatar:url": new AvatarURL(); break;
|
|
}
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
// Bind click listeners to all button attributes
|
|
for(const button of document.querySelectorAll("[button]")) {
|
|
button.addEventListener("click",event => eventHandler(event));
|
|
}
|
|
});
|
|
|
|
localizePage(); |