Changeset 81

User picture

Author: frojo56

(2009/03/19 17:33) Almost 3 years ago

Reverted to 3/6/09 release code

Affected files

Updated twitter_fantastico.user.js Download diff

8081
7
// @require			http://iworkwithcomputers.com/dev/jquery/jquery-1.3.min.js
7
// @require			http://iworkwithcomputers.com/dev/jquery/jquery-1.3.min.js
8
// @require			http://iworkwithcomputers.com/dev/jquery/ui/minified/jquery.ui.all.min.js
8
// @require			http://iworkwithcomputers.com/dev/jquery/ui/minified/jquery.ui.all.min.js
9
// @author    		Carl Furrow
9
// @author    		Carl Furrow
10
// @version			3.12.09
11
// ==/UserScript==
10
// ==/UserScript==
12
11
13
twitter_fantastico = function(){
12
twitter_fantastico = function(){
...
...
25
	var loading=false;
24
	var loading=false;
26
	var lastPage=false;
25
	var lastPage=false;
27
	var useJQXHR=true;
26
	var useJQXHR=true;
28
	var current_script_length = 28734;
27
	var current_script_length = 28882;
29
	var loaded_tweets = new Array();
28
	var loaded_tweets = new Array();
30
29
31
	if (typeof GM_xmlhttpRequest == "function") 
30
	if (typeof GM_xmlhttpRequest == "function") 
...
...
64
63
65
		determine_what_page_user_is_on();
64
		determine_what_page_user_is_on();
66
		j('head').append("<style type='text/css'>"+page_css()+"</style>");
65
		j('head').append("<style type='text/css'>"+page_css()+"</style>");
66
		//add_bottom_actionbar();
67
		log("Loading page data");
67
		log("Loading page data");
68
		//load_page(false,useJQXHR);
68
		load_page(useJQXHR,false);
69
		load_page(useJQXHR,false);
69
		modify_tweets(loaded_tweets[pageNumber-1],false)
70
		modify_tweets(loaded_tweets[pageNumber-1],false)
70
		log("Attaching scroll event handler");
71
		log("Attaching scroll event handler");
71
		//apply scroll event handler
72
		//apply scroll event handler
72
		j(window).scroll(function(e){
73
		j(window).scroll(function(e){
74
			//window.pageYOffset
75
			//window.innerHeight
76
			//log("Y: "+window.pageYOffset+" WindowHeight: "+window.innerHeight);
73
			lastTweetTop = j("#timeline .status:last").offset().top;
77
			lastTweetTop = j("#timeline .status:last").offset().top;
74
			currentScrollPosition = window.pageYOffset + window.innerHeight;
78
			currentScrollPosition = window.pageYOffset + window.innerHeight;
79
			//log("Loading: "+loading+" LastPage: "+lastPage+" currentScrollPosition >= lastTweetTop - 20:" + (currentScrollPosition
>= lastTweetTop - 20));
75
			if( !loading && !lastPage && currentScrollPosition >= lastTweetTop - window.innerHeight/3)
80
			if( !loading && !lastPage && currentScrollPosition >= lastTweetTop - window.innerHeight/3)
76
			{
81
			{
77
				pageNumber++;
82
				pageNumber++;
...
...
212
						new_jq_tweet.find("span.actions div").append("<a class='delete' title='delete this update' href='#delete'></a>");
217
						new_jq_tweet.find("span.actions div").append("<a class='delete' title='delete this update' href='#delete'></a>");
213
						modify_delete_button(new_jq_tweet,tweets[i]);
218
						modify_delete_button(new_jq_tweet,tweets[i]);
214
					}
219
					}
215
					set_to_me_class(new_jq_tweet);
220
					find_reply_to_me_in_tweet_and_set_to_me_class(new_jq_tweet);
216
					if(j("#timeline").length>0)
221
					if(j("#timeline").length>0)
217
						new_jq_tweet.appendTo("#timeline");
222
						new_jq_tweet.appendTo("#timeline");
218
					else
223
					else
...
...
228
					add_retweet_button(jq_tweet,tweets[i]);
233
					add_retweet_button(jq_tweet,tweets[i]);
229
					modify_delete_button(jq_tweet,tweets[i]);
234
					modify_delete_button(jq_tweet,tweets[i]);
230
					add_twitpic_preview(jq_tweet,tweets[i]);
235
					add_twitpic_preview(jq_tweet,tweets[i]);
231
					set_to_me_class(jq_tweet);
236
					find_reply_to_me_in_tweet_and_set_to_me_class(jq_tweet);
232
				}
237
				}
233
238
234
			}
239
			}
