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

14
package-lock.json generated
View file

@ -27,7 +27,7 @@
],
"license": "LGPL-3.0-or-later",
"dependencies": {
"@ajayyy/maze-utils": "1.1.25",
"@ajayyy/maze-utils": "1.1.26",
"content-scripts-register-polyfill": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
@ -67,9 +67,9 @@
}
},
"node_modules/@ajayyy/maze-utils": {
"version": "1.1.25",
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.25.tgz",
"integrity": "sha512-GntQY3v0SfP35/IYuHeCeCuT7z+Pc15padVmRoYqD9aShsU0yrNBgmFJWxkFMIDoltMiY4ZqSWNlPX5p+Vyovw==",
"version": "1.1.26",
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.26.tgz",
"integrity": "sha512-PlqDsdbqeG1qQa1ZGgO5d7N8VeuaKKiR7gzUq0m+ROYcRhQ4k66gxF9Lumhbq6X9B8o0pzNwTu9eT3LFyyfsVw==",
"funding": [
{
"type": "individual",
@ -13602,9 +13602,9 @@
},
"dependencies": {
"@ajayyy/maze-utils": {
"version": "1.1.25",
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.25.tgz",
"integrity": "sha512-GntQY3v0SfP35/IYuHeCeCuT7z+Pc15padVmRoYqD9aShsU0yrNBgmFJWxkFMIDoltMiY4ZqSWNlPX5p+Vyovw=="
"version": "1.1.26",
"resolved": "https://registry.npmjs.org/@ajayyy/maze-utils/-/maze-utils-1.1.26.tgz",
"integrity": "sha512-PlqDsdbqeG1qQa1ZGgO5d7N8VeuaKKiR7gzUq0m+ROYcRhQ4k66gxF9Lumhbq6X9B8o0pzNwTu9eT3LFyyfsVw=="
},
"@ampproject/remapping": {
"version": "2.2.0",

View file

@ -4,7 +4,7 @@
"description": "",
"main": "background.js",
"dependencies": {
"@ajayyy/maze-utils": "1.1.25",
"@ajayyy/maze-utils": "1.1.26",
"content-scripts-register-polyfill": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"

@ -1 +1 @@
Subproject commit 21110d3bac6e15eb837fea4e6cfc7b647c58519a
Subproject commit 48ef0174a0f2d3ad881660193a440d6059fc9349

View file

@ -1,7 +1,7 @@
import { localizeHtmlPage } from "@ajayyy/maze-utils/lib/setup";
import Config from "./config";
import { showDonationLink } from "./utils/configUtils";
import { localizeHtmlPage } from "./utils/pageUtils";
import { waitFor } from "@ajayyy/maze-utils";
window.addEventListener('DOMContentLoaded', init);

View file

@ -13,7 +13,7 @@ import CategoryChooser from "./render/CategoryChooser";
import UnsubmittedVideos from "./render/UnsubmittedVideos";
import KeybindComponent from "./components/options/KeybindComponent";
import { showDonationLink } from "./utils/configUtils";
import { localizeHtmlPage } from "./utils/pageUtils";
import { localizeHtmlPage } from "@ajayyy/maze-utils/lib/setup";
import { StorageChangesObject } from "@ajayyy/maze-utils/lib/config";
import { getHash } from "@ajayyy/maze-utils/lib/hash";
import { isFirefoxOrSafari } from "@ajayyy/maze-utils";

View file

@ -1,6 +1,6 @@
import Config from "./config";
import Utils from "./utils";
import { localizeHtmlPage } from "./utils/pageUtils";
import { localizeHtmlPage } from "@ajayyy/maze-utils/lib/setup";
const utils = new Utils();
// This is needed, if Config is not imported before Utils, things break.

View file

@ -22,7 +22,7 @@ import { showDonationLink } from "./utils/configUtils";
import { AnimationUtils } from "./utils/animationUtils";
import { GenericUtils } from "./utils/genericUtils";
import { shortCategoryName } from "./utils/categoryUtils";
import { localizeHtmlPage } from "./utils/pageUtils";
import { localizeHtmlPage } from "@ajayyy/maze-utils/lib/setup";
import { exportTimes } from "./utils/exporter";
import GenericNotice from "./render/GenericNotice";
import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating";

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;
}
}
}