@Allhen
/// @ 0.12.4
### {
name: "Word Replacer"
version: "0.1.1"
author: "@salano_ym"
description: "ノート閲覧時に特定の単語を置換して表示します"
permissions: []
config: {
repls: {
type: 'string'
label: '置換リスト'
description: '例: ["old", "new"], ["旧", "新"] ...'
default: '["twitter", "misskey"], ["な", "にゃ"]'
}
}
}
@validate(repls) {
if Core:type(repls) != 'arr' {
return [[] false]
}
let new_repls = []
var ok = true
each let r repls {
if Core:type(r) != 'arr' {
ok = false
continue
} elif r.len != 2 {
ok = false
continue
} elif Core:type(r[0]) != 'str' || Core:type(r[1]) != 'str' {
ok = false
continue
}
new_repls.push(r)
}
return [new_repls ok]
}
@replace(text repls) {
if Core:type(text) != 'str' {
return text
}
each let r repls {
text = text.replace(r[0] r[1])
}
return text
}
let a = validate(Json:parse(`[{Plugin:config.repls}]`))
let repls = a[0]
let ok = a[1]
@f(note) {
note.text = replace(note.text repls)
note.cw = replace(note.cw repls)
if note.renote != null {
note.renote.text = replace(note.renote.text repls)
note.renote.cw = replace(note.renote.cw repls)
}
if note.reply != null {
note.reply.text = replace(note.reply.text repls)
note.reply.cw = replace(note.reply.cw repls)
}
return note
}
if !ok {
// Json:parseが例外落ちしたら機能しません
Mk:dialog('Word Replace' '置換リストの一部がうまく読み込めませんでした' 'error')
}
Plugin:register_note_view_interruptor(f)
["みょうじ", "漢字苗字"], ["なまえ", "漢字名前"], ["にゃまえ", "漢字名前"], ["ミョウジ", "カタカナ苗字"], ["ナマエ", "カタカナ名前"], ["ニャマエ", "カタカナ名前"]$[fg.color=999 変換後名]