Move some options page funcs to shared lib

This commit is contained in:
Ajay
2023-05-09 16:49:54 -04:00
parent b35bcae213
commit e094f95602
8 changed files with 14 additions and 37 deletions

View File

@@ -93,27 +93,4 @@ export function getExistingChapters(currentVideoID: VideoID, duration: number):
}
return chapters;
}
export function localizeHtmlPage(): void {
//Localize by replacing __MSG_***__ meta tags
const localizedTitle = getLocalizedMessage(document.title);
if (localizedTitle) document.title = localizedTitle;
const body = document.querySelector(".sponsorBlockPageBody");
const localizedMessage = getLocalizedMessage(body.innerHTML.toString());
if (localizedMessage) body.innerHTML = localizedMessage;
}
export function getLocalizedMessage(text: string): string | false {
const valNewH = text.replace(/__MSG_(\w+)__/g, function(match, v1) {
return v1 ? chrome.i18n.getMessage(v1).replace(/</g, "&#60;")
.replace(/"/g, "&quot;").replace(/\n/g, "<br/>") : "";
});
if (valNewH != text) {
return valNewH;
} else {
return false;
}
}
}