Hatena::Let Omikuji

    @@ -1,14 +1,17 @@ /* - * @title Hatena::Let::Omikuji + * @title Hatena::Let Omikuji * @description Hatena::Let Fortune cookie * @include http://let.hatelabo.jp/* * @include https://let.hatelabo.jp/* * @license MIT License http://nrm.mit-license.org/2012 - * @author noromanba (http://flavors.me/noromanba) - * @require + * @author noromanba http://flavors.me/noromanba + * @javascript_url */ -// TBD feedback indicator +// TBD +// - feedback indicator +// - replace JSDeferred to ES6 Promise +// - replace to ES6 (function () { if (location.hostname !== 'let.hatelabo.jp') { location.href = 'http://let.hatelabo.jp'; @@ -19,15 +22,23 @@ return Math.floor(Math.random() * (Number(max) + 1)); }; - // c.f. http://cho45.stfuawsc.com/jsdeferred/ - // http://cho45.stfuawsc.com/jsdeferred/doc/ - // http://gihyo.jp/dev/feature/01/jsdeferred/ - Ten.Deferred. // if you want to use 'Deferred' in globaly, replace to 'Ten.Deferred.define();' + var Ten = window.Ten; + // JSDeferred c.f. + // http://cho45.stfuawsc.com/jsdeferred/ + // http://cho45.stfuawsc.com/jsdeferred/doc/ + // http://gihyo.jp/dev/feature/01/jsdeferred/ + /* + // if you want to use 'Deferred' in globally + Ten.Deferred.define(); + /*/ + Ten.Deferred. + //*/ next(function () { var D = Ten.Deferred(); + // TODO deferred-wrap to XHR for error-handling new Ten.XHR('http://let.hatelabo.jp/', null, function (req) { var countSelector = /\"top-bookmarklet-count\"\D+(\d+)/; - var total = (countSelector.exec(req.responseText) || [])[1]; + var total = (req.responseText.match(countSelector) || [])[1]; D.call(total); }); return D; @@ -36,7 +47,7 @@ if (!total) return; // TODO deferred-wrap to XHR for error-handling - // http://let.hatelabo.jp/?of=<offset> offset: 0 origin + // http://let.hatelabo.jp/?of=<OFFSET> OFFSET: 0 origin new Ten.XHR('http://let.hatelabo.jp/?of=' + random(total - 1), null, function (req) { var codeSelector = /href\="(\/[\w-]+\/let\/[\w-]+)"/g; var code, codes = []; @@ -50,7 +61,8 @@ }). error(function (e) { if (console && console.warn) { - console.warn('*error caught by Hatena::Let::Omikuji =>', e); + console.warn('*error caught by Omikuji =>', e, e.stack); } }); -})(); +})(); +
  • /*
     * @title Hatena::Let Omikuji
     * @description Hatena::Let Fortune cookie
     * @include http://let.hatelabo.jp/*
     * @include https://let.hatelabo.jp/*
     * @license MIT License http://nrm.mit-license.org/2012
     * @author noromanba http://flavors.me/noromanba
     * @javascript_url
     */
    
    // TBD
    // - feedback indicator
    // - replace JSDeferred to ES6 Promise
    // - replace to ES6
    (function () {
        if (location.hostname !== 'let.hatelabo.jp') {
            location.href = 'http://let.hatelabo.jp';
            return; // for Firefox
        }
    
        var random = function (max) {
            return Math.floor(Math.random() * (Number(max) + 1));
        };
    
        var Ten = window.Ten;
        // JSDeferred c.f.
        // http://cho45.stfuawsc.com/jsdeferred/
        // http://cho45.stfuawsc.com/jsdeferred/doc/
        // http://gihyo.jp/dev/feature/01/jsdeferred/
        /*
        // if you want to use 'Deferred' in globally
        Ten.Deferred.define();
        /*/
        Ten.Deferred.
        //*/
        next(function () {
            var D = Ten.Deferred();
            // TODO deferred-wrap to XHR for error-handling
            new Ten.XHR('http://let.hatelabo.jp/', null, function (req) {
                var countSelector = /\"top-bookmarklet-count\"\D+(\d+)/;
                var total = (req.responseText.match(countSelector) || [])[1];
                D.call(total);
            });
            return D;
        }).
        next(function (total) {
            if (!total) return;
    
            // TODO deferred-wrap to XHR for error-handling
            // http://let.hatelabo.jp/?of=<OFFSET> OFFSET: 0 origin
            new Ten.XHR('http://let.hatelabo.jp/?of=' + random(total - 1), null, function (req) {
                var codeSelector = /href\="(\/[\w-]+\/let\/[\w-]+)"/g;
                var code, codes = [];
                while ((code = codeSelector.exec(req.responseText))) {
                    codes.push(code[1]);
                }
                if (codes.length < 1) return;
    
                location.pathname = codes[random(codes.length - 1)];
            });
        }).
        error(function (e) {
            if (console && console.warn) {
                console.warn('*error caught by Omikuji =>', e, e.stack);
            }
        });
    })();
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2016/01/11 03:15:32 - 2016-01-11
  2. 2013/04/01 12:28:12 - 2013-04-01
  3. 2012/12/27 19:22:59 - 2012-12-27
  4. 2012/12/06 05:45:45 - 2012-12-06
  5. 2012/12/06 05:38:35 - 2012-12-06
  6. 2012/07/25 06:05:17 - 2012-07-25
  7. 2012/07/25 06:03:48 - 2012-07-25
  8. 2012/06/03 09:27:15 - 2012-06-03
  9. 2012/02/23 17:46:18 - 2012-02-23