Add alt missing alt text warning

This commit is contained in:
Leah 2025-01-08 22:06:18 +01:00
parent f2eafaab73
commit ee5efd01b4
7 changed files with 55 additions and 4 deletions

View file

@ -528,6 +528,7 @@ mediaListWithOneImageAppearance: "Height of media lists with one image only"
limitTo: "Limit to {x}" limitTo: "Limit to {x}"
noFollowRequests: "You don't have any pending follow requests" noFollowRequests: "You don't have any pending follow requests"
openImageInNewTab: "Open images in new tab" openImageInNewTab: "Open images in new tab"
warnForMissingAltText: "Warn you when you forget to put alt text"
dashboard: "Dashboard" dashboard: "Dashboard"
local: "Local" local: "Local"
remote: "Remote" remote: "Remote"
@ -1045,6 +1046,9 @@ thisPostMayBeAnnoying: "This note may annoy others."
thisPostMayBeAnnoyingHome: "Post to home timeline" thisPostMayBeAnnoyingHome: "Post to home timeline"
thisPostMayBeAnnoyingCancel: "Cancel" thisPostMayBeAnnoyingCancel: "Cancel"
thisPostMayBeAnnoyingIgnore: "Post anyway" thisPostMayBeAnnoyingIgnore: "Post anyway"
thisPostIsMissingAltTextCancel: "Cancel"
thisPostIsMissingAltTextIgnore: "Post anyway"
thisPostIsMissingAltText: "One of the files attached to this post is missing alt text. Please ensure all the attachments have alt text."
collapseRenotes: "Collapse renotes you've already seen" collapseRenotes: "Collapse renotes you've already seen"
internalServerError: "Internal Server Error" internalServerError: "Internal Server Error"
internalServerErrorDescription: "The server has run into an unexpected error." internalServerErrorDescription: "The server has run into an unexpected error."

12
locales/index.d.ts vendored
View file

@ -4207,6 +4207,18 @@ export interface Locale extends ILocale {
* 稿 * 稿
*/ */
"thisPostMayBeAnnoyingIgnore": string; "thisPostMayBeAnnoyingIgnore": string;
/**
*
*/
"thisPostIsMissingAltTextCancel": string;
/**
* 稿
*/
"thisPostIsMissingAltTextIgnore": string;
/**
* 稿 1
*/
"thisPostIsMissingAltText": string;
/** /**
* *
*/ */

View file

@ -1047,6 +1047,9 @@ thisPostMayBeAnnoying: "この投稿は迷惑になる可能性があります
thisPostMayBeAnnoyingHome: "ホームに投稿" thisPostMayBeAnnoyingHome: "ホームに投稿"
thisPostMayBeAnnoyingCancel: "やめる" thisPostMayBeAnnoyingCancel: "やめる"
thisPostMayBeAnnoyingIgnore: "このまま投稿" thisPostMayBeAnnoyingIgnore: "このまま投稿"
thisPostIsMissingAltTextCancel: "やめる"
thisPostIsMissingAltTextIgnore: "このまま投稿"
thisPostIsMissingAltText: "この投稿に添付されたファイルの 1 つに代替テキストがありません。すべての添付ファイルに代替テキストが含まれていることを確認してください。"
collapseRenotes: "見たことのあるリノートを省略して表示" collapseRenotes: "見たことのあるリノートを省略して表示"
internalServerError: "サーバー内部エラー" internalServerError: "サーバー内部エラー"
internalServerErrorDescription: "サーバー内部で予期しないエラーが発生しました。" internalServerErrorDescription: "サーバー内部で予期しないエラーが発生しました。"

View file

@ -101,7 +101,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { inject, watch, nextTick, onMounted, onUnmounted, defineAsyncComponent, provide, shallowRef, ref, computed } from 'vue'; import { inject, watch, nextTick, onMounted, onUnmounted, defineAsyncComponent, provide, shallowRef, ref, computed, toRaw } from 'vue';
import * as mfm from 'mfm-js'; import * as mfm from 'mfm-js';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import insertTextAtCursor from 'insert-text-at-cursor'; import insertTextAtCursor from 'insert-text-at-cursor';
@ -760,6 +760,31 @@ async function post(ev?: MouseEvent) {
} }
} }
if (defaultStore.state.warnMissingAltText) {
const filesData = toRaw(files.value);
const isMissingAltText = filesData.filter(
file => file.type.startsWith('image/') || file.type.startsWith('video/') || file.type.startsWith('audio/'),
).some(file => !file.comment);
if (isMissingAltText) {
const { canceled, result } = await os.actions({
type: 'warning',
text: i18n.ts.thisPostIsMissingAltText,
actions: [{
value: 'cancel',
text: i18n.ts.thisPostIsMissingAltTextCancel,
}, {
value: 'ignore',
text: i18n.ts.thisPostIsMissingAltTextIgnore,
}],
});
if (canceled) return;
if (result === 'cancel') return;
}
}
let postData = { let postData = {
text: text.value === '' ? null : text.value, text: text.value === '' ? null : text.value,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@ -874,9 +899,9 @@ async function post(ev?: MouseEvent) {
type: 'error', type: 'error',
text: err.message + '\n' + (err as any).id, text: err.message + '\n' + (err as any).id,
}); });
emit("postError"); emit('postError');
}); });
emit("posting"); emit('posting');
} }
function cancel() { function cancel() {
@ -893,7 +918,7 @@ async function insertEmoji(ev: MouseEvent) {
os.openEmojiPicker( os.openEmojiPicker(
(ev.currentTarget ?? ev.target) as HTMLElement, (ev.currentTarget ?? ev.target) as HTMLElement,
{ asReactionPicker: false }, { asReactionPicker: false },
textareaEl.value textareaEl.value,
); );
} }

View file

@ -162,6 +162,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<div class="_gaps_m"> <div class="_gaps_m">
<div class="_gaps_s"> <div class="_gaps_s">
<MkSwitch v-model="warnMissingAltText">{{ i18n.ts.warnForMissingAltText }}</MkSwitch>
<MkSwitch v-model="imageNewTab">{{ i18n.ts.openImageInNewTab }}</MkSwitch> <MkSwitch v-model="imageNewTab">{{ i18n.ts.openImageInNewTab }}</MkSwitch>
<MkSwitch v-model="useReactionPickerForContextMenu">{{ i18n.ts.useReactionPickerForContextMenu }}</MkSwitch> <MkSwitch v-model="useReactionPickerForContextMenu">{{ i18n.ts.useReactionPickerForContextMenu }}</MkSwitch>
<MkSwitch v-model="enableInfiniteScroll">{{ i18n.ts.enableInfiniteScroll }}</MkSwitch> <MkSwitch v-model="enableInfiniteScroll">{{ i18n.ts.enableInfiniteScroll }}</MkSwitch>
@ -299,6 +300,7 @@ const forceShowAds = computed(defaultStore.makeGetterSetter('forceShowAds'));
const loadRawImages = computed(defaultStore.makeGetterSetter('loadRawImages')); const loadRawImages = computed(defaultStore.makeGetterSetter('loadRawImages'));
const highlightSensitiveMedia = computed(defaultStore.makeGetterSetter('highlightSensitiveMedia')); const highlightSensitiveMedia = computed(defaultStore.makeGetterSetter('highlightSensitiveMedia'));
const imageNewTab = computed(defaultStore.makeGetterSetter('imageNewTab')); const imageNewTab = computed(defaultStore.makeGetterSetter('imageNewTab'));
const warnMissingAltText = computed(defaultStore.makeGetterSetter('warnMissingAltText'));
const nsfw = computed(defaultStore.makeGetterSetter('nsfw')); const nsfw = computed(defaultStore.makeGetterSetter('nsfw'));
const showFixedPostForm = computed(defaultStore.makeGetterSetter('showFixedPostForm')); const showFixedPostForm = computed(defaultStore.makeGetterSetter('showFixedPostForm'));
const showFixedPostFormInChannel = computed(defaultStore.makeGetterSetter('showFixedPostFormInChannel')); const showFixedPostFormInChannel = computed(defaultStore.makeGetterSetter('showFixedPostFormInChannel'));

View file

@ -75,6 +75,7 @@ const defaultStoreSaveKeys: (keyof typeof defaultStore['state'])[] = [
'showRenotesCount', 'showRenotesCount',
'showReactionsCount', 'showReactionsCount',
'loadRawImages', 'loadRawImages',
'warnMissingAltText',
'imageNewTab', 'imageNewTab',
'dataSaver', 'dataSaver',
'disableShowingAnimatedImages', 'disableShowingAnimatedImages',

View file

@ -247,6 +247,10 @@ export const defaultStore = markRaw(new Storage('base', {
where: 'device', where: 'device',
default: false, default: false,
}, },
warnMissingAltText: {
where: 'device',
default: true,
},
imageNewTab: { imageNewTab: {
where: 'device', where: 'device',
default: false, default: false,