Add alt missing alt text warning #3

Merged
ashten merged 2 commits from feature/warn-when-missing-alt-text into main 2025-01-09 20:26:34 +00:00
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}"
noFollowRequests: "You don't have any pending follow requests"
openImageInNewTab: "Open images in new tab"
warnForMissingAltText: "Warn you when you forget to put alt text"
dashboard: "Dashboard"
local: "Local"
remote: "Remote"
@ -1045,6 +1046,9 @@ thisPostMayBeAnnoying: "This note may annoy others."
thisPostMayBeAnnoyingHome: "Post to home timeline"
thisPostMayBeAnnoyingCancel: "Cancel"
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"
internalServerError: "Internal Server 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;
/**
*
*/
"thisPostIsMissingAltTextCancel": string;
/**
* 稿
*/
"thisPostIsMissingAltTextIgnore": string;
/**
* 稿 1
*/
"thisPostIsMissingAltText": string;
/**
*
*/

View file

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

View file

@ -101,7 +101,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<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 Misskey from 'misskey-js';
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 = {
text: text.value === '' ? null : text.value,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@ -874,9 +899,9 @@ async function post(ev?: MouseEvent) {
type: 'error',
text: err.message + '\n' + (err as any).id,
});
emit("postError");
emit('postError');
});
emit("posting");
emit('posting');
}
function cancel() {
@ -893,7 +918,7 @@ async function insertEmoji(ev: MouseEvent) {
os.openEmojiPicker(
(ev.currentTarget ?? ev.target) as HTMLElement,
{ 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_s">
<MkSwitch v-model="warnMissingAltText">{{ i18n.ts.warnForMissingAltText }}</MkSwitch>
<MkSwitch v-model="imageNewTab">{{ i18n.ts.openImageInNewTab }}</MkSwitch>
<MkSwitch v-model="useReactionPickerForContextMenu">{{ i18n.ts.useReactionPickerForContextMenu }}</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 highlightSensitiveMedia = computed(defaultStore.makeGetterSetter('highlightSensitiveMedia'));
const imageNewTab = computed(defaultStore.makeGetterSetter('imageNewTab'));
const warnMissingAltText = computed(defaultStore.makeGetterSetter('warnMissingAltText'));
const nsfw = computed(defaultStore.makeGetterSetter('nsfw'));
const showFixedPostForm = computed(defaultStore.makeGetterSetter('showFixedPostForm'));
const showFixedPostFormInChannel = computed(defaultStore.makeGetterSetter('showFixedPostFormInChannel'));

View file

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

View file

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