From f844a47f1deb885af733220bdd018fb3966c4039 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 30 Dec 2016 11:57:17 +0900 Subject: [PATCH] Add nya filter --- .../app/common/scripts/generate-default-userdata.ls | 1 + src/web/app/common/scripts/i.ls | 2 ++ src/web/app/common/scripts/text-compiler.js | 13 ++++++++++++- src/web/app/desktop/tags/settings.tag | 12 ++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/web/app/common/scripts/generate-default-userdata.ls b/src/web/app/common/scripts/generate-default-userdata.ls index de03e9615..c13d221bb 100644 --- a/src/web/app/common/scripts/generate-default-userdata.ls +++ b/src/web/app/common/scripts/generate-default-userdata.ls @@ -22,6 +22,7 @@ module.exports = ~> data = cache: true debug: false + nya: true home: home-data return data diff --git a/src/web/app/common/scripts/i.ls b/src/web/app/common/scripts/i.ls index 5f3c016f8..888ef194d 100644 --- a/src/web/app/common/scripts/i.ls +++ b/src/web/app/common/scripts/i.ls @@ -14,3 +14,5 @@ module.exports = (me) -> if data? Object.assign me, data me.trigger \updated + + me: me diff --git a/src/web/app/common/scripts/text-compiler.js b/src/web/app/common/scripts/text-compiler.js index 9915e3335..41f496668 100644 --- a/src/web/app/common/scripts/text-compiler.js +++ b/src/web/app/common/scripts/text-compiler.js @@ -1,3 +1,5 @@ +const riot = require('riot'); + module.exports = function(tokens, canBreak, escape) { if (canBreak == null) { canBreak = true; @@ -5,7 +7,10 @@ module.exports = function(tokens, canBreak, escape) { if (escape == null) { escape = true; } - return tokens.map(function(token) { + + const me = riot.mixin('i').me; + + let text = tokens.map(function(token) { switch (token.type) { case 'text': if (escape) { @@ -27,4 +32,10 @@ module.exports = function(tokens, canBreak, escape) { return '' + token.content + ''; } }).join(''); + + if (me && me.data && me.data.nya) { + text = text.replace(/な/g, 'にゃ'); + } + + return text; } diff --git a/src/web/app/desktop/tags/settings.tag b/src/web/app/desktop/tags/settings.tag index c6c034091..2a0db236a 100644 --- a/src/web/app/desktop/tags/settings.tag +++ b/src/web/app/desktop/tags/settings.tag @@ -58,6 +58,10 @@ mk-settings input(type='checkbox', checked={ I.data.debug }, onclick={ update-debug }) p 開発者モード p デバッグ等の開発者モードを有効にします。 + label.checkbox + input(type='checkbox', checked={ I.data.nya }, onclick={ update-nya }) + p にゃに変換する + p 攻撃的な投稿が多少和らぐ可能性があります。 section.signin(show={ page == 'signin' }) h1 ログイン履歴 @@ -253,3 +257,11 @@ script. debug: @I.data.debug .then ~> @update-i! + + @update-nya = ~> + @I.data.nya = !@I.data.nya + @api \i/appdata/set do + data: JSON.stringify do + nya: @I.data.nya + .then ~> + @update-i!