Skip to content

Instantly share code, notes, and snippets.

@azu
Created March 21, 2009 17:47
Show Gist options
  • Save azu/82916 to your computer and use it in GitHub Desktop.
Save azu/82916 to your computer and use it in GitHub Desktop.
//v1.2 0037 LT
// ==UserScript==
// @name Pretty Better Twitter
// @namespace http://t-trace.blogspot.com/
// @description Expand conversation chains and twitPic.com thumbnails.
// @include https://twitter.com/*
// @include http://twitter.com/*
// ==/UserScript==
// UPDATE INFO http://t_trace.wed.macserver.jp/pbtweet.html
// for firefox by azu
( function(){
var conv_chain_hash = new Array(0);
var session_id = document.getElementsByName('session-user-screen_name')[0].content;
var isOpera = !!this.opera, isFirefox = !!this.Components, isChromium = !!this.contentWindow , isSafari = this.getMatchedCSSRules && !isChromium;
if(!document.getElementById('show')){
// more button
document.getElementById("timeline").addEventListener("DOMNodeInserted",
function (event){
if(event.target.nodeName == "LI" && (!hasClass(event.target, "animate")))
{
pbtweet_main([event.target]);
} else if(event.target.nodeName == "LI") {
kick_animation_on_top(event);
}
}, false);
}
var insert_HTML = '';
var get_url = '';
if(isSafari){
var oLength = document.styleSheets[0].cssRules.length;
document.styleSheets[0].insertRule('div.conv_chain {clear:both; text-align:left;margin: 0px 5px 4px 0px; padding:0px 0px 0px 0px;}',oLength);
document.styleSheets[0].insertRule('div.conv_chain div.thumb{width: 34px !important; height: 34px !important; position:relative !important;max-width:100px;}',oLength+1);
document.styleSheets[0].insertRule('div.conv_chain div.thumb img{vertical-align:top; margin-right:4px !important;width:60px !important;max-width:60px !important;height:32px !important;}',oLength+2);
document.styleSheets[0].insertRule('div.conv_chain span.icons{display:inline-block;margin-left:25px;text-align:center;padding:0px 0px 10px 0px;width:50px !important;max-width:50px !important;}',oLength+3);
document.styleSheets[0].insertRule('div.conv_chain span.icons img{max-width:40px;max-height:40px;}',oLength+4);
document.styleSheets[0].insertRule('div.conv_chain span.icons a:hover {text-underline: none;}',oLength+5);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content, body#show #content div.conv_chain span.entry-content{display:block;width:400px;max-width:400px;min-height:24px;margin:0px 0px 0px 0px;padding:0px 12px 0px 16px;vertical-align:top;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_02.png); background-repeat:repeat-y;}',oLength+6);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content-before{display:block;width:400px;max-width:400px; height:12px;margin:0px 0px 0px 0px;padding:0px 6px 0px 16px;vertical-align:top;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_01.png); background-repeat:no-repeat;}',oLength+7);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content-after {display:block;width:400px;max-width:400px; height:25px;margin:0px 0px -10px 0px;padding:0px 6px 0px 16px;vertical-align:top;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_03.png); background-repeat:no-repeat; background-position:0px -4px;}',oLength+8);
//document.styleSheets[0].insertRule('div.conv_chain span.entry-content{display:block;margin:0px -6px 5px 75px;min-height:40px;vertical-align:top;border:1px solid #cccccc; -webkit-border-radius: 4px;-webkit-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.5);background:-webkit-gradient(linear, left top, left bottom, from(#fff), to(#ccc), color-stop(0.1, #fff));padding:4px 14px 4px 4px;}',oLength+7);
document.styleSheets[0].insertRule('div.conv_chain span.entry-meta {clear:right; display:block;padding-left:24px; height:10px;}',oLength+9);
document.styleSheets[0].insertRule('.hentry img.twitpic_thumb {display:block;position:absolute;left:500px;top:0px;z-index:100;width:100px;heigt100px;border:7px solid white;-webkit-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.7);-webkit-transform:scale(0.4) rotate(17deg); -webkit-transform-origin:50% 0%;-webkit-transition:-webkit-transform 0.15s ease-in;}',oLength+10);
document.styleSheets[0].insertRule('.hentry img.twitpic_thumb:hover {z-index:101;-webkit-transform:scale(1) rotate(0deg);}',oLength+11);
document.styleSheets[0].insertRule('div.conv_chain img.twitpic_thumb {position:absolute;left:435px; top:inherit;margin-top:-35px;-webkit-transform-origin:50% 0%;-webkit-transform:scale(0.3) rotate(17deg);}',oLength+12);
document.styleSheets[0].insertRule('div.conv_chain img.twitpic_thumb:hover {-webkit-transform-origin:50% 0%;-webkit-transform:scale(1) rotate(0deg);}',oLength+13);
document.styleSheets[0].insertRule('img.twitpic_thumb {display:block;position:absolute;z-index:900;width:100px;heigt100px;border:7px solid white;-webkit-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.7);-webkit-transform:translate(490px, -30px) scale(0.4) rotate(17deg); -webkit-transform-origin:50% 0%;-webkit-transition:-webkit-transform 0.15s ease-in;}',oLength+14);
document.styleSheets[0].insertRule('img.twitpic_thumb:hover {-webkit-transform: translate(490px, -30px) scale(1) rotate(0deg);}',oLength+15);
document.styleSheets[0].insertRule('ol.statuses div.conv_chain .actions {display:inline; visibility: hidden;padding-top:4px ; float:right; width:14px;line-height:0.8em; position:inherit;}',oLength+16);
document.styleSheets[0].insertRule('ol.statuses div.conv_chain:hover .actions {visibility: visible;}',oLength+17);
document.styleSheets[0].insertRule('ol.statuses div.conv_chain .actions .pb-reply {padding:0px 6px; background-image: url(http://static.twitter.com/images/icon_reply.gif);}',oLength+18);
document.styleSheets[0].insertRule('ol.statuses div.conv_chain .actions .pb-fav-action {padding:0px 6px;}',oLength+19);
document.styleSheets[0].insertRule('ol.statuses span.pb-extra span {display:inline;cursor:pointer; margin:0px 3px 5px 3px;padding:1px 6px;border:1px solid #cccccc; -webkit-border-radius: 4px;background:-webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee), color-stop(0.1, #fff)); -webkit-transition:-webkit-box-shadow 0.1s ease-in, color 0.1s ease-in, background 0.1s ease-in;}',oLength+20);
document.styleSheets[0].insertRule('ol.statuses li.status span.pb-extra {opacity: 0; -webkit-transition:opacity 0.3s ease-in;}',oLength+21);
document.styleSheets[0].insertRule('ol.statuses li.status:hover span.pb-extra {opacity: 1;}',oLength+22);
document.styleSheets[0].insertRule('ol.statuses span.pb-extra span:hover {-webkit-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.5);color:#444;background:-webkit-gradient(linear, left top, left bottom, from(#fff), to(#ccc), color-stop(0.1, #fff));}',oLength+23);
document.styleSheets[0].insertRule('ol.statuses span.pb-extra {float:right;color:#ccc;position:absolute;left:390px;}',oLength+24);
document.styleSheets[0].insertRule('div.conv_chain div.conv_chain span.entry-meta {margin-top:0px}',oLength+25);
document.styleSheets[0].insertRule('ol.statuses li {opacity: 1}',oLength+26);
document.styleSheets[0].insertRule('#pb_panel {position:absolute;left: 200px; padding:4px;background:white; -webkit-box-shadow:0px 4px 8px #888;opacity: 0; -webkit-transform: scale(0.2, 0); -webkit-transition:-webkit-transform 0.2s ease-in, opacity 0.1s ease-in;-webkit-transform-origin:50% 0%}',oLength+27);
//coloring for mine or pb-mention //
document.styleSheets[0].insertRule('ol.statuses li.pb-mention {background-color:rgb(96%,100%,100%);}',oLength+28);
document.styleSheets[0].insertRule('ol.statuses li.pb-mention:hover {background-color:rgb(88%,95%,99%);}',oLength+29);
document.styleSheets[0].insertRule('ol.statuses li.mine {background-color:rgb(93%,100%,96%);}',oLength+30);
document.styleSheets[0].insertRule('ol.statuses li.mine:hover {background-color:rgb(91%,100%,93%);}',oLength+31);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content.mine {background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mine_02.png)}',oLength+32);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content.pb-mention{background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mention_02.png)}',oLength+33);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content-before.mine { height:12px;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mine_01.png)}',oLength+34);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content-before.pb-mention{ height:12px;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mention_01.png)}',oLength+35);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content-after.mine { height:25px;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mine_03.png)}',oLength+36);
document.styleSheets[0].insertRule('div.conv_chain span.entry-content-after.pb-mention{ height:25px;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mention_03.png)}',oLength+37);
//debug-css//
document.styleSheets[0].insertRule('.pb-debug-insert {background-color:red !important;}',oLength+38);
document.styleSheets[0].insertRule('div#footer {position:fixed; bottom:-20px; z-index:900; text-align:center; margin:0px auto 0px 140px;-webkit-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.75);-webkit-transition:bottom 0.2s ease-in;}',oLength+39);
document.styleSheets[0].insertRule('div.conv_chain span.entry-baloon {display:inline-block;width:422px;max-width:422px;vertical-align:bottom;margin:0px 0px 0px 0px;}',oLength+40);
document.styleSheets[0].insertRule('ol#timeline {padding-left:0px !important;}',oLength+41);
document.styleSheets[0].insertRule('#profile ol.statuses li.status span.pb-extra {display:none;}',oLength+42);
document.styleSheets[0].insertRule('div#footer:hover {bottom: 0px;}',oLength+43);
}else if(isFirefox){
GM_addStyle(<><![CDATA[s
div.conv_chain {clear:both; text-align:left;margin: 0px 5px 4px 0px; padding:0px 0px 0px 0px;}
div.conv_chain div.thumb{width: 34px !important; height: 34px !important; position:relative !important;max-width:100px;}
div.conv_chain div.thumb img{vertical-align:top; margin-right:4px !important;width:60px !important;max-width:60px !important;height:32px !important;}
div.conv_chain span.icons{display:inline-block;margin-left:25px;text-align:center;padding:0px 0px 10px 0px;width:50px !important;max-width:50px !important;}
div.conv_chain span.icons img{max-width:40px;max-height:40px;}
div.conv_chain span.icons a:hover {text-underline: none;}
div.conv_chain span.entry-content, body#show #content div.conv_chain span.entry-content{display:block;width:400px;max-width:400px;min-height:24px;margin:0px 0px 0px 0px;padding:0px 12px 0px 16px;vertical-align:top;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_02.png); background-repeat:repeat-y;}
div.conv_chain span.entry-content-before{display:block;width:400px;max-width:400px; height:12px;margin:0px 0px 0px 0px;padding:0px 6px 0px 16px;vertical-align:top;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_01.png); background-repeat:no-repeat;}
div.conv_chain span.entry-content-after {display:block;width:400px;max-width:400px; height:25px;margin:0px 0px -10px 0px;padding:0px 6px 0px 16px;vertical-align:top;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_03.png); background-repeat:no-repeat; background-position:0px -4px;}
//div.conv_chain span.entry-content{display:block;margin:0px -6px 5px 75px;min-height:40px;vertical-align:top;border:1px solid #cccccc; -moz-border-radius: 4px;-moz-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.5);background:-moz-gradient(linear, left top, left bottom, from(#fff), to(#ccc), color-stop(0.1, #fff));padding:4px 14px 4px 4px;}
div.conv_chain span.entry-meta {clear:right; display:block;padding-left:24px; height:10px;}
.hentry img.twitpic_thumb {display:block;position:absolute;left:500px;top:0px;z-index:100;width:100px;heigt100px;border:7px solid white;-moz-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.7);-moz-transform:scale(0.4) rotate(17deg); -moz-transform-origin:50% 0%;-moz-transition:-moz-transform 0.15s ease-in;}
.hentry img.twitpic_thumb:hover {z-index:101;-moz-transform:scale(1) rotate(0deg);}
div.conv_chain img.twitpic_thumb {position:absolute;left:435px; top:inherit;margin-top:-35px;-moz-transform-origin:50% 0%;-moz-transform:scale(0.3) rotate(17deg);}
div.conv_chain img.twitpic_thumb:hover {-moz-transform-origin:50% 0%;-moz-transform:scale(1) rotate(0deg);}
img.twitpic_thumb {display:block;position:absolute;z-index:900;width:100px;heigt100px;border:7px solid white;-moz-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.7);-moz-transform:translate(490px, -30px) scale(0.4) rotate(17deg); -moz-transform-origin:50% 0%;-moz-transition:-moz-transform 0.15s ease-in;}
img.twitpic_thumb:hover {-moz-transform: translate(490px, -30px) scale(1) rotate(0deg);}
ol.statuses div.conv_chain .actions {display:inline; visibility: hidden;padding-top:4px ; float:right; width:14px;line-height:0.8em; position:inherit;}
ol.statuses div.conv_chain:hover .actions {visibility: visible;}
ol.statuses div.conv_chain .actions .pb-reply {padding:0px 6px; background-image: url(http://static.twitter.com/images/icon_reply.gif);}
ol.statuses div.conv_chain .actions .pb-fav-action {padding:0px 6px;}
ol.statuses span.pb-extra span {display:inline;cursor:pointer; margin:0px 3px 5px 3px;padding:1px 6px;border:1px solid #cccccc; -moz-border-radius: 4px;background:-moz-gradient(linear, left top, left bottom, from(#fff), to(#eee), color-stop(0.1, #fff)); -moz-transition:-moz-box-shadow 0.1s ease-in, color 0.1s ease-in, background 0.1s ease-in;}
ol.statuses li.status span.pb-extra {opacity: 0; -moz-transition:opacity 0.3s ease-in;}
ol.statuses li.status:hover span.pb-extra {opacity: 1;}
ol.statuses span.pb-extra span:hover {-moz-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.5);color:#444;background:-moz-gradient(linear, left top, left bottom, from(#fff), to(#ccc), color-stop(0.1, #fff));}
ol.statuses span.pb-extra {float:right;color:#ccc;position:absolute;left:390px;}
div.conv_chain div.conv_chain span.entry-meta {margin-top:0px}
ol.statuses li {opacity: 1}
#pb_panel {position:absolute;left: 200px; padding:4px;background:white; -moz-box-shadow:0px 4px 8px #888;opacity: 0; -moz-transform: scale(0.2, 0); -moz-transition:-moz-transform 0.2s ease-in, opacity 0.1s ease-in;-moz-transform-origin:50% 0%}
//coloring for mine or pb-mention //
ol.statuses li.pb-mention {background-color:rgb(96%,100%,100%);}
ol.statuses li.pb-mention:hover {background-color:rgb(88%,95%,99%);}
ol.statuses li.mine {background-color:rgb(93%,100%,96%);}
ol.statuses li.mine:hover {background-color:rgb(91%,100%,93%);}
div.conv_chain span.entry-content.mine {background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mine_02.png)}
div.conv_chain span.entry-content.pb-mention{background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mention_02.png)}
div.conv_chain span.entry-content-before.mine { height:12px;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mine_01.png)}
div.conv_chain span.entry-content-before.pb-mention{ height:12px;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mention_01.png)}
div.conv_chain span.entry-content-after.mine { height:25px;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mine_03.png)}
div.conv_chain span.entry-content-after.pb-mention{ height:25px;background-image:url(http://t_trace.wed.macserver.jp/pbtweet/images/baloon_mention_03.png)}
//debug-css//
.pb-debug-insert {background-color:red !important;}
div#footer {position:fixed; bottom:-20px; z-index:900; text-align:center; margin:0px auto 0px 140px;-moz-box-shadow:0px 3px 5px rgba(0, 0, 0, 0.75);-moz-transition:bottom 0.2s ease-in;}
div.conv_chain span.entry-baloon {display:inline-block;width:422px;max-width:422px;vertical-align:bottom;margin:0px 0px 0px 0px;}
ol#timeline {padding-left:0px !important;}
#profile ol.statuses li.status span.pb-extra {display:none;}
div#footer:hover {bottom: 0px;}
]]></>);
}
// make master objects
try{
var master_fav = document.getElementsByClassName("fav-action")[0].cloneNode(true);
var master_reply = document.getElementsByClassName("reply")[0].cloneNode(true);
} catch(err){
var master_fav = document.createElement('a');
master_fav.className = "favfav";
var master_reply = document.createElement('a');
master_reply.className = "reply";
}
// initialize //
var pb_version = "v1.2 0037 LT";
var pb_nav = document.createElement('li');
pb_nav.id = 'pb_info';
pb_nav.innerHTML = '<a href="">pbtweet</a>';
var pb_panel = document.createElement('div');
pb_panel.id = 'pb_panel';
pb_panel.innerHTML = 'version: ' + pb_version + '<br>';
pb_nav.appendChild(pb_panel);
pb_nav.addEventListener('click', function(e){pb_panel.style.webkitTransform="scale(1, 1)";pb_panel.style.opacity = "1";e.preventDefault();},false);
pb_panel.addEventListener('click', function(e){pb_panel.style.opacity = "0";pb_panel.style.webkitTransform = "scale(0.2, 0)";e.preventDefault();e.stopPropagation()},true);
document.getElementById('navigation').getElementsByTagName('ul')[0].insertBefore(pb_nav, document.getElementById('navigation').getElementsByTagName('ul')[0].getElementsByClassName('last')[0]);
var pb_extra = document.createElement('span');
pb_extra.setAttribute('class','pb-extra');
var pb_rtwweet = document.createElement('span');
pb_rtwweet.setAttribute('class','pb-rtweet');
pb_rtwweet.innerHTML = "RT:";
pb_extra.appendChild(pb_rtwweet);
var pb_via = document.createElement('span');
pb_via.setAttribute('class','pb-via');
pb_via.innerHTML = "(via ";
pb_extra.appendChild(pb_via);
var pb_temp_target = document.createElement('span');
//var pb_replyall = document.createElement('span');
//pb_replyall.setAttribute('class','pb-all');
//pb_replyall.innerHTML = "ALL...";
//pb_extra.appendChild(pb_replyall);
// main process
function pbtweet_main(target){
// if target is moving... delay
// standard window
if(!document.getElementById('show')){
var entry = target;
for (i=0;i <= entry.length;i++){
// remove redundant tweet
for(var j = 0; j <conv_chain_hash.length; j++){
try{
if(entry[i].id == conv_chain_hash[j]){
remove_redundand(entry[i].id);
break;
}
} catch(err) {
}
}
try
{
if(entry[i].hasAttribute("id")){
twitpic_thumb(entry[i].id,entry[i].innerHTML);
pb_extra_set(entry[i]);
pb_appearance_set(entry[i]);
//add external links.
entry[i].getElementsByClassName('entry-content')[0].innerHTML = pb_link_maker(entry[i].getElementsByClassName('entry-content')[0].innerHTML,'main');
}
if(entry[i].childNodes[1].childNodes[1].nodeName == "IMG"){
get_url = entry[i].childNodes[1].childNodes[3].childNodes[4].href;
} else {
get_url = entry[i].childNodes[1].childNodes[2].childNodes[4].href;
}
if(get_url && (!entry[i].getElementsByClassName('conv_chain')[0]))
{
var my_node = entry[i].id;
// delaying //
if(hasClass(entry[i],"animate")){
//alert('stopped');
//document.getElementById('pb-info').innerText = anim_count;
setTimeout(pbtweet_main([entry[i]]), 1000);
} else {
document.getElementById(my_node).addEventListener("DOMNodeInserted", function(event){if(hasClass(event.target, "conv_chain")){kick_animation(event)}}, false);
retreve_data(get_url,my_node);
}
}
} catch(err) {
//alert(err);
}
}
// single view
} else {
try
{
var pic_entry = document.getElementsByClassName("status-body")[0];
pic_entry.setAttribute("id",guid());
twitpic_thumb(pic_entry.id,pic_entry.innerHTML);
var entry = document.getElementsByClassName("entry-meta");
get_url = entry[0].childNodes[4].href;
if(document.getElementById("content").childElementCount == 1)
{
retreve_data(get_url,"content");
}
}
catch(err)
{
}
}
}
function retreve_data(get_url,my_node){
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if(request.readyState == 4 && request.status == 200){
conv_object = eval('(' + request.responseText + ')');
var profile_image_url = conv_object["user"]["profile_image_url"];
var user_name = conv_object["user"]["screen_name"];
var conv_mine = "";
if (user_name == session_id){
conv_mine = " mine";
}
var url_replace = /\:\/\/twitter\.com\/[^\/]+\/status\/[0-9]+\"\>in\ reply\ to/;
var conv_innerHTML = "<span class = \'icons\'><a href='"+ pb_protocol() + "://twitter.com/" + user_name + "'><img src ='" + profile_image_url + "'></a></span><span class=\'entry-content " + user_name + conv_mine + "\'><strong>" + "<a href='" + pb_protocol() + "://twitter.com/" + user_name + "'>" +user_name + "</a> </strong>" + pb_link_maker(conv_object["text"]) + "</span>";
if(conv_object["in_reply_to_status_id"]){
var retreve_status = pb_protocol() + "://twitter.com/" + conv_object["in_reply_to_screen_name"] + "/status/" + conv_object["in_reply_to_status_id"];
retreve_data(retreve_status,my_node);
}
var conv_chain = document.createElement('div');
conv_chain.innerHTML = conv_innerHTML;
conv_chain.setAttribute("class","conv_chain");
conv_chain.id = guid();
// append fav and reply button
var conv_action = document.createElement('div');
conv_action.className = "actions";
var conv_meta = pb_protocol() + "://twitter.com/" + user_name + "/status/" + conv_object["id"];
var conv_fav = master_fav.cloneNode(true);
var conv_reply = master_reply.cloneNode(true);
// detect favorite
if(conv_object["favorited"] == true){
removeClass(conv_fav,"non-fav");
addClass(conv_fav,"fav");
} else {
removeClass(conv_fav,"fav");
addClass(conv_fav,"non-fav");
}
var conv_entry_meta = document.createElement('span');
conv_entry_meta.setAttribute('class','meta entry-meta');
var post_date = new Date(conv_object["created_at"]);
var current_date = new Date();
var past_duration = (current_date - post_date) / 1000;
var string_duration = "";
if (past_duration < 60){
string_duration = "less than a minute";
} else if(past_duration < 180) {
string_duration = "less than 3 minutes";
} else if(past_duration < 6000) {
string_duration = "less than 10 minutes";
} else if(past_duration < 36000) {
string_duration = "less than an hour";
} else if(past_duration < 10800) {
string_duration = "less than 3 hours";
} else if(past_duration < 360000) {
string_duration = "less than 10 hours";
} else if(past_duration < 86400) {
string_duration = "less than a day";
} else if(past_duration < 259200) {
string_duration = "less than 3 days";
} else if(past_duration < 604800) {
string_duration = "less than a week";
} else if(past_duration < 2592000) {
string_duration = "less than a month";
} else if(past_duration < 31536000) {
string_duration = "less than a year";
} else {
string_duration = "more than a year";
}
conv_entry_meta.innerHTML = "<a href='" + conv_meta + "' class='entry-date' rel='bookmark'><span class='published'>" + string_duration +" </span></a> <span>from " + conv_object["source"] + "</span>";
if(conv_object["in_reply_to_status_id"]){
conv_entry_meta.innerHTML = " " + conv_entry_meta.innerHTML + " <a href='" + pb_protocol() + "://twitter.com/" + conv_object["in_reply_to_user_id"] + "/status/" + conv_object["in_reply_to_status_id"] +"'>in reply to " + conv_object["in_reply_to_screen_name"] + "</a>";
}
conv_chain.appendChild(conv_entry_meta);
// append chat balloon
var conv_baloon = document.createElement('span');
conv_baloon.className = "entry-baloon";
var conv_baloon_top = document.createElement('span');
conv_baloon_top.className = "entry-content-before";
var conv_baloon_bottom = document.createElement('span');
conv_baloon_bottom.className = "entry-content-after";
if (user_name == session_id){
addClass(conv_baloon_top,"mine");
addClass(conv_baloon_bottom,"mine");
}
conv_baloon.appendChild(conv_baloon_top);
conv_baloon.appendChild(conv_chain.getElementsByClassName('entry-content')[0]);
conv_baloon.appendChild(conv_baloon_bottom);
conv_baloon.appendChild(conv_entry_meta);
// devidor
//var conv_devidor = document.createElement('div');
//conv_devidor.style.clear = "both";
//conv_devidor.style.marginBottom = "4px";
//conv_chain.appendChild(conv_devidor);
//conv_chain.insertBefore(conv_baloon, conv_devidor);
conv_chain.appendChild(conv_baloon);
var conv_path = location.href.match(/.+\/\/twitter.com(\/[^\/]+)/)[1];
var href_match = /.+\:\/\/twitter\.com\/(.+)\/status\/([0-9]+)/;
conv_reply.href = conv_path + "?status=@" + conv_meta.match(href_match)[1] + "%20&amp;in_reply_to_status_id=" + conv_meta.match(href_match)[2] + "&amp;in_reply_to=" + conv_meta.match(href_match)[1];
conv_reply.title = "reply to " + conv_meta.match(href_match)[1];
conv_fav.id = "status_star_" + conv_meta.match(href_match)[2];
conv_reply.className = "pb-reply";
removeClass(conv_fav,'fav-action');
addClass(conv_fav,'pb-fav-action');
conv_action.appendChild(conv_fav);
conv_action.appendChild(conv_reply);
//
conv_chain.insertBefore(conv_action, conv_baloon.nextElementSibling);
//add reply function
conv_reply.name = conv_reply.href;
conv_reply.removeAttribute("href");
conv_reply.addEventListener("click", function(e){pb_reply(e);e.preventDefault()}, false);
//add fave event
conv_fav.addEventListener("click", function(e){pb_fave(e);e.preventDefault()}, false);
if(my_node != "content"){
conv_chain.style.marginTop = "-60px";
}
pb_extra_set(conv_chain);
pb_appearance_set(conv_chain,conv_chain.getElementsByClassName('entry-content')[0]);
try{
document.getElementById(my_node).appendChild(conv_chain);
} catch(e){
}
var status_id = get_url.replace(/.+\:\/\/twitter\.com\/[^\/]+\/status\/([0-9]+)/,"status_$1");
if(status_id != null){
conv_chain_hash.push(status_id);
if(isSafari){
setTimeout(remove_redundand(status_id),10);
}else if(isFirefox){
remove_redundand(status_id);
}
}
twitpic_thumb(conv_chain.id,conv_chain.innerHTML);
}
};
if (location.href.match(/^https/) && get_url.match(/^https/)){
} else if (location.href.match(/^https/) && get_url.match(/^http\:/)) {
get_url = get_url.replace(/^http\:/, "https:");
} else if (location.href.match(/^http\:/) && get_url.match(/^https/)) {
get_url = get_url.replace(/^https\:/, "http:");
} else if (location.href.match(/^http\:/) && get_url.match(/^http\:/)) {
}
request.open('GET', get_url, true);
// JSON 1st!!!
request.setRequestHeader("Accept", "application/json, text/javascript, */*");
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.send(null);
}
function remove_redundand(target_id){
try {
var remove_target = document.getElementById(target_id);
remove_target.style.display = "none";
//remove_target.parentNode.removeChild(remove_target);
} catch(e) {
}
}
function twitpic_thumb(id,html){
var my_source = html;
if(my_source == ""){
my_source = document.getElementById(id).childNodes[0].childNodes[0].innerHTML;
}
var twitpic_carrier = />(http\:\/\/twitpic.com\/[^\<\.]+)<\/a\>/;
var movapic_carrier = /\"(http\:\/\/movapic.com\/pic\/([^\"]+))/;
var yfrog_carrier = />(http\:\/\/yfrog.com\/[^\<\.]+)<\/a\>/;
var photoshare_carrier = /(http\:\/\/bcphotoshare\.com\/photos\/[0-9]+\/([0-9]+))/;
var bkite_carrier = /Photo\:\ \<a\ [^\>]*href\=\"http\:\/\/bkite.com\/([0-9a-zA-Z]+)\"/;
var sec_carrier = /http\:\/\/tiny12\.tv\/([a-zA-Z0-9]+)/;
//twitpic support
if(my_source.match(twitpic_carrier)){
var pic_thumb_src = my_source.match(twitpic_carrier)[1].replace(/http\:\/\/twitpic\.com\/([0-9a-zA-Z]+)/,"http://twitpic.com/show/thumb/$1");
place_picture(id,pic_thumb_src,my_source.match(twitpic_carrier)[1]);
}
//photoshare support
if(my_source.match(photoshare_carrier)){
var pic_thumb_src = "http://images.bcphotoshare.com/storages/" + my_source.match(photoshare_carrier)[2] +"/thumbnail.jpg";
place_picture(id,pic_thumb_src,my_source.match(photoshare_carrier)[1]);
}
//movapic support
if(my_source.match(movapic_carrier)){
var pic_thumb_src = "http://image.movapic.com/pic/s_" + my_source.match(movapic_carrier)[2] +".jpeg";
place_picture(id,pic_thumb_src,my_source.match(movapic_carrier)[1]);
}
//yfrog support
if(my_source.match(yfrog_carrier)){
var pic_thumb_src = my_source.match(yfrog_carrier)[1].replace(/http\:\/\/yfrog\.com\/([0-9a-zA-Z]+)/,"http://yfrog.com/$1.th.jpg");
place_picture(id,pic_thumb_src,my_source.match(yfrog_carrier)[1]);
}
// getting bkite.com image
if (my_source.match(bkite_carrier)){
var pic_thumb_query = my_source.replace(/.+<a\ [^\>]*href\=\"http\:\/\/bkite\.com\/([0-9a-zA-Z]+)\".+/,"http://bkite.com/objects/$1");
var pic_thumb_loader = document.createElement('script');
pic_thumb_loader.src = "http://pipes.yahoo.com/pipes/pipe.run?_id=WC_YK2IU3hGdr4ty6icw5g&_render=json&snipcode=" + pic_thumb_query + "&parentid=" + id + "&_callback=bkiteSrc";
document.getElementsByTagName("head")[0].appendChild(pic_thumb_loader);
}
// getting bkite.com image
if (my_source.match(sec_carrier)){
var pic_thumb_query = my_source.match(sec_carrier)[1];
var pic_thumb_loader = document.createElement('script');
pic_thumb_loader.src = "http://pipes.yahoo.com/pipes/pipe.run?_id=db3a5299e7cc3465a16b8333891cdc8d&_render=json&snipcode=" + pic_thumb_query + "&parentid=" + id + "&_callback=bkiteSrc";
document.getElementsByTagName("head")[0].appendChild(pic_thumb_loader);
}
return;
}
// getting tinyurl Maker
//if (my_source.match(sec_carrier)){
//var pic_thumb_query = my_source.match(sec_carrier)[1];
//var pic_thumb_loader = document.createElement('script');
//pic_thumb_loader.src = "http://pipes.yahoo.com/pipes/pipe.run?_id=db3a5299e7cc3465a16b8333891cdc8d&_render=json&snipcode=" + pic_thumb_query + "&parentid=" + id + "&_callback=bkiteSrc";
//document.getElementsByTagName("head")[0].appendChild(pic_thumb_loader);
//}
// id = following
//_itCeBsk3hGoE7lY1ZzWFw
function place_picture(id,pic_thumb_src,pic_href){
var pic_thumb = document.createElement('img');
var pic_thumb_link = document.createElement('a');
pic_thumb_link.setAttribute("href", pic_href);
pic_thumb_link.setAttribute("target", "_blank");
var pic_thumb_id = guid();
pic_thumb_link.setAttribute("id",pic_thumb_id);
pic_thumb.setAttribute("class","twitpic_thumb");
pic_thumb.setAttribute("src", pic_thumb_src);
pic_thumb_link.appendChild(pic_thumb);
document.getElementById(id).appendChild(pic_thumb_link);
}
//Make pseudo guid
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
//Standard function
function hasClass(ele,cls) {
try{
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
} catch(err) {
return false;
}
//return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,'');
}
}
function pb_protocol(){
if (location.href.match(/^https/)){
return "https";
} else if (location.href.match(/^http\:/)) {
return "http";
}
}
var bkite_processor = document.createElement('script');
bkite_processor.innerHTML = "var bkiteSrc = function(data){place_picture(data.value.items[1].content,data.value.items[0].content,data.value.items[2].content);}";
document.getElementsByTagName("head")[0].appendChild(bkite_processor);
if(isSafari){
setTimeout(pbtweet_main(document.getElementsByClassName('hentry')), 500); //initial
}else{
pbtweet_main(document.getElementsByClassName('hentry'));
if (window.AutoPagerize) {
window.AutoPagerize.addDocumentFilter(
function(){
pbtweet_main();
});
}
}
//--autoScrolll--//
var during_pagination = true;
setTimeout(function(){if(!document.getElementById("autopagerize_style")){init_autoPager()}}, 1500);
function init_autoPager(){
during_pagination = false;
window.addEventListener("scroll", function(){add_scroll_event()}, false);
}
function add_scroll_event(){
if(document.getElementById("content").clientHeight < (window.scrollY + window.innerHeight + 200) && (during_pagination == false)){
during_pagination = true;
add_next_page();
};
}
// pb_add next page automatically
function add_next_page(){
during_pagination = true;
if(!location.href.match(/\/public_timeline$/)){
var more_url = document.getElementById("more").href;
window.removeEventListener("scroll", function(){add_scroll_event()}, false);
insert_update(more_url);
setTimeout(function(){during_pagination = false},500);
}
}
// -- auto updater -- //
var auto_update = true;
var update_span = 60000;
var update_object = {};
var purge_expression = /public_timeline/;
if(!location.href.match(purge_expression))setInterval(function(){insert_update()}, update_span);
function insert_update(){
if(!arguments[0]){
// insert update
var real_timeline = document.getElementById("timeline");
var insert_point = real_timeline.childNodes[0];
//var top_status_id = location.href + "?max_id=" + insert_point.id.replace(/status_([0-9]+)/,"$1") + "&page=0&twttr=true";
var top_status_id = location.href + "?min_id=" + insert_point.id.replace(/status_([0-9]+)/,"$1") + "&page=0&twttr=true";
var insert_point_id = insert_point.id.replace(/status_([0-9]+)/,"$1");
insert_point_id += 0.1;
insert_point_id -= 0.1;
//addClass(insert_point, "pb-debug-insert");
} else {
// insert next page
var real_timeline = document.getElementById("timeline");
var insert_point = real_timeline;
var insert_point_id = 0.0;
var top_status_id = arguments[0];
var page_num = document.getElementById("more").href.match(/page\=([0-9]+)/)[1];
page_num -= 0.0;
var more_url = document.getElementById("more").href;
document.getElementById("more").href = more_url.replace(/page\=[0-9]+/, ("page=" + (page_num + 1)));
}
var update_req = new XMLHttpRequest();
update_req.onreadystatechange = function() {
if(update_req.readyState == 4 && update_req.status == 200){
update_object = eval('(' + update_req.responseText + ')');
var insert_HTML = update_object["#timeline"];
var update_wrapper = document.createElement('div');
update_wrapper.style.display = "none";
update_wrapper.id = "pb_updater";
update_wrapper.innerHTML = insert_HTML;
document.getElementById("timeline").parentNode.appendChild(update_wrapper);
var update_node_number = update_wrapper.childNodes[0].childNodes.length;
for(var i = 0; i < update_node_number; i++ ){
var updated_entry = update_wrapper.childNodes[0].childNodes[0];
var updated_entry_id = updated_entry.id.replace(/status_([0-9]+)/,"$1");
updated_entry_id += 0.1;
updated_entry_id -= 0.1;
//alert('update: ' + updated_entry_id + '/ next: ' + insert_point_id);
// insert tweet hit newer one. before it, latest status should be skipped.
while(updated_entry_id < insert_point_id && hasClass(insert_point, "mine")){
insert_point = insert_point.nextElementSibling;
insert_point_id = insert_point.id.replace(/status_([0-9]+)/,"$1");
insert_point_id += 0.1;
insert_point_id -= 0.1;
// - debug -- addClass(insert_point, "pb-debug-insert");
}
// this try is for myself
try{
updated_entry.getElementsByClassName("reply")[0].name = updated_entry.getElementsByClassName("reply")[0].href;
updated_entry.getElementsByClassName("reply")[0].removeAttribute("href");
} catch(err){
}
//update status text
if(insert_point_id < updated_entry_id && hasClass(updated_entry,"mine") && (insert_point.id != "timeline")){
if(isSafari){
document.getElementsByClassName("status-text")[0].innerText = updated_entry.getElementsByClassName("entry-content")[0].innerText;
}else if(isFirefox){
document.getElementsByClassName("status-text")[0].textContent = updated_entry.getElementsByClassName("entry-content")[0].textContent;
}
}
//alert(insert_point_id);
if(insert_point_id < updated_entry_id)
{
//add reply function
try{
updated_entry.getElementsByClassName("reply")[0].addEventListener("click", function(e){pb_reply(e);e.preventDefault()}, false);
} catch(err){
}
//add face event
try{
updated_entry.getElementsByClassName("fav-action")[0].addEventListener("click", function(e){pb_fave(e);e.preventDefault()}, false);
} catch(err){
}
//add destroy event
try{
updated_entry.getElementsByClassName("del")[0].addEventListener("click", function(e){pb_destroy(e);e.preventDefault();e.stopPropagation();}, false);
} catch(err){
}
//update animation
//addClass(updated_entry,"animate");
if(insert_point.id != "timeline"){
// add animation
//var conv_script = document.createElement('script');
//conv_script.innerHTML = "setTimeout(function(){document.getElementById('" + updated_entry.id + "').style.opacity = '1';document.getElementById('" + updated_entry.id + "').style.marginTop = '0px';}," + (i * 200 + 10) + ")";
//updated_entry.style.opacity = "0";
//updated_entry.style.marginTop = "-" + updated_entry.clientHeight + "px";
//updated_entry.style.marginTop = "-52px";
//updated_entry.style.webkitTransition = "opacity 0.35s cubic-bezier(0.4, 0.0, 0.6, 0.4), margin-top 0.2s ease-in";
//updated_entry.style.webkitTransition = "opacity 0.35s cubic-bezier(0.4, 0.0, 0.6, 0.4);";
//updated_entry.appendChild(conv_script);
insert_point.parentNode.insertBefore(updated_entry, insert_point);
// latest status class change.
if(insert_point.className.match(/latest\-status/)){
insert_point.className = insert_point.className.replace(/latest\-status/g,"");
}
//only adding page.
} else {
removeClass(updated_entry, "animate");
real_timeline.appendChild(updated_entry);
}
}
else if(insert_point_id == updated_entry_id)
{
updated_entry.parentNode.removeChild(updated_entry);
}
else
{
update_wrapper.parentNode.removeChild(update_wrapper);
break;
}
}
try{
update_wrapper.parentNode.removeChild(update_wrapper);
} catch(err) {
}
}
};
update_req.open('GET', top_status_id, true);
update_req.setRequestHeader("Accept", "application/json, text/javascript, */*");
update_req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
update_req.send(null);
return false;
}
function pb_link_maker(string){
var source = string;
var linked_source = source;
if(!arguments[1]){
linked_source = source.replace(/(https*\:\/\/[^\s\*\]\(\)]+)/g, "<a class='pb-link' href='$1' target='_blank'>$1</a>");
linked_source = linked_source.replace(/blank\'\>([^\<]{28})[^\<]+\<\/a/g, "blank'>$1...</a");
}
linked_source = linked_source.replace(/\@([0-9a-zA-Z\_\-]+)/g,"@<a class='pb-link sname' href='" + pb_protocol() + "://twitter.com/$1' target='_blank'>$1</a>");
//hashtag link
linked_source = linked_source.replace(/([^\/]|)\#([a-zA-Z0-9]+)([\s]|)/g,"$1#<a class='pb-link hashtag' href='" + pb_protocol() + "://search.twitter.com/search?q=%23$2' target='_blank'>$2</a>$3");
return linked_source;
}
function pb_link_remover(target){
pb_temp_target = target.cloneNode(true);
try
{ // remove strong tag
pb_temp_target.removeChild(pb_temp_target.getElementsByTagName('strong')[0]);
} catch(err){
//alert(err);
}
var pb_link = pb_temp_target.getElementsByTagName('a');
var num_pb_link = pb_link.length;
var removed_str = "";
for(i = 0; i < num_pb_link; i++)
{
if(!(hasClass(pb_link[i],'hashtag') || hasClass(pb_link[i],'sname') || pb_link[i].target != "_blank" ))
{
if(isSafari){
pb_link[i].innerText = pb_link[i].href;
}else if(isFirefox){
pb_link[i].textContent = pb_link[i].href;
}
}
}
if(isSafari){
removed_str = pb_temp_target.innerText;
}else if(isFirefox){
removed_str = pb_temp_target.textContent;
}
return removed_str;
}
// kick animation to fix place
function kick_animation(e){
var target = e.target;
if((target.parentNode.offsetTop < (window.scrollY + window.innerHeight + 200)) && ((window.scrollY - 500) < target.parentNode.offsetTop) ){
target.style.opacity = "0";
target.style.webkitTransition = "opacity 0.45s cubic-bezier(0.4, 0.0, 0.6, 0.4), margin-top 0.35s ease-out";
var conv_script = document.createElement('script');
conv_script.innerHTML = "setTimeout(function(){document.getElementById('" + target.id + "').style.opacity = '1';document.getElementById('" + target.id + "').style.marginTop = '0px';},200)";
target.appendChild(conv_script);
} else {
target.style.opacity = "1";
target.style.marginTop = "0px";
}
}
function kick_animation_on_top(e){
var target = e.target;
// if((target.parentNode.offsetTop < (window.scrollY + window.innerHeight + 200)) && ((window.scrollY - 500) < target.parentNode.offsetTop) ){
//target.style.opacity = "0";
//target.style.marginTop = "-52px";
//target.style.webkitTransition = "opacity 0.45s cubic-bezier(0.4, 0.0, 0.6, 0.4), margin-top 0.35s ease-out";
//target.addEventListener("webkitTransitionEnd", function(e){alert();removeClass(e.target, "animate");remove_end_capture(target.id);pbtweet_main([e.target]);e.stopPropagation();e.preventDefault()}, false);
//var conv_script = document.createElement('script');
//conv_script.innerHTML = "document.getElementById('" + target.id + "').style.opacity = '1';document.getElementById('" + target.id + "').style.marginTop = '0px';setTimeout(removeClass(this.parentNode, 'animate'), 1000);";
//target.appendChild(conv_script);
//setTimeout(function(){target.style.opacity = "1";target.style.marginTop = "0px";removeClass(target, "animate");pbtweet_main([target]);}, 2000);
// } else {
// target.style.opacity = "1";
// target.style.marginTop = "0px";
// }
}
//function remove_end_capture(target_id){
// document.getElementById(target_id).removeEventListener("webkitTransitionEnd", function(e){alert();removeClass(e.target, "animate");remove_end_capture(target.id);pbtweet_main([e.target]);}, false);
//}
//reply button builder
function pb_extra_set(target){
var my_pb_extra = pb_extra.cloneNode(true);
var target_meta = target.getElementsByClassName('entry-meta')[0];
var my_in_reply_to_url = target_meta.getElementsByClassName('entry-date')[0].href;
// var target_insert = target.getElementsByClassName('entry-meta')[0];
var my_reply_to = my_in_reply_to_url.match(/twitter\.com\/([^\/]+)/)[1];
var my_pb_rtwweet = my_pb_extra.getElementsByClassName('pb-rtweet')[0];
var my_pb_via = my_pb_extra.getElementsByClassName('pb-via')[0];
// var my_pb_replyall = my_pb_extra.getElementsByClassName('pb-all')[0];
my_pb_extra.addEventListener("click", function(e){pb_reply(e,my_in_reply_to_url);}, false);
//set parameter
my_pb_rtwweet.setAttribute('name',my_in_reply_to_url);
my_pb_rtwweet.setAttribute('title',"RT: @" + my_reply_to);
my_pb_rtwweet.innerHTML = "RT: @";
my_pb_via.setAttribute('name',my_in_reply_to_url);
my_pb_via.setAttribute('title',"via @" + my_reply_to + "");
my_pb_via.innerHTML = "(via @)";
// my_pb_replyall.setAttribute('name',my_in_reply_to_url);
// my_pb_replyall.setAttribute('title',"reply to all");
target_meta.appendChild(my_pb_extra);
}
function pb_appearance_set(target){
var content_target = target;
if(arguments[1]){
var style_target = arguments[1];
} else {
var style_target = content_target;
}
if(isSafari){
var entry_string = content_target.getElementsByClassName('entry-content')[0].innerText;
}else if(isFirefox){
var entry_string = content_target.getElementsByClassName('entry-content')[0].textContent;
}
var mention_regex = new RegExp("@" + session_id);
if(entry_string.match(mention_regex)){
addClass(style_target, "pb-mention");
if(hasClass(style_target.parentNode,"entry-baloon")){
addClass(style_target.parentNode.getElementsByTagName('span')[0], "pb-mention");
addClass(style_target.parentNode.getElementsByTagName('span')[2], "pb-mention");
}
}
}
// reply function
function pb_reply(event){
var target = event.target;
var msg_body = "";
var my_in_reply_to_url = "";
var elm = document.getElementById("status");
switch(event.target.className)
{
case "pb-rtweet":
var in_reply_to_url = arguments[1];
var reply_to = in_reply_to_url.match(/twitter\.com\/([^\/]+)\/status/)[1];
var my_in_reply_to_url = in_reply_to_url.match(/\/status\/([0-9]+)$/)[1];
elm.value = "RT @" + reply_to + ": " + pb_link_remover(target.parentNode.parentNode.parentNode.getElementsByClassName('entry-content')[0]);
break;
case "pb-via":
var in_reply_to_url = arguments[1];
var reply_to = in_reply_to_url.match(/twitter\.com\/([^\/]+)\/status/)[1];
var my_in_reply_to_url = in_reply_to_url.match(/\/status\/([0-9]+)$/)[1];
elm.value = pb_link_remover(target.parentNode.parentNode.parentNode.getElementsByClassName('entry-content')[0]) + " (via @" + reply_to + ")";
break;
case "pb-all":
var in_reply_to_url = arguments[1];
var reply_to = in_reply_to_url.match(/twitter\.com\/([^\/]+)\/status/)[1];
var my_in_reply_to_url = in_reply_to_url.match(/\/status\/([0-9]+)$/)[1];
var id_remover = new RegExp("\@" + reply_to + "\ ");
elm.value = elm.value.replace(id_remover,"");
elm.value = "@" + reply_to + " " + elm.value;
break;
default:
var in_reply_to_url = target.name;
var reply_to = in_reply_to_url.match(/in\_reply\_to\=(.+)$/)[1];
var my_in_reply_to_url = in_reply_to_url.match(/status\_id\=([0-9]+)\&/)[1];
var id_remover = new RegExp("\@" + reply_to + "\ ");
elm.value = elm.value.replace(id_remover,"");
elm.value = "@" + reply_to + " " + elm.value;
}
document.getElementById("in_reply_to_status_id").value = my_in_reply_to_url;
document.getElementById("in_reply_to").value = reply_to;
elm.focus();
if(event.target.className != "pb-rtweet"){
elm.setSelectionRange(elm.value.length, elm.value.length);
} else {
}
return(false);
}
// pb favorite function
function pb_fave(event){
var target = event.target;
var target_id = target.id.match(/status\_star\_([0-9]+)/)[1];
var fave_req = new XMLHttpRequest();
var post_path = "create";
if(hasClass(target,"fav")){
post_path = "destroy";
removeClass(target,"fav");
} else if(hasClass(target,"non-fav")){
post_path = "create";
removeClass(target,"non-fav");
}
fave_req.onreadystatechange = function(){
if(fave_req.readyState == 4 && fave_req.status == 200){
removeClass(target,"fav-throb");
if(post_path == "create"){
addClass(target,"fav");
} else if(post_path == "destroy"){
removeClass(target,"non-fav");
}
}
}
fave_req.open('POST', "/favorites/" + post_path + "/" + target_id , true);
fave_req.setRequestHeader("Accept", "*/*");
fave_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
fave_req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
fave_req.send("authenticity_token=" + document.getElementById("authenticity_token").value);
addClass(target,"fav-throb");
return(false);
}
function pb_destroy(event){
if(confirm("Sure you want to delete this update? There is NO undo")){
var target = event.target;
var target_id = target.parentNode.childNodes[0].id.match(/status\_star\_([0-9]+)/)[1];
var fave_req = new XMLHttpRequest();
var post_path = "destroy";
fave_req.onreadystatechange = function(){
if(fave_req.status == 200){
remove_redundand('status_' + target_id);
}
}
fave_req.open('POST', "/status/" + post_path + "/" + target_id , true);
fave_req.setRequestHeader("Accept", "application/json, text/javascript, */*");
fave_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
fave_req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
fave_req.send("authenticity_token=" + document.getElementById("authenticity_token").value);
addClass(target,"fav-throb");
}
return(false);
}
})();
place_picture = function(id,pic_thumb_src,snip_code){
if(pic_thumb_src.match(/^http:\/\/s3\.amazonaws.com.+photo\-feed\.jpg$/)){
var pic_thumb = document.createElement('img');
var pic_thumb_link = document.createElement('a');
pic_thumb_link.setAttribute("href", "http://bkite.com/" + snip_code);
pic_thumb_link.setAttribute("target", "_blank");
var pic_thumb_id = guid();
pic_thumb_link.setAttribute("id",pic_thumb_id);
pic_thumb.setAttribute("class","twitpic_thumb");
pic_thumb.setAttribute("src", pic_thumb_src);
pic_thumb_link.appendChild(pic_thumb);
document.getElementById(id).appendChild(pic_thumb_link);
} else {
var pic_thumb = document.createElement('img');
var pic_thumb_link = document.createElement('a');
pic_thumb_link.setAttribute("href", snip_code);
pic_thumb_link.setAttribute("target", "_blank");
var pic_thumb_id = guid();
pic_thumb_link.setAttribute("id",pic_thumb_id);
pic_thumb.setAttribute("class","twitpic_thumb");
pic_thumb.setAttribute("src", pic_thumb_src);
pic_thumb_link.appendChild(pic_thumb);
document.getElementById(id).appendChild(pic_thumb_link);
}
}
S4 = function() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
guid = function() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
//Standard function
hasClass = function(ele,cls) {
try{
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
} catch(err) {
return false;
}
//return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
addClass = function(ele,cls) {
if (!hasClass(ele,cls)) ele.className += " "+cls;
}
removeClass = function(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,'');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment