page++

/*
 * @title page++
 * @description page countup
 * @include http://*
 * @license MIT License
 */

var a=location.pathname.split('/');
var p=a[a.length-1];
if (/^\d+$/.test(p)) {
  p++;
  a.pop();
  a.push(p);
} else {
  a.push(2);
}
location.pathname=a.join('/');
  1. http://www.tumblr.com/show/text
  2. http://www.tumblr.com/show/text/2
  3. http://www.tumblr.com/show/text/3
  4. http://www.tumblr.com/show/text/4
  5. ...snip...
  6. http://www.tumblr.com/show/text/10

AutoPagerize 症候群

(テスト) ? (式1) : (式2)

とか

if(テスト) (式1)

より

if(テスト) {
   (式1)
} else {
   (式2)
}

とか

if(テスト) {
   (式1)
}

の方がぱっと見、何なのかわかりやすい。無駄に縦に伸びても。

こういうわけで
↓
じつは
↓
なんとか

みたいに、縦方向に処理してる?
ひょっとして AutoPagerize 脳?

cd..

/*
 * @title cd ..
 * @description up dir
 * @include http://*
 * @license MIT License
 */

a=location.pathname.split('/');
a.pop();
location.pathname=a.join('/');
  1. https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects/Array/pop
  2. https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects/Array
  3. https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects
  4. https://developer.mozilla.org/ja/JavaScript/Reference
  5. https://developer.mozilla.org/ja/JavaScript
  6. https://developer.mozilla.org/ja/

修正

/*
 * @title cd ..
 * @description up dir
 * @include http://*
 * @license MIT License
 */

a=location.pathname.split('/');
(a.pop() == '') ? a.pop() : a;
location.pathname=a.join('/');
  1. http://www.ie.u-ryukyu.ac.jp/~kono/lecture/compiler/index.html
  2. http://ie.u-ryukyu.ac.jp/~kono/lecture/compiler/
  3. http://ie.u-ryukyu.ac.jp/~kono/lecture/
  4. http://ie.u-ryukyu.ac.jp/~kono/
  5. http://ie.u-ryukyu.ac.jp/

習作

ex gkojaxlabo http://kagurazakaundergroundresistance.tumblr.com/ (最古の tumblr bot)のアーカイブから年月日を基準にランダムな post_id を生成する習作

function getRandom() {
  var a = [
    { 'year'  : '2007'
    , 'min'   : 765
    , 'max'   : 22716604
    , 'url'   : 'http://kagurazakaundergroundresistance.tumblr.com/post/22716604'
    },
    { 'year'  : '2008'
    , 'min'   : 22716605
    , 'max'   : 67666062
    , 'url'   : 'http://kagurazakaundergroundresistance.tumblr.com/post/67666062'
    },
    { 'year'  : '2009'
    , 'min'   : 67666063
    , 'max'   : 309781568
    , 'url'   : 'http://kagurazakaundergroundresistance.tumblr.com/post/309781568'
    },
    { 'year'  : '2010'
    , 'min'   : 309781569
    , 'max'   : 2542121207
    , 'url'   : 'http://kagurazakaundergroundresistance.tumblr.com/post/2542121207'
    },
    { 'year'  : '2011'
    , 'min'   : 2542121208
    , 'max'   : 15080900593
    , 'url'   : 'http://kagurazakaundergroundresistance.tumblr.com/post/15080900593'
    },
    { 'year'  : 'now'
    , 'min'   : 15080900593
    , 'max'   : 19893333892
    , 'url'   : 'http://kagurazakaundergroundresistance.tumblr.com/post/19893333892'
    }
  ]
  var c = Math.floor(Math.random() * a.length);
  var d = Math.floor(Math.random() * a[c].max - a[c].min + 1) + a[c].min;
  console.log([d, a[c].year, a[c].max, a[c].min, c]);
  return d;
}

ReblogMachine.endless_summer#choice

http://reblog.machine.mamemomonga.com/js/ReblogMachine.js から。
endless summer のために random な post_id を生成する部分。

choice: function () {
  for (var a = this.range.latest - this.range.oldest, b = [], c = 1; c <= 100; c++) b.push(Math.floor(a / 100 * c));
  a = [];
  for (c = 0; c <= 50; c++) for (var d = 0; d <= 5; d++) a.push(d);
  for (c = 0; c <= 10; c++) for (d = 6; d <= 10; d++) a.push(d);
  for (c = 10; c <= 100; c++) a.push(c);
  c = Math.floor(Math.random() * a.length);
  d = Math.floor(Math.random() * b[a[c]]) + this.range.oldest;
  console.log([d, b[a[c]] + this.range.oldest, a[c]]);
  return d
}

this.range.latest が最新の post_id で、 this.range.oldest が最古の post_id 。
ユーザー数がどんどん増えているから post 間の post_id 間隔(?)がだんだん増えていっているからそのまま Math.random() しても、新しい方の post ばかりヒットしてしまう問題がある。
だから重み付けをしているらしい。

choice: function () {
  for (var a = this.range.latest - this.range.oldest, b = [], c = 1; c <= 100; c++) {
      b.push(Math.floor(a / 100 * c));
  }
  a = [];
  for (c = 0; c <= 50; c++) {
      for (var d = 0; d <= 5; d++) {
          a.push(d);
      }
  }
  for (c = 0; c <= 10; c++) {
      for (d = 6; d <= 10; d++) {
          a.push(d);
      }
  }
  for (c = 10; c <= 100; c++) {
      a.push(c);
  }
  c = Math.floor(Math.random() * a.length);
  d = Math.floor(Math.random() * b[a[c]]) + this.range.oldest;
  console.log([d, b[a[c]] + this.range.oldest, a[c]]);
  return d;
}

2004年、まだ JavaScript の威力を人が知るには至らず。

Web のコッチ側とアッチ側はバラバラだった訳です。