Share on Twitter

  • /*
     * @title Share on Twitter
     * @description my bookmarklet
     * @include *
     * @license MIT License
     * @require 
     */
    // タイトルを""で囲むように変更
    // http://dev.twitter.com/pages/share_bookmarklet
    (function () {
        function B(L) {
            var M = [],
                K = 0,
                J = L.length;
            for (; K < J; K++) {
                M.push(L[K])
            }
            return M
        }
    
        function G(J) {
            return encodeURIComponent(J).replace(/\+/g, "%2B")
        }
    
        function C(L) {
            var K = [],
                J;
            for (J in L) {
                if (L[J] !== null && typeof L[J] !== "undefined") {
                    K.push(G(J) + "=" + G(L[J]))
                }
            }
            return K.sort().join("&")
        }
    
        function H() {
            var K = document.getElementsByTagName("a"),
                Q = document.getElementsByTagName("link"),
                J = /\bme\b/,
                M = /^https?\:\/\/(www\.)?twitter.com\/([a-zA-Z0-9_]+)$/,
                P = B(K).concat(B(Q)),
                O, S, L, N = 0,
                R;
            for (;
            (R = P[N]); N++) {
                S = R.getAttribute("rel");
                L = R.getAttribute("href");
                if (S && L && S.match(J) && (O = L.match(M))) {
                    return O[2]
                }
            }
        }
    
        function F(K) {
            var J;
            if (K.match(/^https?:\/\//)) {
                return K
            } else {
                J = location.host;
                if (location.port.length > 0) {
                    J += ":" + location.port
                }
                return [location.protocol, "//", J, K].join("")
            }
        }
    
        function I() {
            var J = document.getElementsByTagName("link");
            for (var K = 0, L;
            (L = J[K]); K++) {
                if (L.getAttribute("rel") == "canonical") {
                    return F(L.getAttribute("href"))
                }
            }
            return null
        }
        var D = (function () {
            var K = {
                text: '"' + decodeURIComponent(document.title) + '"',
                url: (I() || location.href),
                _: ((new Date()).getTime())
            };
            var J = H();
            if (J) {
                K.via = J
            }
            return C(K)
        }());
        var E=window,A = "http://twitter.com/share?" + D;
        if (E && E.open) {
            location.href = A;
        } else {
            window.location.href = A
        }
    })();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2010/08/21 17:59:12 - 2010-08-21
  2. 2010/08/21 17:58:55 - 2010-08-21
  3. 2010/08/21 17:54:35 - 2010-08-21
  4. 2010/08/21 17:53:44 - 2010-08-21
  5. 2010/08/21 17:53:17 - 2010-08-21