darekagakaku random

    @@ -3,9 +3,9 @@ * @description darekagakaku nikki wo random ni hyouji * @include http://darekagakaku.herokuapp.com/* * @license MIT License - * @require */ + function trim(num, l) { if (num < 0) { num = -(num); @@ -20,24 +20,22 @@ } return num; }; - -function vday() { - now = new Date(); - bottom = new Date("Feburary 17, 2012"); /* http://darekagakaku.herokuapp.com/v/2012-02-17 */ - max = now.getTime(); - min = bottom.getTime(); +function rday(max, min) { + max = max.getTime(); + min = min.getTime(); rd = new Date(Math.floor(Math.random() * (max - min) + min)); d = trim(rd.getFullYear(), 4) + "-" + trim(rd.getMonth() + 1, 2) + "-" + trim(rd.getDate(), 2); - return "/v/" + d; + return d; } - -function go() { - path = vday(); +now = new Date(); +bottom = new Date("Feburary 17, 2012"); /* http://darekagakaku.herokuapp.com/v/2012-02-17 */ +path = "/v/" + rday(now, bottom); +function go(){ if (location.pathname != path) { location.pathname = path; } else { - //go(); - location.pathname = "/a"; + go(); + //location.pathname = "/a"; } } go();
  • /*
     * @title darekagakaku random
     * @description darekagakaku nikki wo random ni hyouji
     * @include http://darekagakaku.herokuapp.com/*
     * @license MIT License
     */
    
    
    function trim(num, l) {
      if (num < 0) {
        num = -(num);
      }
      if (typeof (num) != 'string') {
        num = '' + num;
      }
      var s = l - num.length;
      while (s > 0) {
        num = '0' + num;
        --s;
      }
      return num;
    };
    function rday(max, min) {
      max = max.getTime();
      min = min.getTime();
      rd = new Date(Math.floor(Math.random() * (max - min) + min));
      d = trim(rd.getFullYear(), 4) + "-" + trim(rd.getMonth() + 1, 2) + "-" + trim(rd.getDate(), 2);
      return d;
    }
    now = new Date();
    bottom = new Date("Feburary 17, 2012"); /* http://darekagakaku.herokuapp.com/v/2012-02-17 */
    path = "/v/" + rday(now, bottom);
    function go(){
      if (location.pathname != path) {
        location.pathname = path;
      } else {
        go();
        //location.pathname = "/a";
      }
    }
    go();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2012/03/29 18:25:30 - 2012-03-29
  2. 2012/03/28 17:48:46 - 2012-03-28
  3. 2012/03/13 19:48:18 - 2012-03-13
  4. 2012/03/13 19:46:11 - 2012-03-13