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('/');
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('/');
- https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects/Array/pop
- https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects/Array
- https://developer.mozilla.org/ja/JavaScript/Reference/Global_Objects
- https://developer.mozilla.org/ja/JavaScript/Reference
- https://developer.mozilla.org/ja/JavaScript
- 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('/');
習作
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; }
■
javascript: (function () { var m = document.createElement("meta"); m.name = "viewport"; m.content = "width=" (orientation ? 2048 : 1536)",initial-scale=0.5"; document.head.appendChild(m) })()
■
2004年、まだ JavaScript の威力を人が知るには至らず。
Web のコッチ側とアッチ側はバラバラだった訳です。