Created
March 11, 2013 14:29
-
-
Save saitamanodoruji/5134629 to your computer and use it in GitHub Desktop.
Tumblr Dashboard Fix Pagination on Show Pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @id Tumblr Dashboard Fix Pagination on Show Pages | |
// @name Tumblr Dashboard Fix Pagination on Show Pages | |
// @version 0.0.1.0 | |
// @namespace http://saitamanodoruji.tumblr.com/ | |
// @author saitamanodoruji | |
// @description | |
// @include http://www.tumblr.com/show/* | |
// @include http://www.tumblr.com/blog/*/show/* | |
// ==/UserScript== | |
// most parts are copied from: | |
// Tumblr Dashboard Filter by Post Type for Greasemonkey by cxx | |
// http://userscripts.org/scripts/show/40794 | |
// requires sharedObject.AutoPagerize | |
// cf. | |
// Firefox 17 環境でのLDRize復活への手引き(unsafeWindow不使用バージョン) - 近江在住 | |
// http://d.hatena.ne.jp/t_f_m/20121126/1353860818 | |
// AutoPagerizeもwindow共有不可の問題にはやっぱり影響受けてて、そのあたりちょっと考えてみましたよ - 近江在住 | |
// http://d.hatena.ne.jp/t_f_m/20111121/1321886246 | |
(function(){ | |
function fixPagination(doc, uri) { | |
var found = uri.match(/www\.tumblr\.com(.*?)(?:\/(\d+))?\/?(\?|$)/); | |
var base = found[1]; | |
var page = found[2] ? Number(found[2]) : 1; | |
var posts = Array.prototype.slice.call( | |
doc.querySelectorAll('li[id^="post_"]') | |
, 0); | |
var offset = posts[posts.length - 1].id.match(/\d+/)[0]; | |
var prev = base + '/' + (page - 1); | |
var next = base + '/' + (page + 1) + '?offset=' + offset; | |
var pagination = Array.prototype.slice.call( | |
doc.querySelectorAll('#pagination > a') | |
, 0); | |
pagination[0].href = (page > 1) ? prev : next; | |
if (pagination[1]) pagination[1].href = next; | |
} | |
fixPagination(document, location.href); | |
setTimeout(function(){ | |
if (sharedObject.AutoPagerize && sharedObject.AutoPagerize.addDocumentFilter) { | |
sharedObject.AutoPagerize.addDocumentFilter(fixPagination); | |
} | |
}, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment