feat(scripts): apply translations
This commit is contained in:
parent
2e589f2adc
commit
5bb09feebd
@ -94,8 +94,10 @@ const handleRate = (event) => {
|
||||
*/
|
||||
|
||||
const handleContentLoaded = () => {
|
||||
dispatch({ type: "GET_TAB" }, null, ({ hostname, id }) => {
|
||||
dispatch({ type: "GET_TAB" }, null, ({ hostname }) => {
|
||||
dispatch({ hostname, type: "GET_CACHE" }, null, ({ enabled }) => {
|
||||
translate();
|
||||
|
||||
const host = document.getElementById("host");
|
||||
const like = document.getElementById("like");
|
||||
const power = document.getElementById("power");
|
||||
@ -108,12 +110,27 @@ const handleContentLoaded = () => {
|
||||
reload.addEventListener("click", handleReload);
|
||||
store.setAttribute("href", isChromium ? chromeUrl : firefoxUrl);
|
||||
unlike.addEventListener("click", handleRate);
|
||||
if (location) host.innerText = hostname.replace("www.", "");
|
||||
if (location) host.innerText = hostname.replace("www.", " ");
|
||||
if (!enabled) power.removeAttribute("checked");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Applies translations to tags with i18n data attribute
|
||||
*/
|
||||
|
||||
const translate = () => {
|
||||
const nodes = document.querySelectorAll("[data-i18n]");
|
||||
|
||||
for (let i = nodes.length; i--; ) {
|
||||
const node = nodes[i];
|
||||
const { i18n } = node.dataset;
|
||||
|
||||
node.innerHTML = chrome.i18n.getMessage(i18n);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Listen to document ready
|
||||
* @listens document#ready
|
||||
|
Loading…
Reference in New Issue
Block a user