stadia-avatar/client/extension/assets/js/popup.js
Victor Westerlund 74b2635755 New folder structure for extension
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.
2021-02-08 04:50:47 +01:00

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();