Skip to content

Instantly share code, notes, and snippets.

@syoichi
Created January 13, 2012 22:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syoichi/1609210 to your computer and use it in GitHub Desktop.
Save syoichi/1609210 to your computer and use it in GitHub Desktop.
Add shortcut key T for Reblog on Tumblr Dashboard.
// ==UserScript==
// @id Reblogable
// @name Reblogable
// @namespace http://syoichi.tumblr.com/
// @version 0.0.5
// @description Add shortcut key T for Reblog 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
// ==/UserScript==
/* User Script info
license: Public Domain
confirmed:
Windows 7 Home Premium SP1 64bit:
Firefox 16.0.1(Scriptish 0.1.8)
Google Chrome 22.0.1229.94
Opera 12.02 64bit
*/
/*jslint browser: true, maxlen: 80*/
// Edition 2012-10-03
(function executeReblogable(win, doc) {
'use strict';
var KEY, KEY_CODE, POST_MARGIN_TOP;
if (!doc.querySelector('li[id^="post_"]')) {
return;
}
KEY = 't'; // or r, h, and so on.
KEY_CODE = KEY.toUpperCase().charCodeAt();
POST_MARGIN_TOP = 7;
win.addEventListener('keydown', function reblogable(evt) {
var isKey, modKey, post, nextPost, reblogButton, altClick;
isKey = evt.keyCode === KEY_CODE;
if (!isKey) {
return;
}
modKey = evt.altKey || evt.ctrlKey || evt.shiftKey || evt.metaKey;
if (modKey || evt.target.tagName !== 'BODY') {
return;
}
post = doc.elementFromPoint(win.innerWidth / 2, POST_MARGIN_TOP + 1);
if (!post) {
return;
}
reblogButton = post.querySelector('.reblog_button');
if (!reblogButton) {
return;
}
evt.stopPropagation();
nextPost = doc.querySelector('#' + post.id + ' ~ .post');
if (nextPost) {
win.scrollBy(
0,
nextPost.offsetTop - win.pageYOffset - POST_MARGIN_TOP
);
}
altClick = doc.createEvent('MouseEvent');
altClick.initMouseEvent('click',
true, true, win, 1, 0, 0, 0, 0, false, true, false, false, 0, null);
reblogButton.dispatchEvent(altClick);
}, true);
}(window, document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment