大雨注意報 (endless summer on dashboard 起動セズ)
なにぃぃぃ @taizooo tumblrのパス部分dashboard/1てやってもdashboard/に戻されちゃうようになってる。手入力/1000/*で夏は動くけど
- http://taizooo.tumblr.com/post/78498835/endless-summer-on-dashboard-ver-0-0-3-1
- http://jihou.tumblr.com/api/read
- http://jihou.tumblr.com/api/read?num=1
<tumblr version="1.0"> − <tumblelog name="jihou" timezone="Asia/Tokyo" title="jihou"> +0900(JST) − <feeds> <feed id="199786" url="http://twitter.com/statuses/user_timeline/11084662.rss" import-type="regular-no-title" next-update-in-seconds="1452" title="Twitter / jihou"/> </feeds> </tumblelog> − <posts start="0" total="7016"> − <post id="83297833" url="http://jihou.tumblr.com/post/83297833" type="regular" date-gmt="2009-03-04 00:46:51 GMT" date="Wed, 04 Mar 2009 09:46:51" unix-timestamp="1236127611" feed-item="http://twitter.com/jihou/statuses/1276268848" from-feed-id="199786"> <regular-body>【時報】9時をお知らせします。</regular-body> </post> </posts> </tumblr>
2009/3/4 の今現在 post id="83297833"
var tumblr_api_read = {"tumblelog":{"title":"jihou","description":"+0900\uff08JST\uff09","name":"jihou","timezone":"Asia\/Tokyo","cname":false,"feeds":[{"id":199786,"title":"Twitter \/ jihou","attribution":null,"error":0,"error_text":null,"url":null,"import-type":"regular-no-title","next-update-in-seconds":1052}]},"posts-start":0,"posts-total":7024,"posts-type":false,"posts":[{"id":83405724,"url":"http:\/\/jihou.tumblr.com\/post\/83405724","type":"regular","date-gmt":"2009-03-04 08:38:12 GMT","date":"Wed, 04 Mar 2009 17:38:12","bookmarklet":0,"mobile":0,"feed-item":"http:\/\/twitter.com\/jihou\/statuses\/1277726404","from-feed-id":199786,"unix-timestamp":1236155892,"regular-title":"","regular-body":"\u3010\u6642\u5831\u301117\u6642\u3092\u304a\u77e5\u3089\u305b\u3057\u307e\u3059\u3002"}]};
GM_xmlhttpRequest( { method: 'GET', url: 'http://' + window.location.host + '/api/read?num=1', onload: function(res) { var doc = (new DOMParser()).parseFromString( res.responseText, 'application/xml'); var total = doc.evaluate( '//posts/@total', doc, null, XPathResult.NUMBER_TYPE, null ).numberValue; var pages = Math.ceil(total / postsPerPage); var pageNum = Math.ceil(Math.random() * pages); var uri = 'http://' + window.location.host + '/page/' + pageNum; var shuffleElem = document.createElement('p'); shuffleElem.className = 'shuffle'; shuffleElem.innerHTML = '<a href="' + uri + '" style="' + style + '">Shuffle</a>'; document.body.appendChild(shuffleElem); }
コッチの場合 //post/@id
か。これを GM_setValue
すればいいのだろうけど、発火するたび、取りにいくのはマズイよなあ。AutoPagerize の SITEINFO がどうやっているか見てみるか。もしくは youpy の wedata utility。
function summerFilter(doc, url, info){ var content_element = $X('id("posts")', doc)[0]; content_element.className = 'autopagerize_page_element'; var a = $X('id("pagination")/a[contains(text(), "Next page")]',doc); if (a.length) a = a[0]; else return; r = Math.floor(Math.random() * GM_getValue('postno', ' 83297833')); a.href = 'http://www.tumblr.com/dashboard/1000/' + r; a.className = 'autopagerize_nextlink'; a.rel = 'next'; }
6000000 から 83297833 に変更
// wedata utility for Greasemonkey // usage /* // ==UserScript== // @name foo bar // @namespace http://baz.com // @require http://gist.github.com/raw/34615/04333b7e307eb029462680e4f4cf961f72f4324c // ==/UserScript== var DATABASE_URL = 'http://wedata.net/databases/XXX/items.json'; var database = new Wedata.Database(DATABASE_URL); database.get(function(items) { items.forEach(function(item) { // do something }); }); // clear cache GM_registerMenuCommand('XXX - clear cache', function() { database.clearCache(); }); */ var Wedata = {}; Wedata.Database = function(url) { this.items = []; this.expires = 24 * 60 * 60 * 1000; // 1 day this.url = url; }; Wedata.Database.prototype.get = function(callback) { var self = this; var cacheInfo; if(cacheInfo = Wedata.Cache.get(self.url)) { self.items = cacheInfo; callback(self.items); } else { GM_xmlhttpRequest({ method : "GET", url : self.url, onload : function(res) { self.items = eval('(' + res.responseText + ')'); callback(self.items); Wedata.Cache.set(self.url, self.items, self.expires); } }); } }; Wedata.Database.prototype.clearCache = function() { Wedata.Cache.set(this.url, null, 0); } Wedata.Cache = {}; Wedata.Cache.set = function(key, value, expire) { var expire = new Date().getTime() + expire; GM_setValue(key, uneval({ value: value, expire: expire })); }; Wedata.Cache.get = function(key) { var cached = eval(GM_getValue(key)); if(!cached) { return; } if(cached.expire > new Date().getTime()) { return cached.value; } return; };