Created
November 10, 2010 07:38
-
-
Save taizooo/670503 to your computer and use it in GitHub Desktop.
via http://coderepos.org/share/browser/lang/javascript/userscripts/playontumblr.user.js?rev=35880 & ref http://bardiche.posterous.com/33022839
This file contains hidden or 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== | |
// @name play on tumblr | |
// @namespace tag:[email protected],2008-04-03:/coderepos.org | |
// @description play current image or video on tumblr dashboard with 'ENTER' key. open notes with 'h' key. like it with 'l' key. if won't work, pray on tumblr! | |
// @include http://www.tumblr.com/dashboard* | |
// @include http://www.tumblr.com/show/* | |
// @include http://www.tumblr.com/tumblelog/* | |
// @include http://www.tumblr.com/tagged/* | |
// ==/UserScript== | |
(function() { | |
var boot = function() { | |
with (window.Minibuffer) { | |
var click = function(n) { | |
var e = document.createEvent('MouseEvents'); | |
e.initMouseEvent("click",true,true,unsafeWindow,1,10,50,10,50,0,0,0,0,1,n); | |
n.dispatchEvent(e); | |
}; | |
addShortcutkey({ | |
key: "RET", | |
description: 'tumblr.play', | |
command: function() { | |
try { execute( 'tumblr.play', execute('current-node')); } catch (e) { } | |
}}); | |
addShortcutkey({ | |
key: "h", | |
description: 'tumblr.reblogcount', | |
command: function() { | |
try { execute( 'tumblr.reblogcount', execute('current-node')); } catch (e) { } | |
}}); | |
addShortcutkey({ | |
key: "l", | |
description: 'tumblr.like', | |
command: function() { | |
try { execute( 'tumblr.like', execute('current-node')); } catch(e) { } | |
}}); | |
addCommand({ | |
name: 'tumblr.play', | |
command: function(stdin) { | |
try { | |
if (!stdin.length) stdin = execute('current-node'); | |
var img = $X('.//div[starts-with(@id, "highres_photo")]', stdin[0]); | |
for (var n = 0; n < img.length; n++) { | |
if (img[n].style.display != 'none') { | |
click($X('./a', img[n])[0]); | |
return stdin; | |
} | |
else{ | |
click($X('./preceding-sibling::a[1]', img[n])[0]); | |
return stdin; | |
} | |
} | |
var mov = $X('.//div[contains(@id,"watch_") and .//a]', stdin[0]); | |
for (var n = 0; n < mov.length; n++) { | |
if (mov[n].style.display != 'none') { | |
click($X('.//a', mov[n])[0]); | |
return stdin; | |
} | |
} | |
var timg = $X('.//img[contains(@src,"media.tumblr.com/tumblr_")]', stdin[0]); | |
for (var n = 0; n < timg.length; n++) { | |
click(timg[n]); | |
} | |
return stdin; | |
} catch (e) { } | |
return stdin; | |
}}); | |
addCommand({ | |
name: 'tumblr.reblogcount', | |
command: function(stdin) { | |
try { | |
if (!stdin.length) stdin = execute('current-node'); | |
var count = $X('.//a[contains(concat(" ",@class," "), " reblog_count ")]', stdin[0]); | |
for (var n = 0; n < count.length; n++) { | |
click(count[n]); | |
return stdin; | |
} | |
} catch (e) { } | |
return stdin; | |
}}); | |
addCommand({ | |
name: "tumblr.like", | |
command: function(stdin) { | |
try { | |
if (!stdin.length) stdin = execute('current-node'); | |
var count = $X('.//a[contains(concat(" ",@class," "), " like_button ")]', stdin[0]); | |
for (var n = 0; n < count.length; n++) { | |
if(!count[n].clientWidth) continue; | |
click(count[n]); | |
return stdin; | |
} | |
} catch(e) {} | |
return stdin; | |
}}); | |
} | |
} | |
if (window.Minibuffer) { | |
boot(); | |
} else { | |
window.addEventListener('GM_MinibufferLoaded', boot, false); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment