Last active
December 10, 2015 18:08
-
-
Save mtrovo/4472166 to your computer and use it in GitHub Desktop.
GreaseMonkey script for enabling shortcuts modifiers (eg. ALT + R for Fast Reblog) on Linux platform.
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 Tumblr Shortcut Modifiers for Linux | |
// @namespace mtrovo | |
// @include http://www.tumblr.com/* | |
// @grant GM_log | |
// @version 1 | |
// ==/UserScript== | |
var KeyCommandsForLinux = (function ($) { | |
return unsafeWindow.Backbone.View.extend({ | |
el: 'body', | |
suspended: false, | |
events: { | |
'keydown': 'keydown', | |
'keyup': 'keyup' | |
}, | |
'keydown': function (e) { | |
if (navigator.platform.startsWith("Linux")) { | |
var code = e.charCode ? e.charCode : e.keyCode, | |
modified = (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey), | |
i; | |
var ctx = unsafeWindow.Tumblr.KeyCommands; | |
if (e.altKey && code == 9) { | |
ctx.blog_switcher({ | |
toggle: 'start', | |
shift: e.shiftKey | |
}); | |
return false | |
} | |
if (e.altKey && code == 192) { | |
ctx.blog_switcher({ | |
toggle: 'start', | |
shift: true | |
}); | |
return false | |
} | |
if (e.altKey && code == 27 && ctx.tab_switching) { | |
ctx.blog_switcher({ | |
toggle: 'cancel' | |
}); | |
return false | |
} | |
if (e.altKey && code == 37 && ctx.tab_switching) { | |
ctx.blog_switcher({ | |
toggle: 'start', | |
shift: true | |
}); | |
return false | |
} | |
if (e.altKey && code == 39 && ctx.tab_switching) { | |
ctx.blog_switcher({ | |
toggle: 'start' | |
}); | |
return false | |
} | |
if (e.altKey && code == 82 && ctx.logged_in) { | |
for (i in ctx.post_positions) { | |
ctx.fast_reblog(i, ctx.post_positions[i]) | |
} | |
return false | |
} | |
if (e.altKey && code == 69 && ctx.logged_in) { | |
for (i in ctx.post_positions) { | |
ctx.fast_reblog(i, ctx.post_positions[i], true) | |
} | |
return false | |
} | |
} | |
}, | |
'keyup': function (e) { | |
var code = e.charCode ? e.charCode : e.keyCode, | |
modified = (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey); | |
if (navigator.platform.startsWith("Linux")) { | |
var ctx = unsafeWindow.Tumblr.KeyCommands; | |
if (!e.altKey && ctx.tab_switching) { | |
ctx.blog_switcher({ | |
toggle: 'stop' | |
}); | |
return false | |
} | |
} | |
} | |
}); | |
})(unsafeWindow.jQuery); | |
unsafeWindow.jQuery(document).ready(function ($) { | |
new KeyCommandsForLinux(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment