Skip to content

Instantly share code, notes, and snippets.

@syoichi
Created May 7, 2012 10:20
Show Gist options
  • Save syoichi/2627067 to your computer and use it in GitHub Desktop.
Save syoichi/2627067 to your computer and use it in GitHub Desktop.
fix 2 bugs on Tumblr Dashboard.
// ==UserScript==
// @id Tumblr Dashboard bugfix
// @name Tumblr Dashboard bugfix
// @namespace http://syoichi.tumblr.com/
// @author syoichi <[email protected]>
// @version 0.0.3
// @update 2012-06-24T16:47:26.875Z(GMT+09:00)
// @description fix 2 bugs on Tumblr Dashboard.
// @include http://www.tumblr.com/dashboard*
// @include http://www.tumblr.com/show/*
// @include http://www.tumblr.com/likes*
// @include http://www.tumblr.com/liked/by/*
// @include http://www.tumblr.com/tagged/*
// @include http://www.tumblr.com/blog/*
// @exclude http://www.tumblr.com/dashboard/iframe*
// @run-at document-end
// @priority 0
// @compatibility Firefox 13.0.1(Scriptish 0.1.7), Chrome 19.0.1084.56, Safari 5.1.7(NinjaKit 0.9.1), Opera 12.00 on Windows 7 Home Premium SP1 64bit
// @charset UTF-8
// @license Public Domain
// ==/UserScript==
/*jslint browser: true, nomen: true, maxlen: 80*/
// Edition 2012-05-09
(function executeDashboardBugfix(win, doc) {
'use strict';
var loader, scriptContent;
if (!doc.querySelector('li[id^="post_"]')) {
return;
}
doc.head.appendChild(doc.createElement('style')).textContent = [
'body {',
' margin-bottom: ' + win.innerHeight + 'px !important;',
'}'
].join('\n');
loader = doc.getElementById('auto_pagination_loader');
if (!(/^(?:\/blog\/[\-\w]+)?\/show\//.test(location.pathname) && loader)) {
return;
}
scriptContent = function scriptContent(win, doc) {
var nextLink, basePath, nextPageNumber, oldProcess, fixNextPageUrl;
if (!win.next_page) {
return;
}
nextLink = doc.getElementById('next_page_link');
if (!nextLink) {
return;
}
basePath = location.pathname.replace(/\/(?:\d+)?$/, '') + '/';
nextPageNumber = Number(/(\d+)(?:\/\d+)?$/.exec(nextLink.pathname)[1]);
win.next_page = basePath + nextPageNumber;
oldProcess = win._process_auto_paginator_response;
fixNextPageUrl = function fixNextPageUrl(transport) {
oldProcess(transport);
if (!win.next_page) {
return;
}
win.next_page = basePath + (nextPageNumber += 1);
};
win._process_auto_paginator_response = fixNextPageUrl;
};
doc.head.appendChild(doc.createElement('script')).textContent =
'(' + scriptContent + '(window, document));';
}(window, document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment