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

View File

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

View File

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

View File

@@ -13,7 +13,7 @@ import CategoryChooser from "./render/CategoryChooser";
import UnsubmittedVideos from "./render/UnsubmittedVideos"; import UnsubmittedVideos from "./render/UnsubmittedVideos";
import KeybindComponent from "./components/options/KeybindComponent"; import KeybindComponent from "./components/options/KeybindComponent";
import { showDonationLink } from "./utils/configUtils"; 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 { StorageChangesObject } from "@ajayyy/maze-utils/lib/config";
import { getHash } from "@ajayyy/maze-utils/lib/hash"; import { getHash } from "@ajayyy/maze-utils/lib/hash";
import { isFirefoxOrSafari } from "@ajayyy/maze-utils"; import { isFirefoxOrSafari } from "@ajayyy/maze-utils";

View File

@@ -1,6 +1,6 @@
import Config from "./config"; import Config from "./config";
import Utils from "./utils"; import Utils from "./utils";
import { localizeHtmlPage } from "./utils/pageUtils"; import { localizeHtmlPage } from "@ajayyy/maze-utils/lib/setup";
const utils = new Utils(); const utils = new Utils();
// This is needed, if Config is not imported before Utils, things break. // 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 { AnimationUtils } from "./utils/animationUtils";
import { GenericUtils } from "./utils/genericUtils"; import { GenericUtils } from "./utils/genericUtils";
import { shortCategoryName } from "./utils/categoryUtils"; import { shortCategoryName } from "./utils/categoryUtils";
import { localizeHtmlPage } from "./utils/pageUtils"; import { localizeHtmlPage } from "@ajayyy/maze-utils/lib/setup";
import { exportTimes } from "./utils/exporter"; import { exportTimes } from "./utils/exporter";
import GenericNotice from "./render/GenericNotice"; import GenericNotice from "./render/GenericNotice";
import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating"; import { getFormattedTime } from "@ajayyy/maze-utils/lib/formating";

View File

@@ -94,26 +94,3 @@ export function getExistingChapters(currentVideoID: VideoID, duration: number):
return chapters; 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;
}
}