darekagakaku days--

    @@ -10,46 +10,31 @@ // - code beautify // - peitit refactoring -// TODO create dkkDate{} and encapsulation methods and property (function () { - var trim = function (num, l) { - if (num < 0) { - num = -(num); // absolutize: Math.abs(num) - } - if (typeof (num) !== 'string') { - num = '' + num; // stringfy: String(num) - } - var s = l - num.length; // zero-fill / zero-padding: slice(-l) - while(s > 0) { - num = '0' + num; - --s; - } - return num; - }; - - var toDBDateString = function (date) { + var toDBdateString = function (date) { + // absolutize, stringfy, digitalize, zeropadding + var paddingSlice = function (num, digit) { + return ('0' + Math.abs(num)).slice(-(Number(digit))); + }; var y = date.getFullYear(), - m = date.getMonth() + 1, + m = date.getMonth() + 1, // display month: 1-12 d = date.getDate(); - return trim(y, 4) + '-' + trim(m, 2) + '-' + trim(d, 2); + return paddingSlice(y, 4) + '-' + paddingSlice(m, 2) + '-' + paddingSlice(d, 2); }; (function () { var date = location.pathname.slice(3).split('-'); if (!date || date.length < 3) return; - var year = date[0], - month = date[1] - 1, - day = date[2]; - - var eve = new Date(year, month, day); - eve.setDate(eve.getDate() - 1); // -1day + // better be assert + var eve = new Date(date[0], (date[1] - 1), date[2]); // innner month: 0-11 + eve.setDate(eve.getDate() - 1); // previous day var origin = 'https://darekagakaku.herokuapp.com/'; if (location.href.indexOf(origin) === -1) { location.href = origin; } else { - location.pathname = '/v/' + toDBDateString(eve); + location.pathname = '/v/' + toDBdateString(eve); } })(); })();
  • /*
     * @title darekagakaku timemachine
     * @description dive into darekagakaku. more deep, deep, deeper
     * @include http://darekagakaku.herokuapp.com/*
     * @include https://darekagakaku.herokuapp.com/*
     * @license MIT License
     * @see http://let.hatelabo.jp/taizooo/let/gYC-ycuH_KPtfg (Fork of)
     */
    // [Changes]
    // - code beautify
    // - peitit refactoring
    
    (function () {
        var toDBdateString = function (date) {
            // absolutize, stringfy, digitalize, zeropadding
            var paddingSlice = function (num, digit) {
                return ('0' + Math.abs(num)).slice(-(Number(digit)));  
            };
            var y = date.getFullYear(),
                m = date.getMonth() + 1, // display month: 1-12
                d = date.getDate();
            return paddingSlice(y, 4) + '-' + paddingSlice(m, 2) + '-' + paddingSlice(d, 2);
        };
    
        (function () {
            var date = location.pathname.slice(3).split('-');
            if (!date || date.length < 3) return;
            
            // better be assert
            var eve = new Date(date[0], (date[1] - 1), date[2]); // innner month: 0-11
            eve.setDate(eve.getDate() - 1); // previous day
            
            var origin = 'https://darekagakaku.herokuapp.com/';
            if (location.href.indexOf(origin) === -1) {
                location.href = origin;
            } else {
                location.pathname = '/v/' + toDBdateString(eve);
            }
        })();
    })();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2012/05/04 00:08:07 - 2012-05-04
  2. 2012/05/03 06:11:16 - 2012-05-03
  3. 2012/05/03 06:10:10 - 2012-05-03
  4. 2012/05/03 06:05:50 - 2012-05-03
  5. 2012/05/03 05:46:55 - 2012-05-03
  6. 2012/05/03 02:54:37 - 2012-05-03
  7. 2012/05/03 02:54:27 - 2012-05-03