Sunday 10 January 2010

Fixing Twitter for Chrome with User JS

I'm a rather conservative Twitter user and prefer web interface to all the others. The only thing in it that have been bugging me since I've started using it was impossibility of submitting tweet with Ctrl + Enter shortcut. And today I've fixed that (yeap, I'm damn proud of myself!) using User JS script for Chrome.

Yes, it only fixes Twitter in Chrome and may possibly fix it in Firefox with GreaseMonkey (I did not check it!).

So, first of all - make your Chrome accept User JS.

1. Switch to development channel of Chrome
2. Enable User JS in Chrome using "--enable-user-scripts" shortcut flag as it is described here
3. Restart Chrome
4. Copy this code and paste it to file named Twitter.user.js :

// ==UserScript==
// @name Twitter extensions script
// @description Short script that gives some features I really miss like Ctrl + Enter way to submit tweets.
// @version 0.1
// @include http://**
// ==/UserScript==

console.log('Started Twitter script');

var txtStatus = document.getElementById('status');
if (txtStatus == null) {
txtStatus.onkeypress = function (e) {
e = e || window.event;
var keyCode = e.keyCode || e.which;

var ctrlKeyPressed = e.ctrlKey;
var enterKeyPressed = keyCode == 13 || keyCode == 10;

if (ctrlKeyPressed && enterKeyPressed) {
console.log('trying to submit tweet...');
var submitTweetButton = document.getElementById('update-submit');;

return false;

5. Drag and drop this file to opened Chrome
6. Accept script installation
7. Enjoy Ctrl + Enter shortcut in Twitter web interface! :)

No comments: