summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/scripts')
-rw-r--r--packages/frontend/src/scripts/autocomplete.ts4
-rw-r--r--packages/frontend/src/scripts/check-word-mute.ts28
-rw-r--r--packages/frontend/src/scripts/chiptune2.ts10
-rw-r--r--packages/frontend/src/scripts/nyaize.ts8
-rw-r--r--packages/frontend/src/scripts/sanitize-html.ts18
5 files changed, 57 insertions, 11 deletions
diff --git a/packages/frontend/src/scripts/autocomplete.ts b/packages/frontend/src/scripts/autocomplete.ts
index 9fc8f7843e..d942402ffc 100644
--- a/packages/frontend/src/scripts/autocomplete.ts
+++ b/packages/frontend/src/scripts/autocomplete.ts
@@ -99,7 +99,7 @@ export class Autocomplete {
const isHashtag = hashtagIndex !== -1;
const isMfmParam = mfmParamIndex !== -1 && afterLastMfmParam?.includes('.') && !afterLastMfmParam?.includes(' ');
const isMfmTag = mfmTagIndex !== -1 && !isMfmParam;
- const isEmoji = emojiIndex !== -1 && text.split(/:[a-z0-9_+\-]+:/).pop()!.includes(':');
+ const isEmoji = emojiIndex !== -1 && text.split(/:[\p{Letter}\p{Number}\p{Mark}_+-]+:/u).pop()!.includes(':');
let opened = false;
@@ -125,7 +125,7 @@ export class Autocomplete {
if (isEmoji && !opened && this.onlyType.includes('emoji')) {
const emoji = text.substring(emojiIndex + 1);
if (!emoji.includes(' ')) {
- this.open('emoji', emoji);
+ this.open('emoji', emoji.normalize('NFC'));
opened = true;
}
}
diff --git a/packages/frontend/src/scripts/check-word-mute.ts b/packages/frontend/src/scripts/check-word-mute.ts
index 67e896b4b9..8d3e96cea5 100644
--- a/packages/frontend/src/scripts/check-word-mute.ts
+++ b/packages/frontend/src/scripts/check-word-mute.ts
@@ -3,12 +3,14 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-export function checkWordMute(note: Record<string, any>, me: Record<string, any> | null | undefined, mutedWords: Array<string | string[]>): boolean {
+import type { Note, MeDetailed } from "misskey-js/entities.js";
+
+export function checkWordMute(note: Note, me: MeDetailed | null | undefined, mutedWords: Array<string | string[]>): boolean {
// 自分自身
if (me && (note.userId === me.id)) return false;
if (mutedWords.length > 0) {
- const text = ((note.cw ?? '') + '\n' + (note.text ?? '')).trim();
+ const text = getNoteText(note);
if (text === '') return false;
@@ -40,3 +42,25 @@ export function checkWordMute(note: Record<string, any>, me: Record<string, any>
return false;
}
+
+function getNoteText(note: Note): string {
+ const textParts: string[] = [];
+
+ if (note.cw)
+ textParts.push(note.cw);
+
+ if (note.text)
+ textParts.push(note.text);
+
+ if (note.files)
+ for (const file of note.files)
+ if (file.comment)
+ textParts.push(file.comment);
+
+ if (note.poll)
+ for (const choice of note.poll.choices)
+ if (choice.text)
+ textParts.push(choice.text);
+
+ return textParts.join('\n').trim();
+}
diff --git a/packages/frontend/src/scripts/chiptune2.ts b/packages/frontend/src/scripts/chiptune2.ts
index 3cc34c0040..56afb9b708 100644
--- a/packages/frontend/src/scripts/chiptune2.ts
+++ b/packages/frontend/src/scripts/chiptune2.ts
@@ -1,4 +1,3 @@
-// @ts-nocheck
/* eslint-disable */
const ChiptuneAudioContext = window.AudioContext || window.webkitAudioContext;
@@ -6,6 +5,11 @@ const ChiptuneAudioContext = window.AudioContext || window.webkitAudioContext;
let libopenmpt
let libopenmptLoadPromise
+type ChiptuneJsConfig = {
+ repeatCount: number | null;
+ context: AudioContext | null;
+};
+
export function ChiptuneJsConfig (repeatCount?: number, context?: AudioContext) {
this.repeatCount = repeatCount;
this.context = context;
@@ -13,7 +17,7 @@ export function ChiptuneJsConfig (repeatCount?: number, context?: AudioContext)
ChiptuneJsConfig.prototype.constructor = ChiptuneJsConfig;
-export function ChiptuneJsPlayer (config: object) {
+export function ChiptuneJsPlayer (config: ChiptuneJsConfig) {
this.config = config;
this.audioContext = config.context || new ChiptuneAudioContext();
this.context = this.audioContext.createGain();
@@ -27,7 +31,7 @@ ChiptuneJsPlayer.prototype.initialize = function() {
if (libopenmptLoadPromise) return libopenmptLoadPromise;
if (libopenmpt) return Promise.resolve();
- libopenmptLoadPromise = new Promise(async (resolve, reject) => {
+ libopenmptLoadPromise = new Promise<void>(async (resolve, reject) => {
try {
const { Module } = await import('./libopenmpt/libopenmpt.js');
await new Promise((resolve) => {
diff --git a/packages/frontend/src/scripts/nyaize.ts b/packages/frontend/src/scripts/nyaize.ts
index 58ed88fed1..5e6fa298d1 100644
--- a/packages/frontend/src/scripts/nyaize.ts
+++ b/packages/frontend/src/scripts/nyaize.ts
@@ -9,9 +9,9 @@ const koRegex3 = /(야(?=\?))|(야$)|(야(?= ))/gm;
function ifAfter(prefix, fn) {
const preLen = prefix.length;
- const regex = new RegExp(prefix,'i');
- return (x,pos,string) => {
- return pos > 0 && string.substring(pos-preLen,pos).match(regex) ? fn(x) : x;
+ const regex = new RegExp(prefix, 'i');
+ return (x, pos, string) => {
+ return pos > 0 && string.substring(pos - preLen, pos).match(regex) ? fn(x) : x;
};
}
@@ -25,7 +25,7 @@ export function nyaize(text: string): string {
.replace(/one/gi, ifAfter('every', x => x === 'ONE' ? 'NYAN' : 'nyan'))
// ko-KR
.replace(koRegex1, match => String.fromCharCode(
- match.charCodeAt(0)! + '냐'.charCodeAt(0) - '나'.charCodeAt(0),
+ match.charCodeAt(0) + '냐'.charCodeAt(0) - '나'.charCodeAt(0),
))
.replace(koRegex2, '다냥')
.replace(koRegex3, '냥');
diff --git a/packages/frontend/src/scripts/sanitize-html.ts b/packages/frontend/src/scripts/sanitize-html.ts
new file mode 100644
index 0000000000..6e1a46c746
--- /dev/null
+++ b/packages/frontend/src/scripts/sanitize-html.ts
@@ -0,0 +1,18 @@
+/*
+ * SPDX-FileCopyrightText: dakkar and other Sharkey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+*/
+
+import original from 'sanitize-html';
+
+export default function sanitizeHtml(str: string | null): string | null {
+ if (str == null) return str;
+ return original(str, {
+ allowedTags: original.defaults.allowedTags.concat(['img', 'audio', 'video', 'center', 'details', 'summary']),
+ allowedAttributes: {
+ ...original.defaults.allowedAttributes,
+ a: original.defaults.allowedAttributes.a.concat(['style']),
+ img: original.defaults.allowedAttributes.img.concat(['style']),
+ },
+ });
+}