LoginSignup
1
0

More than 5 years have passed since last update.

ワイルドアームズのアプリが公開されたので、テキストをWAっぽくするブックマークレットでも作る

Last updated at Posted at 2018-09-30

昔によく遊んだので、懐かしくって……(˘ω˘)
多分、需要は自分にしかないんじゃないかな!

jsを実装!

xtu.js
(function (baseDom) {
    const change = function (text) {
        return text.replace(/っ([!!])/g, function (m, p1) { return "" + p1; }).replace(/([^<ッ!!??])([!!])/g, function (m, p1, p2) { return p1 + "" + p2; });
    }
    const replace = function (dom) {
        if (["IFRAME", "SCRIPT", "NOSCRIPT", "STYLE"].indexOf(dom.tagName) >= 0) {
            return;
        }
        if (dom.children.length > 0) {
            Array.from(dom.children).forEach(replace)
        } else if (dom.innerText && dom.innerText.trim().length > 0) {
            dom.innerText = change(dom.innerText);
        }
    }
    replace(baseDom);
})(window.document.body)

scriptタグだけは書き換えずにエラーにならないようにしてみる。

ng.html
<h1>
ほげほげ!
<span>ふがふが!</span>
</h1>

ただこれだと、上みたいなサイトで上手くいかないんだよな……どうしたものかな。

最小化!

minify.js
(function(a){const c=function(d){return d.replace(/っ([!!])/g,function(e,f){return""+f}).replace(/([^<ッ!!??])([!!])/g,function(e,g,f){return g+""+f})};const b=function(d){if(["IFRAME","SCRIPT","NOSCRIPT","STYLE"].indexOf(d.tagName)>=0){return}if(d.children.length>0){Array.from(d.children).forEach(b)}else{if(d.innerText&&d.innerText.trim().length>0){d.innerText=c(d.innerText)}}};b(a)})(window.document.body);

ブックマークレット用のURLを作成!

javascript:(function(a){const c=function(d){return d.replace(/っ([!!])/g,function(e,f){return"ッ"+f}).replace(/([^<ッ!!??])([!!])/g,function(e,g,f){return g+"ッ"+f})};const b=function(d){if(["IFRAME","SCRIPT","NOSCRIPT","STYLE"].indexOf(d.tagName)>=0){return}if(d.children.length>0){Array.from(d.children).forEach(b)}else{if(d.innerText&&d.innerText.trim().length>0){d.innerText=c(d.innerText)}}};b(a)})(window.document.body);;

ブックマークへの登録!

image.png

chromeであればブックマークツールバーから、上のような形で登録ができるよ!

試さずにはいられない!

ちょっと感嘆符の勢いが足りない公式サイトでも

この通り!!

感想!

:gun:こんなことをやっていないでイベントを回ってこよう🧛

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0