fix: trustedTypes issue

- Close #2339
This commit is contained in:
JellyBrick
2024-10-16 20:40:35 +09:00
parent 11b11ed966
commit 9bc42f836f
5 changed files with 9 additions and 5 deletions

View File

@ -107,7 +107,8 @@ export const onRendererLoad = ({
ipc.on('downloader-feedback', (feedback: string) => { ipc.on('downloader-feedback', (feedback: string) => {
if (progress) { if (progress) {
progress.innerHTML = feedback || t('plugins.downloader.templates.button'); const targetHtml = feedback || t('plugins.downloader.templates.button');
progress.innerHTML = window.trustedTypes?.defaultPolicy ? window.trustedTypes.defaultPolicy.createHTML(targetHtml) : targetHtml;
} else { } else {
console.warn( console.warn(
LoggerPrefix, LoggerPrefix,

View File

@ -10,7 +10,7 @@ export const onRendererLoad = ({
ipc: { invoke, on }, ipc: { invoke, on },
}: RendererContext<LyricsGeniusPluginConfig>) => { }: RendererContext<LyricsGeniusPluginConfig>) => {
const setLyrics = (lyricsContainer: Element, lyrics: string | null) => { const setLyrics = (lyricsContainer: Element, lyrics: string | null) => {
lyricsContainer.innerHTML = ` const targetHtml = `
<div id="contents" class="style-scope ytmusic-section-list-renderer description ytmusic-description-shelf-renderer genius-lyrics"> <div id="contents" class="style-scope ytmusic-section-list-renderer description ytmusic-description-shelf-renderer genius-lyrics">
${ ${
lyrics?.replaceAll(/\r\n|\r|\n/g, '<br/>') ?? lyrics?.replaceAll(/\r\n|\r|\n/g, '<br/>') ??
@ -20,6 +20,7 @@ export const onRendererLoad = ({
<yt-formatted-string class="footer style-scope ytmusic-description-shelf-renderer" style="align-self: baseline"> <yt-formatted-string class="footer style-scope ytmusic-description-shelf-renderer" style="align-self: baseline">
</yt-formatted-string> </yt-formatted-string>
`; `;
lyricsContainer.innerHTML = window.trustedTypes?.defaultPolicy ? window.trustedTypes.defaultPolicy.createHTML(targetHtml) : targetHtml;
if (lyrics) { if (lyrics) {
const footer = lyricsContainer.querySelector('.footer'); const footer = lyricsContainer.querySelector('.footer');

View File

@ -22,7 +22,8 @@ const updatePlayBackSpeed = () => {
const playbackSpeedElement = document.querySelector('#playback-speed-value'); const playbackSpeedElement = document.querySelector('#playback-speed-value');
if (playbackSpeedElement) { if (playbackSpeedElement) {
playbackSpeedElement.innerHTML = String(playbackSpeed); const targetHtml = String(playbackSpeed);
playbackSpeedElement.innerHTML = window.trustedTypes?.defaultPolicy ? trustedTypes.defaultPolicy.createHTML(targetHtml) : targetHtml;
} }
}; };

View File

@ -6,7 +6,7 @@
export const ElementFromHtml = (html: string): HTMLElement => { export const ElementFromHtml = (html: string): HTMLElement => {
const template = document.createElement('template'); const template = document.createElement('template');
html = html.trim(); // Never return a text node of whitespace as the result html = html.trim(); // Never return a text node of whitespace as the result
template.innerHTML = html; template.innerHTML = window.trustedTypes?.defaultPolicy ? window.trustedTypes.defaultPolicy.createHTML(html) : html;
return template.content.firstElementChild as HTMLElement; return template.content.firstElementChild as HTMLElement;
}; };

View File

@ -269,7 +269,8 @@ const defineYTMDTransElements = () => {
const that = this as HTMLElement; const that = this as HTMLElement;
const key = that.getAttribute('key'); const key = that.getAttribute('key');
if (key) { if (key) {
that.innerHTML = i18t(key); const targetHtml = i18t(key);
that.innerHTML = window.trustedTypes?.defaultPolicy ? window.trustedTypes.defaultPolicy.createHTML(targetHtml) : targetHtml;
} }
}; };
customElements.define( customElements.define(