235
		}
240
		}
241
		//modify_nested_twitter_replies();
242
		//log("Done modifying tweets.");
236
	}
243
	}
237
	function modify_nested_twitter_replies()
244
	function modify_nested_twitter_replies()
238
	{
245
	{
...
...
243
		if(json_tweet.user.screen_name != current_username)
250
		if(json_tweet.user.screen_name != current_username)
244
		{
251
		{
245
			tweet.find("a.retweet-link").remove();
252
			tweet.find("a.retweet-link").remove();
253
			//log("Adding retweet button for "+ json_tweet.id);
254
			//log("Adding retweet button for " + json_tweet.id);
246
			if(tweet.find(".actions div").length==0)
255
			if(tweet.find(".actions div").length==0)
247
				jq_retweet_link = j("<a class='retweet-link' href='#retweet'>RT</a>").appendTo(tweet.find(".actions"));
256
				jq_retweet_link = j("<a class='retweet-link' href='#retweet'>RT</a>").appendTo(tweet.find(".actions"));
248
			else
257
			else
...
...
253
				show_embedded_retweet(j(this).data('json_tweet'));
262
				show_embedded_retweet(j(this).data('json_tweet'));
254
				return false;
263
				return false;
255
			});
264
			});
265
			//log("Done adding retweet");
256
		}
266
		}
257
267
258
	}
268
	}
...
...
269
279
270
			jq_embedded_retweet.appendTo(jq_tweet.find(".status-body")).effect('scale',{from:{height:0},percent:100,direction:'vertical',scale:'box'},300);
280
			jq_embedded_retweet.appendTo(jq_tweet.find(".status-body")).effect('scale',{from:{height:0},percent:100,direction:'vertical',scale:'box'},300);
271
			jq_textarea = jq_embedded_retweet.find("textarea.retweet-text");
281
			jq_textarea = jq_embedded_retweet.find("textarea.retweet-text");
282
			//jq_textarea.focus(function(){
283
			//	counter_span = j(this).parent().find("span.counter");
284
			//	counter_span.html(140-parseInt(j(this).val().length));
285
			//});
272
			counter_span = jq_textarea.parent().find("span.counter");
286
			counter_span = jq_textarea.parent().find("span.counter");
273
			counter_span.html(140-parseInt(jq_textarea.val().length));
287
			counter_span.html(140-parseInt(jq_textarea.val().length));
274
288
...
...
309
	}
323
	}
310
	function modify_reply_button(tweet,json_tweet)
324
	function modify_reply_button(tweet,json_tweet)
311
	{
325
	{
326
		//log("Modifying reply button for " + json_tweet.id);
312
		tweet.find(".actions .repl").remove();
327
		tweet.find(".actions .repl").remove();
313
		tweet.find(".actions .reply").remove();
328
		tweet.find(".actions .reply").remove();
314
		tweet.find(".actions .reply2").remove();
329
		tweet.find(".actions .reply2").remove();
...
...
326
			tweet.find(".reply2").remove();
341
			tweet.find(".reply2").remove();
327
			return false;
342
			return false;
328
		}
343
		}
344
		//log("Adding reply click-event for: "+jq_reply_link.parent().parent().parent().attr("id"));
329
		jq_reply_link.click(function(){
345
		jq_reply_link.click(function(){
330
			show_embedded_reply(j(this).data('json_tweet'));
346
			show_embedded_reply(j(this).data('json_tweet'));
331
			return false;
347
			return false;
332
		});
348
		});
349
		//log("Done modifying reply");
333
	}
350
	}
334
	function show_embedded_reply(json_tweet)
351
	function show_embedded_reply(json_tweet)
