summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-07-18 15:41:32 +0900
committerGitHub <noreply@github.com>2024-07-18 15:41:32 +0900
commit4f85b6aa9158190bbdd9246bb8565d5c80081706 (patch)
tree90d7099a30ce0bbf3d2c623732d9825917766549 /packages/frontend/src/scripts
parentMerge branch 'master' into develop (diff)
downloadsharkey-4f85b6aa9158190bbdd9246bb8565d5c80081706.tar.gz
sharkey-4f85b6aa9158190bbdd9246bb8565d5c80081706.tar.bz2
sharkey-4f85b6aa9158190bbdd9246bb8565d5c80081706.zip
fix(frontend): Twitchの埋め込みが開けない問題を修正 (#14247)
* fix(frontend): twitchの埋め込みが開けない問題を修正 * Update Changelog * fix test
Diffstat (limited to 'packages/frontend/src/scripts')
-rw-r--r--packages/frontend/src/scripts/player-url-transform.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/frontend/src/scripts/player-url-transform.ts b/packages/frontend/src/scripts/player-url-transform.ts
new file mode 100644
index 0000000000..53b2a9e441
--- /dev/null
+++ b/packages/frontend/src/scripts/player-url-transform.ts
@@ -0,0 +1,26 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+import { hostname } from '@/config.js';
+
+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();
+}