-
Notifications
You must be signed in to change notification settings - Fork 0
/
AxsTweet.js
394 lines (338 loc) · 13.8 KB
/
AxsTweet.js
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
//Java script for improviing accessibility of twitter.com
//Author Nishit Chokhawala ([email protected])
//Author Nikhil Mohan ([email protected])
//Author Ranjanabh Bahukhandi ([email protected])
//Author Vinay Tambve ([email protected])
// create namespace
var axsTweet = {};
/**
* These are strings to be spoken to the user
* @type string
*/
axsTweet.HELP = 'The following shortcut keys are available. ';
/**
* The AxsJAX object that will do the tickling and speaking.
* @type AxsJAX?
*/
axsTweet.axsJAXObj = null;
/**
* The AxsNav object that will handle navigation.
* @type AxsNav?
*/
axsTweet.axsNavObj = null;
/**
* The AxsSound object that will play earcons
* @type AxsSound?
*/
axsTweet.axsSoundObj = null;
/**
* The PowerKey object that will provide a quick search
* @type PowerKey?
*/
axsTweet.pkObj = null;
/**
* The AxsLens object that will magnify content.
* @type AxsLens?
*/
axsTweet.axsLensObj = null;
/**
* The magnification factor for the AxsLens object.
* @type number
*/
axsTweet.magSize = 1.5;
axsTweet.loggedin = null;
/**
* Initializes the AxsJAX script
*/
axsTweet.init = function(){
axsTweet.axsJAXObj = new AxsJAX(true);
axsTweet.axsNavObj = new AxsNav(axsTweet.axsJAXObj);
var patt1 = new RegExp("/logout");
var patt2 = new RegExp("twitter.com");
var patt3 = new RegExp("login");
if(patt2.test(document.baseURI) && !patt3.test(document.baseURI)) {
if(patt1.test(document.getElementsByTagName("body")[0].innerHTML)) {
//alert("User is logged in.");
axsTweet.loggedin = true;
axsTweet.axsJAXObj.speakTextViaNode("Twitter home page has been loaded.");
} else {
axsTweet.loggedin = false;
//alert("User is not logged in.");
//axsTweet.axsJAXObj.speakTextViaNode("You are not logged in. Press control and L to log in.");
window.location = "http://twitter.com/login";
axsTweet.LoginPage.pageLoad();
}
}
//Add event listeners
document.addEventListener('DOMNodeInserted',
axsTweet.nodeInsertedHandler,
true);
document.addEventListener('DOMAttrModified',
axsTweet.attrModifiedHandler,
true);
document.addEventListener('keypress', axsTweet.keyHandler, true);
var cnrString = '<cnr> ' +
' <list title="Cycle Results" next="DOWN j" prev="UP k"' +
' hotkey="w">' +
' <item action="CALL:speakTweet">' +
' /html/body[@id="home"]/div[@id="container"]/t' +
'able/tbody/tr/td[@id="content"]/div/div[3]/ol[@id="timelin' +
'e"]/li' +
' </item>' +
' <target title="Delete Tweet" hotkey="d" >' +
' ./span[2]/ul/li/span[@class="del"]' +
' </target>' +
' <target title="Reply Tweet" hotkey="r">' +
' ./span[2]/ul/li/span[@class="reply"]' +
' </target>' +
' <target title="Retweet" hotkey="t">' +
' ./span[2]/ul/li/span[@class="retweet-link"]' +
' </target>' +
' <!--target title="Retweet" hotkey="f">' +
' //./span[2]/ul/li/span[@class="retweet-link"]' +
' //</target-->' +
' </list>' +
' <list title="Trending" next="DOWN j" prev="UP k" hotk' +
'ey="e">' +
' <item action="CALL:speakTrends">' +
' /html/body[@id="home"]/div[@id="container"]/t' +
'able/tbody/tr/td[@id="side_base"]/div[@id="side"]/div[@id=' +
'"trends"]/ul/li/a' +
' </item>' +
' </list>' +
' <list title="Cycle Results" next="UP j" prev="DOWN k"' +
' fwd="x" back="c" >' +
' <item>' +
' /html/body[@id="following"]/div[@id="containe' +
'r"]/table/tbody/tr/td[@id="content"]/div/div[@id="follow"]' +
'/div[@id="follow_grid"]/table/tbody/tr[*]/td[2]/address/sp' +
'an[2]/span[1]' +
' </item>' +
' <target title="Next Following Link" hotkey="b">' +
' /html/body[@id="following"]/div[@id="containe' +
'r"]/table/tbody/tr/td[@id="content"]/div/div[@id="follow"]' +
'/div[@id="follow_grid"]/div[@id="pagination"]/a' +
' </target>' +
' <target title="Prev Following Link" hotkey="c">' +
' /html/body[@id="following"]/div[@id="containe' +
'r"]/table/tbody/tr/td[@id="content"]/div/div[@id="follow"]' +
'/div[@id="follow_grid"]/div[@id="pagination"]/a[2]' +
' </target>' +
' </list>' +
' <list title="Cycle Results" next="UP j" prev="DOWN k"' +
'>' +
' <item>' +
' /html/body[@id="followers"]/div[@id="containe' +
'r"]/table/tbody/tr/td[@id="content"]/div/div[@id="follow"]' +
'/div[@id="follow_grid"]/table/tbody/tr[*]/td[2]/address/sp' +
'an[2]/span[1]' +
' </item>' +
' </list>' +
' <target title="Next Followers Link" hotkey="b">' +
' /html/body[@id="followers"]/div[@id="container"]/' +
'table/tbody/tr/td[@id="content"]/div/div[@id="follow"]/div' +
'[@id="follow_grid"]/div[@id="pagination"]/a' +
' </target>' +
' <target title="Prev Followers Link" hotkey="c">' +
' /html/body[@id="followers"]/div[@id="container"]/' +
'table/tbody/tr/td[@id="content"]/div/div[@id="follow"]/div' +
'[@id="follow_grid"]/div[@id="pagination"]/a[2]' +
' </target>' +
'</cnr>';
axsTweet.axsNavObj.navInit(cnrString, null);
axsTweet.axsLensObj = new AxsLens(axsTweet.axsJAXObj);
axsTweet.axsNavObj.setLens(axsTweet.axsLensObj);
axsTweet.axsLensObj.setMagnification(axsTweet.magSize);
axsTweet.axsSoundObj = new AxsSound(true);
axsTweet.axsNavObj.setSound(axsTweet.axsSoundObj);
axsTweet.pkObj = new PowerKey('available actions', axsTweet.axsJAXObj);
axsTweet.axsNavObj.setPowerKey(axsTweet.pkObj, '.');
//Delete the next line when you are done with your script.
};
/**
* Handler for DOMNodeInserted events.
* @param {Object} evt A DOMNodeInserted event.
*/
axsTweet.nodeInsertedHandler = function(evt){
var target = evt.target;
// If the target node is something that should
// be spoken, speak it here.
if (target.className == "inline-form retweet-dlg" && evt.type == "DOMNodeInserted")
{
axsTweet.axsJAXObj.speakTextViaNode("Do you want to Retweet? Press y for yes and n for no");
}
};
/**
* Handler for DOMAttrModified events.
* @param {Object} evt A DOMAttrModified event.
*/
axsTweet.attrModifiedHandler = function(evt){
var attrib = evt.attrName;
var newVal = evt.newValue;
var oldVal = evt.prevValue;
var target = evt.target;
// If the target node is something that should
// be spoken, speak it here.
};
axsTweet.LoginPage = {};
axsTweet.LoginPage.state = "username";
axsTweet.LoginPage.pageLoad = function() {
axsTweet.axsJAXObj.speakTextViaNode("Please enter login details . . Enter username and then press tab to enter password.");
//alert("Login page lodaded.");
}
/**
* Handler for key events.
* @param {Object} evt A keypress event.
* @return {boolean} If true, the event should be propagated.
*/
axsTweet.keyHandler = function(evt){
//If Ctrl is held, it must be for some AT.
if(window.location != "http://twitter.com/login")
{
if(evt.ctrlKey && evt.altKey) {
if (evt.charCode == 52) { //4
window.location = "http://twitter.com/following";
}
if(evt.charCode == 51) //3
window.location = "http://twitter.com/followers";
if(evt.charCode == 49) { //1
try{
document.getElementById("status").focus();
axsTweet.axsJAXObj.speakTextViaNode("You can enter Tweet");
} catch(e){}
}
if(evt.charCode == 50) { //2
try{
document.getElementById("update-submit").click();
axsTweet.axsJAXObj.speakTextViaNode("You Posted a Tweet");
} catch(e){}
}
if(evt.charCode == 48) { //0
try{
document.getElementById('sign_out_form').submit();
axsTweet.axsJAXObj.speakTextViaNode("You are signed out!");
} catch(e){}
}
//alert(evt.charCode+" "+evt.keyCode );
if ( evt.charCode == 53) { //5
window.location = "http://twitter.com/";
}
}
if (evt.keyCode == 27) {
try {
axsTweet.axsJAXObj.lastFocusedNode.blur();
} catch(e){}
return false;
}
//for retweet yes or no
if(evt.charCode == 121 && document.getElementsByTagName("body")[0].lastChild.className == "inline-form retweet-dlg")
{
document.getElementsByClassName("btn")[4].click();
axsTweet.axsJAXObj.speakTextViaNode("Retweet Successful !");
}
}
if (axsTweet.axsJAXObj.inputFocused) return true;
var command = axsTweet.keyCodeMap[evt.keyCode] ||
axsTweet.charCodeMap[evt.charCode];
if (command) return command();
return true;
};
/**
* Map from key codes to functions
*/
axsTweet.keyCodeMap = {
// Map additional keyboard behavior that involves key codes here
};
/**
* Map from character codes to functions
* @return {boolean} Always returns false to indicate
* that the keycode has been handled.
*/
axsTweet.charCodeMap = {
// Map additional keyboard behavior that involves char codes here
// - (minus symbol)
45 : function() {
axsTweet.magSize -= 0.10;
axsTweet.axsLensObj.setMagnification(axsTweet.magSize);
return false;
},
// = (equal symbol)
61 : function() {
axsTweet.magSize += 0.10;
axsTweet.axsLensObj.setMagnification(axsTweet.magSize);
return false;
},
// ? (question mark)
63 : function() {
var helpStr = axsTweet.HELP +
axsTweet.axsNavObj.localHelpString() +
axsTweet.axsNavObj.globalHelpString();
axsTweet.axsJAXObj.speakTextViaNode(helpStr);
return false;
}
};
var curr = null;
function removeHTMLTags(html_data)
{
var strInputCode = html_data;
strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){return (p1 == "lt")? "<" : ">";});
var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
return (strTagStrippedText);
}
function getElementsByClassName(oElm, strTagName, strClassName)
{
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements);
}
// This function makes the TTS speak the tweet intelligently
function speakTweet(currentElement)
{
var compStr = "", tempStr = "";
var realnameA = new Array();
realnameA = getElementsByClassName(currentElement.elem,"img","photo fn");
compStr += realnameA[0].getAttribute("alt");
usernameA = new Array();
usernameA = getElementsByClassName(currentElement.elem,"a","tweet-url screen-name");
compStr += " with twitter name " + usernameA[0].innerHTML + " says. ";
// Replace URLs
var hrefArray = currentElement.elem.getElementsByTagName('a');
var j=0;
for(var i=0; i<hrefArray.length;i++)
{
if(hrefArray[i].className == "tweet-url web")
{
j++;
var replStr = "; Link"+j+";";
hrefArray[i].innerHTML = replStr;
}
}
// end of Replace URLs
messageA = new Array();
usernameA = getElementsByClassName(currentElement.elem,"span","entry-content");
tempStr = removeHTMLTags(usernameA[0].innerHTML);
compStr += tempStr;
compStr = compStr.replace(/[!#^(){}\[\]\\<>\|]/gi,"");
axsTweet.axsLensObj.view(currentElement.elem);
currentElement.elem.scrollIntoView(true);
axsTweet.axsJAXObj.speakTextViaNode(compStr);
}
function speakTrends(currentElement)
{
var trendStr = "";
trendStr = currentElement.elem.innerHTML;
trendStr = trendStr.replace(/#/gi,"Tag of ");
axsTweet.axsLensObj.view(currentElement.elem);
currentElement.elem.scrollIntoView(true);
axsTweet.axsJAXObj.speakTextViaNode(trendStr);
}
axsTweet.init();