2024-07-18 06:41:32 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
2024-09-10 09:39:53 +00:00
|
|
|
import { hostname } from '@@/js/config.js';
|
2024-07-18 06:41:32 +00:00
|
|
|
|
|
|
|
export function transformPlayerUrl(url: string): string {
|
|
|
|
const urlObj = new URL(url);
|
|
|
|
if (!['https:', 'http:'].includes(urlObj.protocol)) throw new Error('Invalid protocol');
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(urlObj.search);
|
|
|
|
|
|
|
|
if (urlObj.hostname === 'player.twitch.tv') {
|
|
|
|
// TwitchはCSPの制約あり
|
|
|
|
// https://dev.twitch.tv/docs/embed/video-and-clips/
|
|
|
|
urlParams.set('parent', hostname);
|
|
|
|
urlParams.set('allowfullscreen', '');
|
|
|
|
urlParams.set('autoplay', 'true');
|
|
|
|
} else {
|
|
|
|
urlParams.set('autoplay', '1');
|
|
|
|
urlParams.set('auto_play', '1');
|
|
|
|
}
|
|
|
|
urlObj.search = urlParams.toString();
|
|
|
|
|
|
|
|
return urlObj.toString();
|
|
|
|
}
|