335
	{
352
	{
...
...
342
			jq_embedded_reply = j("<div id='reply_"+json_tweet.id+"' class='embedded-reply'><span
class='counter'>140</span><br/><textarea class='reply-text'>@"+json_tweet.user.screen_name+"</textarea><br/><a
class='reply-submit' href='#'>Reply</a><a class='reply-cancel' href='#'>Cancel</a></div>");
359
			jq_embedded_reply = j("<div id='reply_"+json_tweet.id+"' class='embedded-reply'><span
class='counter'>140</span><br/><textarea class='reply-text'>@"+json_tweet.user.screen_name+"</textarea><br/><a
class='reply-submit' href='#'>Reply</a><a class='reply-cancel' href='#'>Cancel</a></div>");
343
			jq_embedded_reply.appendTo(jq_tweet.find(".status-body")).effect('scale',{from:{height:0},percent:100,scale:'box',direction:'vertical'},300);
360
			jq_embedded_reply.appendTo(jq_tweet.find(".status-body")).effect('scale',{from:{height:0},percent:100,scale:'box',direction:'vertical'},300);
344
			jq_textarea = jq_embedded_reply.find("textarea.reply-text");
361
			jq_textarea = jq_embedded_reply.find("textarea.reply-text");
345
362
			//jq_textarea.focus(function(){
363
			//	counter_span = j(this).parent().find("span.counter");
364
			//	counter_span.html(140-parseInt(j(this).val().length));
365
			//});
366
			//jq_textarea.focus();
346
			counter_span = jq_textarea.parent().find("span.counter");
367
			counter_span = jq_textarea.parent().find("span.counter");
347
			counter_span.html(140-parseInt(jq_textarea.val().length));
368
			counter_span.html(140-parseInt(jq_textarea.val().length));
348
			jq_reply_link = jq_embedded_reply.find("a.reply-submit");
369
			jq_reply_link = jq_embedded_reply.find("a.reply-submit");
...
...
374
				jtweet = j(this).data('json_tweet');
395
				jtweet = j(this).data('json_tweet');
375
				jq_ta = j(this).data('jq_textarea');
396
				jq_ta = j(this).data('jq_textarea');
376
				jq_ta.parent().effect('scale',{percent:0,direction:'vertical',scale:'box'},300,function(){j(this).remove();});
397
				jq_ta.parent().effect('scale',{percent:0,direction:'vertical',scale:'box'},300,function(){j(this).remove();});
398
				//jq_ta.parent().remove();
377
				return false;
399
				return false;
378
			});
400
			});
379
		}	
401
		}	
