My favorites | Sign in
Project Logo
Project hosting will be READ-ONLY Wednesday at 8am PST due to brief network maintenance.
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// ==UserScript==
// @name Friendfeed Keyboard Shortcuts
// @namespace http://userscripts.org/users/44035
// @description Like Google Reader keyboard shortcuts, but for FF! w00t.
// @include http://friendfeed.com/*
// @include http://beta.friendfeed.com/*
// @exclude http://friendfeed.com/settings*
// ==/UserScript==

unsafeWindow.document.onkeydown = KeyCheck;
unsafeWindow.document.onkeyup = checkModifier;
unsafeWindow.document.onclick = mouseUse;


var currentEntry;
var modifierShift = 0;
var f=0;

function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}

addGlobalStyle('div.selectedEntry { margin-left: -12px; padding-left: 7px; border-left: 5px solid #D7E4F4;}');

function GM_wait()
{
if(typeof unsafeWindow.jQuery == 'undefined')
{
window.setTimeout(GM_wait,100);
}
else
{
$ = unsafeWindow.jQuery; letsJQuery();
}
}

function addHandlers() { // if "Comment" link is clicked, go into typing mode
$('.feed').find('.l_comment').each(function () {
this.onclick = function () {
unsafeWindow.document.onkeydown = typingComment;
unsafeWindow.document.onclick = typingMouse;
}
});
$('input.query').each(function () {
this.onfocus = function () {
unsafeWindow.document.onkeydown = typingComment;
unsafeWindow.document.onclick = typingMouse;
}
this.onblur = function () {
unsafeWindow.document.onkeydown = KeyCheck;
unsafeWindow.document.onclick = mouseUse;
}
});
$('.sharebox textarea.title').each(function () {
this.onfocus = function () {
unsafeWindow.document.onkeydown = typingComment;
unsafeWindow.document.onclick = typingMouse;
}
this.onblur = function () {
this.onblur;
unsafeWindow.document.onkeydown = KeyCheck;
unsafeWindow.document.onclick = mouseUse;
}
});
}

GM_wait();
addHandlers();


function mouseUse(event) {
var tgt = event.target;
if ($(tgt).parents('.cluster').length != 0) {
var oldEntry = currentEntry;
oldEntry.toggleClass('selectedEntry');
currentEntry = $(tgt).parents('.cluster').toggleClass('selectedEntry');
}
}

function checkModifier(event) {

var key = event.keyCode;
if (key == 16) modifierShift = 0;

}

function KeyCheck(event)
{
var key = event.keyCode;
switch(key)
{
case 74: //j -- suggested behaviour when at bottom of page: move to first entry on next page (and vice versa with 'k')
var oldEntry = currentEntry;
currentEntry = currentEntry.toggleClass('selectedEntry').next('.cluster').toggleClass('selectedEntry');
if(currentEntry.length != 0)
{
$.scrollTo( currentEntry, 1, {offset: -100} );
}
else
{
currentEntry = oldEntry.toggleClass('selectedEntry');
}
break;
case 75: //k
currentEntry = currentEntry.toggleClass('selectedEntry').prev('.cluster').toggleClass('selectedEntry');
if(currentEntry.length != 0)
{
$.scrollTo( currentEntry, 1, {offset: -100} );
}
else
{
currentEntry = $('.feed .cluster:first').toggleClass('selectedEntry');
}
break;
case 72: //h
var link = currentEntry.find('.l_hideone');
if (link.length == 0) link = currentEntry.find('.l_unhideone');
triggerClick(link);
break;
case 69: //e
triggerClick(currentEntry.find('.l_expandcomments'));
break;
case 76: //l
var link = currentEntry.find('.l_unlike');
if (link.length == 0) link = currentEntry.find('.l_like');
triggerClick(link);
break;
case 67: //c -- todo: clear out comment form (the 'c' keypress appears in the form)
unsafeWindow.document.onkeydown = typingComment;
unsafeWindow.document.onclick = typingMouse;
triggerClick(currentEntry.find('.l_comment'));
currentEntry.find('.commentform textarea').each(function () { this.value = ''; });
break;
case 13: //enter
if (f) {
openLink(currentEntry.find('.summary .l_person:first'));
endHover(currentEntry.find('.summary .l_person:first'));
break;
}
case 86: //v
openLink(currentEntry.find('.entry .main'));
break;
case 70: // f
if (!f) {
triggerHover(currentEntry.find('.summary .l_person:first'));
f=1;
} else {
endHover(currentEntry.find('.summary .l_person:first'));
f=0;
}
break;
case 77: //m
triggerClick(currentEntry.find('.l_expandmedia'));
triggerClick(currentEntry.find('.l_audio'));
triggerClick(currentEntry.find('a.l_play'));
break;
case 16: //shift
modifierShift = 1;
break;
case 191: // /
if (modifierShift) {
showHelp();
break;
}
$('input.query').each(function () { this.focus(); });
break;
case 80: //p
$('.sharebox textarea.title').each(function () { this.focus(); });
break;
case 82: // r
unsafeWindow.location.href = '/';
break;
}
}

function endHover(link) {
link.each(function () {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("mouseout", true, true);
this.dispatchEvent(evt);
});
}

function triggerHover(link) {
link.each(function () {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("mouseover", true, true);
this.dispatchEvent(evt);
});
}

// todo: make a pretty help, not just a fugly alert box.
function showHelp() {
alert("friendfeed keyboard shortcuts:\nj: down (next entry)\nk: up (previous entry)\nl: like/unlike\n" +
"c: comment\nh: hide/unhide\ne: expand comments\nm: expand media\nv or ENTER: open link in new tab/window\n" +
"f: show/hide poster's userpopup\n\t(if userpopup open: ENTER: open user's page)\n" +
"\np: post\n/: search\nr: refresh page\n?: this help");
}

function openLink(link) {
link.each(function () {
unsafeWindow.open(this.href);
});
}

function triggerClick(link) {
link.each(function () {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("click", true, true);
this.dispatchEvent(evt);
});
}

function typingMouse(event) {
if (event.target.value == "Post" || event.target.value == "Search") {
unsafeWindow.document.onkeydown = KeyCheck;
unsafeWindow.document.onclick = mouseUse;
return;
}
}

function typingComment(event) {
var key = event.keyCode;
if (key == 13) {
unsafeWindow.document.onkeydown = KeyCheck;
unsafeWindow.document.onclick = mouseUse;
}
if (key == 27) {
triggerClick(currentEntry.find('.l_cancelcomment'));
unsafeWindow.document.onkeydown = KeyCheck;
unsafeWindow.document.onclick = mouseUse;
}
// todo: cancelling the comment form via mouseclick needs to return the onkeydown event handlers to KeyCheck, mouseUse
}



var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}

function letsJQuery()
{
currentEntry = $('.feed .cluster:first');
currentEntry.toggleClass('selectedEntry');

at = new RegExp(/name="at" value="([\S\s]*?)"/ig).exec(unsafeWindow.gShareMainForm);
//console.log(at[1].toString());
}
Show details Hide details

Change log

r3 by detectx on Sep 04, 2008   Diff
v0.3
Go to: 
Sign in to write a code review

Older revisions

r2 by detectx on Aug 30, 2008   Diff
first!
All revisions of this file

File info

Size: 8448 bytes, 253 lines
Hosted by Google Code