This commit is contained in:
syuilo 2024-08-29 14:19:00 +09:00
parent 79d56e0b32
commit b4b8aa8ab2
10 changed files with 26 additions and 28 deletions

4
locales/index.d.ts vendored
View file

@ -5073,9 +5073,9 @@ export interface Locale extends ILocale {
*/ */
"fromX": ParameterizedString<"x">; "fromX": ParameterizedString<"x">;
/** /**
* *
*/ */
"copyEmbedCode": string; "genEmbedCode": string;
/** /**
* *
*/ */

View file

@ -1264,7 +1264,7 @@ sensitiveMediaRevealConfirm: "センシティブなメディアです。表示
createdLists: "作成したリスト" createdLists: "作成したリスト"
createdAntennas: "作成したアンテナ" createdAntennas: "作成したアンテナ"
fromX: "{x}から" fromX: "{x}から"
copyEmbedCode: "埋め込みコードをコピー" genEmbedCode: "埋め込みコードを生成"
noteOfThisUser: "このユーザーのノート一覧" noteOfThisUser: "このユーザーのノート一覧"
clipNoteLimitExceeded: "これ以上このクリップにノートを追加できません。" clipNoteLimitExceeded: "これ以上このクリップにノートを追加できません。"

View file

@ -60,7 +60,7 @@ import { url, instanceName } from '@/config.js';
import { defaultEmbedParams } from '@/embed-page.js'; import { defaultEmbedParams } from '@/embed-page.js';
const props = defineProps<{ const props = defineProps<{
username: string; userId: string;
}>(); }>();
const embedParams = inject<ParsedEmbedParams>('embedParams', defaultEmbedParams); const embedParams = inject<ParsedEmbedParams>('embedParams', defaultEmbedParams);
@ -77,7 +77,7 @@ const loading = ref(true);
const notesEl = shallowRef<InstanceType<typeof EmNotes> | null>(null); const notesEl = shallowRef<InstanceType<typeof EmNotes> | null>(null);
misskeyApi('users/show', { misskeyApi('users/show', {
username: props.username, userId: props.userId,
}).then(res => { }).then(res => {
user.value = res; user.value = res;
loading.value = false; loading.value = false;

View file

@ -35,6 +35,7 @@ import EmUserTimelinePage from '@/pages/user-timeline.vue';
const page = location.pathname.split('/')[2]; const page = location.pathname.split('/')[2];
const contentId = location.pathname.split('/')[3]; const contentId = location.pathname.split('/')[3];
console.log(page, contentId);
const embedParams = inject<ParsedEmbedParams>('embedParams', defaultEmbedParams); const embedParams = inject<ParsedEmbedParams>('embedParams', defaultEmbedParams);

View file

@ -117,7 +117,7 @@ const emit = defineEmits<{
const props = defineProps<{ const props = defineProps<{
entity: EmbeddableEntity; entity: EmbeddableEntity;
idOrUsername: string; id: string;
params?: EmbedParams; params?: EmbedParams;
}>(); }>();
@ -152,13 +152,12 @@ const paramsForUrl = computed<EmbedParams>(() => ({
const paramsForPreview = ref<EmbedParams>(props.params ?? {}); const paramsForPreview = ref<EmbedParams>(props.params ?? {});
const embedPreviewUrl = computed(() => { const embedPreviewUrl = computed(() => {
const _idOrUsername = props.entity === 'user-timeline' ? '@' + props.idOrUsername : props.idOrUsername;
const paramClass = new URLSearchParams(normalizeEmbedParams(paramsForPreview.value)); const paramClass = new URLSearchParams(normalizeEmbedParams(paramsForPreview.value));
if (paramClass.has('maxHeight')) { if (paramClass.has('maxHeight')) {
const maxHeight = parseInt(paramClass.get('maxHeight')!); const maxHeight = parseInt(paramClass.get('maxHeight')!);
paramClass.set('maxHeight', maxHeight === 0 ? '500' : Math.min(maxHeight, 700).toString()); // 700px paramClass.set('maxHeight', maxHeight === 0 ? '500' : Math.min(maxHeight, 700).toString()); // 700px
} }
return `${url}/embed/${props.entity}/${_idOrUsername}${paramClass.toString() ? '?' + paramClass.toString() : ''}`; return `${url}/embed/${props.entity}/${props.id}${paramClass.toString() ? '?' + paramClass.toString() : ''}`;
}); });
const isEmbedWithScrollbar = computed(() => embedRouteWithScrollbar.includes(props.entity)); const isEmbedWithScrollbar = computed(() => embedRouteWithScrollbar.includes(props.entity));
@ -193,8 +192,7 @@ function applyToPreview() {
const result = ref(''); const result = ref('');
function generate() { function generate() {
const _idOrUsername = props.entity === 'user-timeline' ? '@' + props.idOrUsername : props.idOrUsername; result.value = getEmbedCode(`/embed/${props.entity}/${props.id}`, paramsForUrl.value);
result.value = getEmbedCode(`/embed/${props.entity}/${_idOrUsername}`, paramsForUrl.value);
phase.value = 'result'; phase.value = 'result';
} }

View file

@ -44,7 +44,7 @@ import MkButton from '@/components/MkButton.vue';
import { clipsCache } from '@/cache.js'; import { clipsCache } from '@/cache.js';
import { isSupportShare } from '@/scripts/navigator.js'; import { isSupportShare } from '@/scripts/navigator.js';
import { copyToClipboard } from '@/scripts/copy-to-clipboard.js'; import { copyToClipboard } from '@/scripts/copy-to-clipboard.js';
import { copyEmbedCode } from '@/scripts/get-embed-code.js'; import { genEmbedCode } from '@/scripts/get-embed-code.js';
const props = defineProps<{ const props = defineProps<{
clipId: string, clipId: string,
@ -140,9 +140,9 @@ const headerActions = computed(() => clip.value && isOwned.value ? [{
}, },
}, { }, {
icon: 'ti ti-code', icon: 'ti ti-code',
text: i18n.ts.copyEmbedCode, text: i18n.ts.genEmbedCode,
action: () => { action: () => {
copyEmbedCode('clips', clip.value!.id); genEmbedCode('clips', clip.value!.id);
}, },
}, ...(isSupportShare() ? [{ }, ...(isSupportShare() ? [{
icon: 'ti ti-share', icon: 'ti ti-share',

View file

@ -28,7 +28,7 @@ import { i18n } from '@/i18n.js';
import { $i } from '@/account.js'; import { $i } from '@/account.js';
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { copyEmbedCode } from '@/scripts/get-embed-code.js'; import { genEmbedCode } from '@/scripts/get-embed-code.js';
const props = defineProps<{ const props = defineProps<{
tag: string; tag: string;
@ -57,10 +57,10 @@ const headerActions = computed(() => [{
label: i18n.ts.more, label: i18n.ts.more,
handler: (ev: MouseEvent) => { handler: (ev: MouseEvent) => {
os.popupMenu([{ os.popupMenu([{
text: i18n.ts.copyEmbedCode, text: i18n.ts.genEmbedCode,
icon: 'ti ti-code', icon: 'ti ti-code',
action: () => { action: () => {
copyEmbedCode('tags', props.tag); genEmbedCode('tags', props.tag);
}, },
}], ev.currentTarget ?? ev.target); }], ev.currentTarget ?? ev.target);
} }

View file

@ -4,10 +4,10 @@
*/ */
import { defineAsyncComponent } from 'vue'; import { defineAsyncComponent } from 'vue';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import type { EmbedParams, EmbeddableEntity } from '@/scripts/embed-page.js';
import { url } from '@/config.js'; import { url } from '@/config.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { copyToClipboard } from '@/scripts/copy-to-clipboard.js'; import { copyToClipboard } from '@/scripts/copy-to-clipboard.js';
import type { EmbedParams, EmbeddableEntity } from '@/scripts/embed-page.js';
import { defaultEmbedParams, embedRouteWithScrollbar } from '@/scripts/embed-page.js'; import { defaultEmbedParams, embedRouteWithScrollbar } from '@/scripts/embed-page.js';
const MOBILE_THRESHOLD = 500; const MOBILE_THRESHOLD = 500;
@ -64,7 +64,7 @@ export function getEmbedCode(path: string, params?: EmbedParams): string {
* *
* getEmbedCode 使 * getEmbedCode 使
*/ */
export function copyEmbedCode(entity: EmbeddableEntity, idOrUsername: string, params?: EmbedParams) { export function genEmbedCode(entity: EmbeddableEntity, id: string, params?: EmbedParams) {
const _params = { ...params }; const _params = { ...params };
if (embedRouteWithScrollbar.includes(entity) && _params.maxHeight == null) { if (embedRouteWithScrollbar.includes(entity) && _params.maxHeight == null) {
@ -73,13 +73,12 @@ export function copyEmbedCode(entity: EmbeddableEntity, idOrUsername: string, pa
// PCじゃない場合はコードカスタマイズ画面を出さずにそのままコピー // PCじゃない場合はコードカスタマイズ画面を出さずにそのままコピー
if (window.innerWidth < MOBILE_THRESHOLD) { if (window.innerWidth < MOBILE_THRESHOLD) {
const _idOrUsername = entity === 'user-timeline' ? `@${idOrUsername}` : idOrUsername; copyToClipboard(getEmbedCode(`/embed/${entity}/${id}`, _params));
copyToClipboard(getEmbedCode(`/embed/${entity}/${_idOrUsername}`, _params));
os.success(); os.success();
} else { } else {
const { dispose } = os.popup(defineAsyncComponent(() => import('@/components/MkEmbedCodeGenDialog.vue')), { const { dispose } = os.popup(defineAsyncComponent(() => import('@/components/MkEmbedCodeGenDialog.vue')), {
entity, entity,
idOrUsername, id,
params: _params, params: _params,
}, { }, {
closed: () => dispose(), closed: () => dispose(),

View file

@ -21,7 +21,7 @@ import { MenuItem } from '@/types/menu.js';
import MkRippleEffect from '@/components/MkRippleEffect.vue'; import MkRippleEffect from '@/components/MkRippleEffect.vue';
import { isSupportShare } from '@/scripts/navigator.js'; import { isSupportShare } from '@/scripts/navigator.js';
import { getAppearNote } from '@/scripts/get-appear-note.js'; import { getAppearNote } from '@/scripts/get-appear-note.js';
import { copyEmbedCode } from '@/scripts/get-embed-code.js'; import { genEmbedCode } from '@/scripts/get-embed-code.js';
export async function getNoteClipMenu(props: { export async function getNoteClipMenu(props: {
note: Misskey.entities.Note; note: Misskey.entities.Note;
@ -165,7 +165,7 @@ function getNoteEmbedCodeMenu(note: Misskey.entities.Note, text: string): MenuIt
icon: 'ti ti-code', icon: 'ti ti-code',
text, text,
action: (): void => { action: (): void => {
copyEmbedCode('notes', note.id); genEmbedCode('notes', note.id);
}, },
}; };
} }
@ -324,7 +324,7 @@ export function getNoteMenu(props: {
action: () => { action: () => {
window.open(appearNote.url ?? appearNote.uri, '_blank', 'noopener'); window.open(appearNote.url ?? appearNote.uri, '_blank', 'noopener');
}, },
} : getNoteEmbedCodeMenu(appearNote, i18n.ts.copyEmbedCode), } : getNoteEmbedCodeMenu(appearNote, i18n.ts.genEmbedCode),
...(isSupportShare() ? [{ ...(isSupportShare() ? [{
icon: 'ti ti-share', icon: 'ti ti-share',
text: i18n.ts.share, text: i18n.ts.share,
@ -464,7 +464,7 @@ export function getNoteMenu(props: {
action: () => { action: () => {
window.open(appearNote.url ?? appearNote.uri, '_blank', 'noopener'); window.open(appearNote.url ?? appearNote.uri, '_blank', 'noopener');
}, },
} : getNoteEmbedCodeMenu(appearNote, i18n.ts.copyEmbedCode)] } : getNoteEmbedCodeMenu(appearNote, i18n.ts.genEmbedCode)]
.filter(x => x !== undefined); .filter(x => x !== undefined);
} }

View file

@ -17,7 +17,7 @@ import { notesSearchAvailable, canSearchNonLocalNotes } from '@/scripts/check-pe
import { IRouter } from '@/nirax.js'; import { IRouter } from '@/nirax.js';
import { antennasCache, rolesCache, userListsCache } from '@/cache.js'; import { antennasCache, rolesCache, userListsCache } from '@/cache.js';
import { mainRouter } from '@/router/main.js'; import { mainRouter } from '@/router/main.js';
import { copyEmbedCode } from '@/scripts/get-embed-code.js'; import { genEmbedCode } from '@/scripts/get-embed-code.js';
import { MenuItem } from '@/types/menu.js'; import { MenuItem } from '@/types/menu.js';
export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter = mainRouter) { export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter = mainRouter) {
@ -182,12 +182,12 @@ export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter
}, },
}] : [{ }] : [{
icon: 'ti ti-code', icon: 'ti ti-code',
text: i18n.ts.copyEmbedCode, text: i18n.ts.genEmbedCode,
type: 'parent' as const, type: 'parent' as const,
children: [{ children: [{
text: i18n.ts.noteOfThisUser, text: i18n.ts.noteOfThisUser,
action: () => { action: () => {
copyEmbedCode('user-timeline', user.username); genEmbedCode('user-timeline', user.id);
}, },
}], // TODO: ユーザーカードの埋め込みなど }], // TODO: ユーザーカードの埋め込みなど
}]), { }]), {