2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2023-01-06 05:40:17 +01:00
|
|
|
<div class="_gaps_m">
|
2023-01-05 13:04:56 +01:00
|
|
|
<div>
|
2023-10-03 13:26:11 +02:00
|
|
|
<MkTextarea v-model="mutedWords">
|
|
|
|
<span>{{ i18n.ts._wordMute.muteWords }}</span>
|
|
|
|
<template #caption>{{ i18n.ts._wordMute.muteWordsDescription }}<br>{{ i18n.ts._wordMute.muteWordsDescription2 }}</template>
|
|
|
|
</MkTextarea>
|
2021-11-28 12:07:37 +01:00
|
|
|
</div>
|
2022-12-19 11:01:30 +01:00
|
|
|
<MkButton primary inline :disabled="!changed" @click="save()"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
|
2020-10-17 13:12:00 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
<script lang="ts" setup>
|
2022-06-20 10:38:49 +02:00
|
|
|
import { ref, watch } from 'vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
2022-08-30 17:24:33 +02:00
|
|
|
import MkKeyValue from '@/components/MkKeyValue.vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
2022-08-30 17:24:33 +02:00
|
|
|
import MkTab from '@/components/MkTab.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import number from '@/filters/number.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { $i } from '@/account.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
const render = (mutedWords) => mutedWords.map(x => {
|
|
|
|
if (Array.isArray(x)) {
|
|
|
|
return x.join(' ');
|
|
|
|
} else {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}).join('\n');
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
const tab = ref('soft');
|
2023-10-03 13:26:11 +02:00
|
|
|
const mutedWords = ref(render($i!.mutedWords));
|
2022-05-05 15:51:58 +02:00
|
|
|
const changed = ref(false);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-10-03 13:26:11 +02:00
|
|
|
watch(mutedWords, () => {
|
2022-05-05 15:51:58 +02:00
|
|
|
changed.value = true;
|
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
async function save() {
|
2023-10-03 13:26:11 +02:00
|
|
|
const parseMutes = (mutes) => {
|
2022-05-05 15:51:58 +02:00
|
|
|
// split into lines, remove empty lines and unnecessary whitespace
|
2022-05-26 15:53:09 +02:00
|
|
|
let lines = mutes.trim().split('\n').map(line => line.trim()).filter(line => line !== '');
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
// check each line if it is a RegExp or not
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
2022-06-10 07:36:55 +02:00
|
|
|
const line = lines[i];
|
2022-05-05 15:51:58 +02:00
|
|
|
const regexp = line.match(/^\/(.+)\/(.*)$/);
|
|
|
|
if (regexp) {
|
|
|
|
// check that the RegExp is valid
|
|
|
|
try {
|
|
|
|
new RegExp(regexp[1], regexp[2]);
|
|
|
|
// note that regex lines will not be split by spaces!
|
|
|
|
} catch (err: any) {
|
|
|
|
// invalid syntax: do not save, do not reset changed flag
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts.regexpError,
|
2023-10-03 13:26:11 +02:00
|
|
|
text: i18n.t('regexpErrorDescription', { tab: 'word mute', line: i + 1 }) + '\n' + err.toString(),
|
2022-05-05 15:51:58 +02:00
|
|
|
});
|
|
|
|
// re-throw error so these invalid settings are not saved
|
|
|
|
throw err;
|
2022-02-10 11:47:46 +01:00
|
|
|
}
|
2022-05-05 15:51:58 +02:00
|
|
|
} else {
|
|
|
|
lines[i] = line.split(' ');
|
|
|
|
}
|
|
|
|
}
|
2022-02-11 11:44:56 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
return lines;
|
|
|
|
};
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2023-10-03 13:26:11 +02:00
|
|
|
let parsed;
|
2022-05-05 15:51:58 +02:00
|
|
|
try {
|
2023-10-03 13:26:11 +02:00
|
|
|
parsed = parseMutes(mutedWords.value);
|
2022-05-05 15:51:58 +02:00
|
|
|
} catch (err) {
|
|
|
|
// already displayed error message in parseMutes
|
|
|
|
return;
|
|
|
|
}
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
await os.api('i/update', {
|
2023-10-03 13:26:11 +02:00
|
|
|
mutedWords: parsed,
|
2022-05-05 15:51:58 +02:00
|
|
|
});
|
2022-02-10 11:47:46 +01:00
|
|
|
|
2022-05-05 15:51:58 +02:00
|
|
|
changed.value = false;
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
</script>
|