...
...
391
	{
413
	{
392
		if(current_username == json_tweet.user.screen_name)
414
		if(current_username == json_tweet.user.screen_name)
393
		{
415
		{
416
			//log("current_username==json_tweet.user.screen_name: "+current_username+" == "+json_tweet.user.screen_name);
417
			//http://twitter.com/statuses/destroy/id.json
394
			//What's going on here:
418
			//What's going on here:
395
				//I'm finding and removing Twitter's existing delete button, so as to create a new delete button that does not
419
				//I'm finding and removing Twitter's existing delete button, so as to create a new delete button that does not
396
				//use a javascript prompt. Multiple attemps to just "unbind" Twitter's delete button failed. So I had to resort
420
				//use a javascript prompt. Multiple attemps to just "unbind" Twitter's delete button failed. So I had to resort
...
...
426
		jq_tweet_li.children(".actions a.reply2").attr("class","repl");
450
		jq_tweet_li.children(".actions a.reply2").attr("class","repl");
427
		jq_tweet_li.children(".actions .retweet-link").remove();
451
		jq_tweet_li.children(".actions .retweet-link").remove();
428
		jq_tweet_li.find("a:contains('in reply to')").remove();
452
		jq_tweet_li.find("a:contains('in reply to')").remove();
453
		//log("Using "+jq_tweet_li.attr("id")+" as a template for copy.");
429
		jq_tweet_li.attr("id","status_"+json_tweet.id);
454
		jq_tweet_li.attr("id","status_"+json_tweet.id);
430
		jq_tweet_li.attr("class","hentry status u-"+json_tweet.user.screen_name+(current_username==json_tweet.user.screen_name?"
mine":""));
455
		jq_tweet_li.attr("class","hentry status u-"+json_tweet.user.screen_name+(current_username==json_tweet.user.screen_name?"
mine":""));
431
		jq_tweet_li.find("span.author a.url").attr("href","http://twitter.com/"+json_tweet.user.screen_name);
456
		jq_tweet_li.find("span.author a.url").attr("href","http://twitter.com/"+json_tweet.user.screen_name);
...
...
440
		jq_tweet_li.find("span.status-body span.entry-meta a.entry-date span.published").attr("title",format_time(json_tweet.created_at) + "
ago"); 
465
		jq_tweet_li.find("span.status-body span.entry-meta a.entry-date span.published").attr("title",format_time(json_tweet.created_at) + "
ago"); 
441
466
442
		jq_tweet_li.find("span.status-body span.entry-meta a.entry-date span.published").html( format_time(json_tweet.created_at) + " ago"); 
467
		jq_tweet_li.find("span.status-body span.entry-meta a.entry-date span.published").html( format_time(json_tweet.created_at) + " ago"); 
468
		//jq_tweet_li.find("span.status-body span.entry-meta a.entry-date span.published").timeago();
443
		jq_tweet_li.find("span.status-body span.entry-meta a.entry-date + span").html("from " + json_tweet.source + "&nbsp;");
469
		jq_tweet_li.find("span.status-body span.entry-meta a.entry-date + span").html("from " + json_tweet.source + "&nbsp;");
444
470
445
		jq_tweet_li.find("span.actions div a[id^=status_star]").unbind();
471
		jq_tweet_li.find("span.actions div a[id^=status_star]").unbind();
...
...
447
		jq_tweet_li.find("span.actions div a[id^=status_star]").attr("class",(json_tweet.favorited?"fav":"non-fav"));
473
		jq_tweet_li.find("span.actions div a[id^=status_star]").attr("class",(json_tweet.favorited?"fav":"non-fav"));
448
		jq_tweet_li.find("span.actions div a[id^=status_star]").attr("title",(json_tweet.favorited?"favorite this
update":"un-favorite this tweet"));
474
		jq_tweet_li.find("span.actions div a[id^=status_star]").attr("title",(json_tweet.favorited?"favorite this
update":"un-favorite this tweet"));
449
475
476
		//log("Adding retweet button, via convert_json method.");
477
478
450
		jq_tweet_li.find("span.actions div a.retweet-link").unbind();
479
		jq_tweet_li.find("span.actions div a.retweet-link").unbind();
451
480
452
		jq_tweet_li.find("div.embedded-reply").remove();
481
		jq_tweet_li.find("div.embedded-reply").remove();
...
...
456
		{
485
		{
457
			jq_tweet_li.find("span.entry-meta").append("&nbsp;<a
href='http://twitter.com/"+json_tweet.in_reply_to_screen_name+"/status/"+json_tweet.in_reply_to_status_id+"'>in reply to
"+json_tweet.in_reply_to_screen_name+"</a>")
486
			jq_tweet_li.find("span.entry-meta").append("&nbsp;<a
href='http://twitter.com/"+json_tweet.in_reply_to_screen_name+"/status/"+json_tweet.in_reply_to_status_id+"'>in reply to
"+json_tweet.in_reply_to_screen_name+"</a>")
458
		}
487
		}
488
		//find_reply_to_me_in_tweet_and_set_to_me_class(jq_tweet_li);
459
		return jq_tweet_li;
489
		return jq_tweet_li;
460
	}
490
	}
461
	function determine_what_page_user_is_on()
491
	function determine_what_page_user_is_on()
...
...
526
		}
556
		}
527
		return newtext;
557
		return newtext;
528
	}
558
	}
529
	function set_to_me_class(jqTweet)
559
	//helluva function name--bad practice on my part :)
560
	function find_reply_to_me_in_tweet_and_set_to_me_class(jqTweet)
530
	{
561
	{
531
		text = jqTweet.find(".status-body .entry-content").html();
562
		text = jqTweet.find(".status-body .entry-content").html();
532
		if(text != null)
563
		if(text != null)
...
...
548
			url:"http://userscripts.org/scripts/source/41387.user.js",
579
			url:"http://userscripts.org/scripts/source/41387.user.js",
549
			headers: { 'Accept-Encoding': '' }, //Thanks Mislav
580
			headers: { 'Accept-Encoding': '' }, //Thanks Mislav
550
			onload:function(response){
581
			onload:function(response){
582
				//log("Response from userscripts.org: "+response.responseHeaders);
551
				scriptLength = response.responseHeaders.match(/Content-Length: (\d+)/)[1];
583
				scriptLength = response.responseHeaders.match(/Content-Length: (\d+)/)[1];
552
				log("Got script, length: "+scriptLength);
584
				log("Got script, length: "+scriptLength);
553
				if(current_script_length != scriptLength)
585
				if(current_script_length != scriptLength)
586
				{
587
					//show update link
554
					j("<div><a href='http://userscripts.org/scripts/show/41387'>*Update to Twitter Fantastico is
available*</a></div>").prependTo("td#content .wrapper");
588
					j("<div><a href='http://userscripts.org/scripts/show/41387'>*Update to Twitter Fantastico is
available*</a></div>").prependTo("td#content .wrapper");
589
				}
555
			}
590
			}
556
		});		
591
		});		
557
	}
592
	}