mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 03:11:46 +00:00
fix: TrustedHTML warning
This commit is contained in:
@ -4,6 +4,7 @@ import { setOptions, setMenuOptions, isEnabled } from '../../config/plugins';
|
||||
import { debounce } from '../../providers/decorators';
|
||||
|
||||
import { YoutubePlayer } from '../../types/youtube-player';
|
||||
import { noopTrustedHtmlPolicy } from '../utils';
|
||||
|
||||
import type { ConfigType } from '../../config/dynamic';
|
||||
|
||||
@ -87,14 +88,18 @@ function injectVolumeHud(noVid: boolean) {
|
||||
const position = 'top: 18px; right: 60px;';
|
||||
const mainStyle = 'font-size: xx-large;';
|
||||
|
||||
$('.center-content.ytmusic-nav-bar')?.insertAdjacentHTML('beforeend',
|
||||
`<span id="volumeHud" style="${position + mainStyle}"></span>`);
|
||||
$('.center-content.ytmusic-nav-bar')?.insertAdjacentHTML(
|
||||
'beforeend',
|
||||
noopTrustedHtmlPolicy().createHTML(`<span id="volumeHud" style="${position + mainStyle}"></span>`) as unknown as string,
|
||||
);
|
||||
} else {
|
||||
const position = 'top: 10px; left: 10px;';
|
||||
const mainStyle = 'font-size: xxx-large; webkit-text-stroke: 1px black; font-weight: 600;';
|
||||
|
||||
$('#song-video')?.insertAdjacentHTML('afterend',
|
||||
`<span id="volumeHud" style="${position + mainStyle}"></span>`);
|
||||
$('#song-video')?.insertAdjacentHTML(
|
||||
'afterend',
|
||||
noopTrustedHtmlPolicy().createHTML(`<span id="volumeHud" style="${position + mainStyle}"></span>`) as unknown as string,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,11 +5,17 @@ import { ipcMain, ipcRenderer } from 'electron';
|
||||
|
||||
import { ValueOf } from '../utils/type-utils';
|
||||
|
||||
export const noopTrustedHtmlPolicy = () => window?.trustedTypes?.createPolicy('forceInner', {
|
||||
createHTML: (s: string): string => s,
|
||||
}) ?? {
|
||||
createHTML: (s: string): string => s,
|
||||
};
|
||||
|
||||
// Creates a DOM element from an HTML string
|
||||
export const ElementFromHtml = (html: string): HTMLElement => {
|
||||
const template = document.createElement('template');
|
||||
html = html.trim(); // Never return a text node of whitespace as the result
|
||||
template.innerHTML = html;
|
||||
template.innerHTML = noopTrustedHtmlPolicy().createHTML(html) as unknown as string;
|
||||
|
||||
return template.content.firstElementChild as HTMLElement;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user