51
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

あたし 30 代だけど夏のラ王のサイトが読めない

Last updated at Posted at 2017-06-27

あたし 30 代だけど夏のラ王のサイトが読めない

514355911513
( ^ω^)
読めない ...

www.rao.jp-natsuno_rao-before.jpg

そんなあなた (僕も含む) のために JavaScript の力で何とかしてみました。

/**
 * @fileOverview 夏のラ王のなんかいなあんごうをかいどくするすくりぷと
 */

(() => {

  /* 変換テーブル */
  const table = `あいうえおABCDE
かきくけこFGHIJ
さしすせそKLMNO
たちつてとPQRST
なにぬねのUVWXY
はひふへほZ?!-/
まみむめも¥&   
や(ゆ)よ*#   
らりるれろ12345
わをん゛°67890`;

  /* テーブルを 2 次元配列にする */
  const MAT = table.split('\n').map(a => {
    return a.split('');
  });

  /**
   * 2 桁の番号を文字にする
   * @param {string} nn
   * @returns {string}
   */
  const charAtPokebel = nn => {
    const m = nn.split('').slice(0, 2).map(n => {
      return n - 1 < 0 ? 9 : n - 1;
    });
    return MAT[m[0]][m[1]];
  };

  /**
   * ポケベル風テキストを含む Node 一覧を取得
   * @param {HTMLElement} node
   * @returns {Array}
   */
  const getPokebelTextNode = (node) => {
    const nodes = [];
    const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null, false);
    let el;
    while (el = walker.nextNode()) {
      if (/\d+/.test(el.textContent)) {
        nodes.push(el);
      }
    }
    return nodes;
  };

  /**
   * 変換する
   * @param {HTMLElement} node
   */
  const convert = (node) => {
    getPokebelTextNode(node)
    .forEach((el) => {
      el.parentNode.style.whiteSpace = 'nowrap'; // 改行されると困るので阻止する
      el.textContent = el.textContent.replace(/(\d{1,2})/g, (m) => {
        return charAtPokebel(m);
      });
    });
  };

  convert(document);

})();

ブックマークレットにしたためましたのでお使いください。

javascript:(function(){var d="\u3042\u3044\u3046\u3048\u304a\uff21\uff22\uff23\uff24\uff25 \u304b\u304d\u304f\u3051\u3053\uff26\uff27\uff28\uff29\uff2a \u3055\u3057\u3059\u305b\u305d\uff2b\uff2c\uff2d\uff2e\uff2f \u305f\u3061\u3064\u3066\u3068\uff30\uff31\uff32\uff33\uff34 \u306a\u306b\u306c\u306d\u306e\uff35\uff36\uff37\uff38\uff39 \u306f\u3072\u3075\u3078\u307b\uff3a\uff1f\uff01\uff0d\uff0f \u307e\u307f\u3080\u3081\u3082\uffe5\uff06 \u3084\uff08\u3086\uff09\u3088\uff0a\uff03 \u3089\u308a\u308b\u308c\u308d\uff11\uff12\uff13\uff14\uff15 \u308f\u3092\u3093\u309b\u00b0\uff16\uff17\uff18\uff19\uff10".split(" ").map(function(a){return a.split("")}),e=function(a){a=a.split("").slice(0,2).map(function(a){return 0>a-1?9:a-1});return d[a[0]][a[1]]},f=function(a){var c=[];a=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,null,!1);for(var b;b=a.nextNode();)/\d+/.test(b.textContent)&&c.push(b);return c};(function(a){f(a).forEach(function(a){a.parentNode.style.whiteSpace="nowrap";a.textContent=a.textContent.replace(/(\d{1,2})/g,function(a){return e(a)})})})(document)})();

やったぜ (画像はムリですゆるしてください)

www.rao.jp-natsuno_rao-after.jpg

51
7
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
51
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?