文字を汚ない画像にする

    @@ -26,6 +26,13 @@ tti.width = node.parentNode.offsetWidth; tti.font = style.font; tti.color = style.color; - tti.background = (style.backgroundColor == 'rgba(0, 0, 0, 0)' ? '#ffffff' : style.backgroundColor); + tti.background = style.backgroundColor; + if (tti.background == 'rgba(0, 0, 0, 0)') { + if (tti.color == 'rgb(255, 255, 255)') { + tti.background = 'rgb(0, 0, 0)'; + } else { + tti.background = 'rgb(255, 255, 255)'; + } + } node.parentNode.replaceChild(tti.createImage('image/jpeg', 0.01), node); });
  • /*
     * @title 文字を汚ない画像にする
     * @description 文字を汚ない画像にするやつ 例 → http://dl.dropbox.com/u/8270034/g/e333618264368ada4432c70ffe376447.png
     * @include http://*
     * @license MIT License
     * @require http://hitode909.appspot.com/text_to_image/text_to_image.js
     */
    
    var walkTextNode = function(node, callback) {
        var children = node.childNodes;
        for (var i = 0, len = children.length; i < len; i++) {
            var child = children[i];
            if (child.nodeType == 3) {
                callback(child);
            } else if (child.childNodes.length > 0 && child.offsetWidth > 0 && ! node.tagName.match(/script/)) {
                walkTextNode(child, callback);
            }
        }
    }
    
    walkTextNode(document.body, function(node) {
        if (node.textContent.match(/^\s+$/)) return;
        var style = document.defaultView.getComputedStyle(node.parentNode, '');
        var tti = new TextToImage;
        tti.text = node.textContent;
        tti.width = node.parentNode.offsetWidth;
        tti.font = style.font;
        tti.color = style.color;
        tti.background = style.backgroundColor;
        if (tti.background == 'rgba(0, 0, 0, 0)') {
            if (tti.color == 'rgb(255, 255, 255)') {
                tti.background = 'rgb(0, 0, 0)';
            } else {
                tti.background = 'rgb(255, 255, 255)';
            }
        }
        node.parentNode.replaceChild(tti.createImage('image/jpeg', 0.01), node);
    });
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2012/03/24 13:23:50 - 2012-03-24
  2. 2012/03/24 13:07:59 - 2012-03-24
  3. 2012/03/24 13:07:45 - 2012-03-24
  4. 2012/03/24 13:00:24 - 2012-03-24
  5. 2012/03/24 12:59:36 - 2012-03-24