Guest User

Source Code of old Facebook Chat

a guest
Aug 2nd, 2011
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.65 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Facebook-Chat
  3. // @include http://*.facebook.com/*
  4. // @include https://*.facebook.com/*
  5. // @exclude *facebook.com/plugins/*
  6. // @require http://code.jquery.com/jquery-latest.min.js
  7. // @require http://www.hajanet.de/facebox/facebox_new.js
  8. // @version 3.2
  9. // @author Jan Schroeder
  10. // ==/UserScript==
  11. // Copyright: Jan Schroeder!!
  12. // All rights reserved!
  13. // Facebook Chat-Enhancer
  14. // Lets the new Facebook Chat-Bar looks like the old one!
  15. // http://hajanet.de :: hajanet websolutions!
  16. // This one was the first version of the old Chat, so please do not believe the others!
  17. // Stylesheets
  18.  
  19. $('head').append('<style type="text/css">' +
  20. '.fbChatTypeaheadView{background-color:#F2F4F8!important;bottom:auto!important;top:3px!important;}' +
  21. '.fbChatSidebar{height: 50px!important; top:auto!important;right:15px!important;bottom:0;border-left:0!important;border-right:0!important;}' +
  22. '.fbChatSidebarBody{height: 0px!important;border-left:1px solid rgba(0,0,0,0.4);border-right:1px solid rgba(0,0,0,0.4);}' +
  23. '.fbChatOrderedList .item{display:block;}' +
  24. '.fbChatOrderedList .item.active{display:block;}' +
  25. '.sidebarMode .fbDockWrapper.bb{right:184px!important;}' +
  26. '.fbChatSidebarFooter.uiGrid{border:1px solid rgba(0,0,0,0.4)!important;border-top:1px solid #C9D0DA!important;border-collapse:separate!important;}' +
  27. '.fbChatSidebarFooter{border-left:1px solid rgba(0,0,0,0.4);border-right:1px solid rgba(0,0,0,0.4);}' +
  28. '.sidebarMode #globalContainer{left:0!important;}' +
  29. '.sidebarBtn{display:none!important;}' +
  30. '.fbChatOrderedList .item.idle,.sidebarMode #chatFriendsOnline{display:block!important;}' +
  31. '.fbChatSidebarMessage {border: 1px solid grey;}'+
  32. '.chat .clearfix.offline {display: none;}'+
  33. '.fbNubFlyout .fbDockChatTabFlyout.uiToggleFlyout {height: 400px;}' +
  34. '</style>');
  35.  
  36. $('head').append('<link rel="stylesheet" type="text/css" href="http://www.hajanet.de/facebox/facebox.css" />');
  37.  
  38. // Update-Funktion!
  39.  
  40. var SUC_script_num = 107107; // Change this to the number given to the script by userscripts.org (check the address bar)
  41.  
  42. try
  43. {
  44. function updateCheck(forced)
  45. {
  46. if ((forced) || (parseInt(GM_getValue('SUC_last_update', '0')) + 86400000 <= (new Date().getTime()))) // Checks once a day (24 h * 60 m * 60 s * 1000 ms)
  47. {
  48. try
  49. {
  50. GM_xmlhttpRequest(
  51. {
  52. method: 'GET',
  53. url: 'http://userscripts.org/scripts/source/'+SUC_script_num+'.meta.js?'+new Date().getTime(),
  54. headers: {'Cache-Control': 'no-cache'},
  55. onload: function(resp)
  56. {
  57. var local_version, remote_version, rt, script_name;
  58.  
  59. rt=resp.responseText;
  60. GM_setValue('SUC_last_update', new Date().getTime()+'');
  61. remote_version=parseInt(/@uso:version\s*(.*?)\s*$/m.exec(rt)[1]);
  62. local_version=parseInt(GM_getValue('SUC_current_version', '-1'));
  63. if(local_version!=-1)
  64. {
  65. script_name = (/@name\s*(.*?)\s*$/m.exec(rt))[1];
  66. GM_setValue('SUC_target_script_name', script_name);
  67. if (remote_version > local_version)
  68. {
  69. if(confirm('There is an update available for the Greasemonkey script "'+script_name+'."\nWould you like to go to the install page now?'))
  70. {
  71. GM_openInTab('http://userscripts.org/scripts/show/'+SUC_script_num);
  72. GM_setValue('SUC_current_version', remote_version);
  73. }
  74. }
  75. else if (forced)
  76. alert('No update is available for "'+script_name+'."');
  77. }
  78. else
  79. GM_setValue('SUC_current_version', remote_version+'');
  80. }
  81. });
  82. }
  83. catch (err)
  84. {
  85. if (forced)
  86. alert('An error occurred while checking for updates:\n'+err);
  87. }
  88. }
  89. }
  90. GM_registerMenuCommand(GM_getValue('SUC_target_script_name', '???') + ' - Manual Update Check', function()
  91. {
  92. updateCheck(true);
  93. });
  94. updateCheck(false);
  95. }
  96. catch(err)
  97. {}
  98.  
  99. // UPDATER ENDE!
  100. function insertIntoBody() {
  101. var copyright = document.createElement('span');
  102. copyright.innerHTML = '<br><br><center><a href="http://www.hajanet.de">Chat Enhancer programmed by hajanet websolutions</a><br><b>Chat Enhancer , Copyright, Jan Schroeder, Dueren 2011!</center></b>';
  103. document.getElementsByTagName('body')[0].appendChild(copyright);
  104. }
  105.  
  106. window.addEventListener('load', insertIntoBody, true);
  107.  
  108. (function(){
  109.  
  110. var load_interval = 100;
  111. var update_interval = 2000;
  112. var load_timer = setInterval (function() { load(); }, load_interval);
  113. var update_timer = setInterval (function() { update(); }, update_interval);
  114.  
  115. var list;
  116.  
  117. function changeOffline() {
  118. if ($('.fbChatSidebarMessage').is(':visible')) {
  119. $('#numFriends').html('Offline');
  120. $('#fbDockChatBuddylistNub').find('.label').text( 'Chat (Offline)' );
  121. $(".fbChatSidebar").attr('style', 'height: 107px !important');
  122. $(".fbChatSidebarBody").attr('style', 'height: 0px !important');
  123. }
  124. }
  125.  
  126. function changeSize(numFriends) {
  127. if ($('.fbChatSidebarMessage').is(':visible')) {
  128. $('#numFriends').html('Offline');
  129. $('#fbDockChatBuddylistNub').find('.label').text( 'Chat (Offline)' );
  130. $(".fbChatSidebar").attr('style', 'height: 107px !important');
  131. $(".fbChatSidebarBody").attr('style', 'height: 0px !important');
  132. return true;
  133. } else {
  134. var window_height = $(unsafeWindow).height();
  135. var saved_height = GM_getValue('fbe_chat_height');
  136. if( saved_height ) {
  137. saved_height = parseInt(saved_height);
  138. if( GM_getValue('fce_num_lists') && GM_getValue('fce_num_lists') > 0 )
  139. saved_height = saved_height+(32*(parseInt(GM_getValue('fce_num_lists'))));
  140. if( saved_height > (numFriends*32) )
  141. saved_height = (numFriends*32)+(32*(parseInt(GM_getValue('fce_num_lists'))));
  142. if( saved_height > (window_height-125) )
  143. saved_height = window_height-125;
  144. if( saved_height < 200 )
  145. saved_height = 200;
  146. if( $(".fbChatSidebar").height() != (saved_height + 50 + 15) ) {
  147. $(".fbChatSidebar").attr('style', 'height: ' + (saved_height + 50 + 15) +'px !important');
  148. $(".fbChatSidebarBody").attr('style', 'height: ' + (saved_height + 15) +'px !important');
  149. }
  150. } else {
  151. $(".fbChatSidebar").attr('style', 'height: ' + (500 + 50 + 15) +'px !important');
  152. $(".fbChatSidebarBody").attr('style', 'height: ' + (500 + 15) +'px !important');
  153. }
  154. return false;
  155. }
  156. }
  157.  
  158. function changeConversationSize() {
  159. var window_height = $(unsafeWindow).height();
  160. var saved_con_height = GM_getValue('fbe_con_size');
  161. var large_h = parseInt(400);
  162. if( saved_con_height ) {
  163. if( large_h > (window_height-125) )
  164. large_h = window_height-125;
  165. if( saved_con_height == 2 ) {
  166. if( $(".fbNubFlyout").height() != (large_h+50) ) {
  167. $('.fbNubFlyoutBody').css('height', large_h +'px');
  168. $('.fbNubFlyout').css('height', (large_h+50) + 'px');
  169. }
  170. }
  171. }
  172. }
  173.  
  174. function ProfilLinks() {
  175. $('.fbNubFlyoutTitlebar').each(function() {
  176. var chat_window = $(this);
  177. var menu = chat_window.find('.uiMenuInner');
  178. all_link = $(this).find('.uiMenuInner').find('.itemAnchor').attr('href');
  179. if (all_link.indexOf('https') >= 1)
  180. var new_link = all_link.replace('https://www.facebook.com/messages/', '');
  181. else
  182. var new_link = all_link.replace('http://www.facebook.com/messages/', '');
  183. var cuid = new_link;
  184. if( !(chat_window.find('.titlebarText').html().indexOf('Profile') >=0) )
  185. chat_window.find('.titlebarText').append('&nbsp;|&nbsp;<a style="color: white;" href="http://www.facebook.com/profile.php?id=' + cuid + '">Profile</a>');
  186. var status = unsafeWindow.AvailableList.get(val[0]);
  187. var classname = (status == 1) ? 'idle' : 'active';
  188. $('.titlebarLabel .clearfix').find();
  189. });
  190. }
  191.  
  192. var fce_version = '3.2';
  193. function firstload () {
  194. if( !GM_getValue('fce_firstload') || fce_version != GM_getValue('fce_inst_version')) {
  195. jQuery.facebox('<center><h3>Hello, and thanks for loading the new Facebook Chat Enhancer!</h3><br>' +
  196. '<h2>Please add the new FB Chat Enhancer Fanpage!<br><a href="http://www.facebook.com/pages/FB-Chat-Enhancer/196158403772097">Click Here</a>' +
  197. '<h1 style="color:red">NEW FEATURE:</h1><b>You can use the Groups you added in the Past, at this Time without names, but stay tuned!</b><br><br>' +
  198. '<span style="font-size:90px;">:)</span><br><h1>HAVE FUN!</h1><br><br>' +
  199. 'CHANGELOG:<br>' +
  200. '2011-07-27 (11:53 AM): Fixed \'loading\'-Bug in Applications e.g. Zynga Poker<br><br>' +
  201. '2011-07-27 (11:05 PM): Added Groups into the Chatbar, Groups can be de/activated in the cog-menu bottom right!<br>' +
  202. '2011-07-28 (01:10 PM): Function to change the Name of a Friendlist (only for showing in the Chat), by clicking on the Header of the Friendlist!<br><br>' +
  203. '2011-07-28 (02:30 PM): Function to change the Style of the Chatbar (Profilepictures), adjust in the Chat-Setting (bottom right)!<br><br>' +
  204. '<input type="submit" value="close" class="closefirst"></center>' +
  205. '<div style="float: right; text-align: right;">&copy; hajanet.de</div>');
  206. $('.closefirst').bind('click', function() {$.facebox.close();});
  207. GM_setValue('fce_firstload', true);
  208. // Set Version GMCookie
  209. GM_setValue('fce_inst_version', fce_version);
  210. }
  211. }
  212.  
  213. function load () {
  214. if (window.navigator.vendor.match(/Google Inc./) || window.navigator.vendor.match(/Google/)) {
  215. var div = document.createElement("div");
  216. div.setAttribute("onclick", "return window;");
  217. unsafeWindow = div.onclick();
  218. }
  219.  
  220. // If the chat has loaded
  221. if (unsafeWindow.chatDisplay && unsafeWindow.chatDisplay.loaded) {
  222. if( GM_getValue('sidestat') == 'true' ) { unsafeWindow.ChatSidebar.enable(); }
  223. if( GM_getValue('sidestat') == 'false' ) { unsafeWindow.ChatSidebar.disable(); }
  224. unsafeWindow.ChatConfig.set({"sidebar.minimum_width":0});
  225. firstload();
  226. changeSize(unsafeWindow.AvailableList.getCount());
  227. var sidebar = $('.fbChatSidebarBody');
  228. // Hide the default sidebar chat
  229. sidebar.find('ul').hide();
  230.  
  231. var sideMenu = $('.uiMenuInner');
  232. sideMenu.append('<li class="uiMenuItem" data-label="Manage Friendlists"><a class="itemAnchor" href="http://www.facebook.com/friends/edit/"><span class="itemLabel fsm">Manage Friendlists</span></a></li>');
  233. sideMenu.append('<li class="uiMenuItem" data-label="Chat-Settings"><div class="seti"><a class="itemAnchor" href="#"><span class="itemLabel fsm">Chat-Settings</span></a></div></li>');
  234. sideMenu.append('<li class="uiMenuSeparator"></li>');
  235. sideMenu.append('<li class="uiMenuItem" data-label="FB Chat Enhancer Fanpage"><a class="itemAnchor" href="http://www.facebook.com/pages/FB-Chat-Enhancer/196158403772097"><span class="itemLabel fsm">FB Chat Enhancer Fanpage</span></a></li>');
  236. sideMenu.append('<li class="uiMenuItem" data-label="hajanet.de"><a class="itemAnchor" href="http://www.hajanet.de"><span class="itemLabel fsm">&copy; hajanet.de</span></a></li>');
  237. sideMenu.append('<li class="uiMenuItem" data-label="FCE v'+fce_version+'"><a class="itemAnchor" href="http://userscripts.org/scripts/show/107107"><span class="itemLabel fsm">FCE v'+fce_version+'</span></a></li>');
  238.  
  239. // Insert the titlebar to the sidebar
  240. sidebar
  241. .before(
  242. '<div id="closeFBChat" class="bb">' +
  243. '<div class="clearfix fbNubFlyoutTitlebar titlebar">' +
  244. '<div class="titlebarLabel clearfix">' +
  245. '<div class="titlebarTextWrapper"><span class="titlebarText">Chat (<span id="numFriends">fixed by jan</span>)</span></div>' +
  246. '</div>' +
  247. '</div>' +
  248. '</div>'
  249. )
  250. .prepend(
  251. '<ul id="myList" class="fbChatOrderedList"><a class="itemAnchor" href="#"><span class="itemLabel fsm">Loading</span></a></ul>'
  252. );
  253.  
  254. // Bind the titlebar to close chat when clicked
  255. $('#closeFBChat')
  256. .click(function(){
  257. if( unsafeWindow.ChatSidebar.isEnabled() ) {
  258. $('.fbChatSidebar').attr('class', 'fbChatSidebar hidden_elem');
  259. $('#fbDockChatBuddylistNub').attr('style', 'display: block; margin-right: -200px;');
  260. GM_setValue('sidestat', 'false');
  261. }
  262. });
  263. $('.fbNubButton')
  264. .click(function(){
  265. $('#fbDockChatBuddylistNub').attr('style', '');
  266. $('.fbChatSidebar').attr('class', 'fbChatSidebar');
  267. GM_setValue('sidestat', 'true');
  268. });
  269.  
  270. // Define the new list object
  271. list = $('#myList');
  272. clearInterval(load_timer);
  273. }
  274. }
  275.  
  276. function update()
  277. {
  278. // If the chat has loaded
  279. if (unsafeWindow.chatDisplay && unsafeWindow.chatDisplay.loaded) {
  280. if( !changeSize(unsafeWindow.AvailableList.getCount()) ) {
  281. var search = $('.inputsearch');
  282. var search_field = $('.fbChatSidebarFooter').find('input').last();
  283.  
  284. var user_string = [];
  285. var online = unsafeWindow.AvailableList.getAvailableIDs();
  286. // Empty friends list
  287. list.empty();
  288. var closedButton = $('#fbDockChatBuddylistNub');
  289. closedButton.find('.label').text( 'Chat ('+unsafeWindow.AvailableList.getCount()+')' );
  290. // Update friends online counter
  291. $('#numFriends').html(unsafeWindow.AvailableList.getCount());
  292. // Generate User List
  293. online_list = {};
  294. $.each(online, function(index, val) {
  295. online_list[val] = unsafeWindow.ChatUserInfos[val];
  296. });
  297. // Sort List
  298. var sorted_online_list = [];
  299. for (var id in online_list)
  300. sorted_online_list.push([id, unsafeWindow.ChatUserInfos[id].name]);
  301. sorted_online_list.sort(function(a, b) {return (a[1] < b[1]) ? -1 : 1; })
  302.  
  303. var flists = [];
  304.  
  305. function inArray (value, array) {
  306. for (var i=0, item; item=array[i]; i++) {
  307. if (value.toString() == item.toString()) {
  308. return true;
  309. }
  310. }
  311. return false;
  312. }
  313.  
  314. // Loop over online IDs and generate list HTML
  315. var i = 1;
  316. $.each(sorted_online_list, function(index, val) {
  317. var flist = parseInt(unsafeWindow.FriendLists.get(val[0]));
  318. if( isNaN(flist) )
  319. flist = 1;
  320. if( !inArray(flist, flists) ) {
  321. user_string[flist] = { 1: "", 2: "" };
  322. flists.push(flist);
  323. if( flist != 1 ) {
  324. if( flist == -1 ) {
  325. if( GM_getValue('fce_num_lists') > 1 ) {
  326. flistn = 'Other Friends';
  327. user_string[flist][2] = '<li class="item" style="margin-top: 10px; border-top: 1px solid grey; border-bottom: 1px solid grey;"><a class="clearfix" rel="ignore"><span class="name"><b>'+flistn+'</b></span></i></a></li>';
  328. }
  329. } else {
  330. flistn = 'Friendlist ' + i;
  331. if( GM_getValue('fbe_flname_' + flist) && GM_getValue('fbe_flname_' + flist) != '')
  332. flistn = GM_getValue('fbe_flname_' + flist);
  333. if( i != 1 )
  334. var margin = 'margin-top: 10px;';
  335. user_string[flist][2] = '<li class="item" style="border-top: 1px solid grey; border-bottom: 1px solid grey;'+ margin +'"><div class="listing" lid="'+flist+'"><a class="clearfix" rel="ignore">' +
  336. '<span class="name"><b>'+flistn+'</b></span></a></div></li>';
  337. i++;
  338. }
  339.  
  340. }
  341. }
  342. var user = unsafeWindow.ChatUserInfos[val[0]];
  343. var status = unsafeWindow.AvailableList.get(val[0]);
  344. var classname = (status == 1) ? 'idle' : 'active';
  345. if( GM_getValue('fce_show_pics') && GM_getValue('fce_show_pics') == 0 ) {
  346. var pic = '';
  347. var height = 'style="padding-top: -11px; height: 22px;"';
  348. } else {
  349. var pic = '<img class="pic" src="' + user.thumbSrc + '">';
  350. var height = '';
  351. }
  352. user_string[flist][status] += '<li '+height+' class="item ' + classname + '" uid="' + val[0] + '">' +
  353. '<a class="clearfix" '+height+'rel="ignore">' + pic +
  354. '<span class="name">' + user.name + '</span>' +
  355. '<i class="status img sp_3xd8gf sx_94f6be"></i>' +
  356. '</a>' +
  357. '</li>';
  358. });
  359. if( !inArray('1',flists) )
  360. GM_setValue('fce_num_lists', flists.length);
  361. else
  362. GM_setValue('fce_num_lists', 0);
  363. // Append the list HTML to the list
  364. flists.sort(function(a, b) {return (a > b) ? -1 : 1; })
  365. $.each(flists, function(index, value) {
  366. list.append( user_string[value][2] + user_string[value][1] );
  367. });
  368. // Bind the items in the list to open the appropriate chat dialog when clicked
  369. list.find('li')
  370. .click(function(e){
  371. location.href = "javascript:void(chatDisplay._focusTab("+$(this).attr('uid')+"));";
  372. return false;
  373. });
  374.  
  375. $('.listing')
  376. .click(function(e){
  377. if( GM_getValue('fbe_flname_' + $(this).attr('lid')) )
  378. var value = 'value = "'+GM_getValue('fbe_flname_' + $(this).attr('lid'))+'"';
  379. else
  380. var value = '';
  381. $.facebox('Please type in the name of the Friendlist: <input class="fl_name" fl_id="'+$(this).attr('lid')+'" ' + value + ' type="text"><br><input type="submit" id="test1" class="flsaveb" value="save"><div class="flreturn"></div>');
  382. });
  383. $('.flsaveb')
  384. .click(function(e){
  385. $(".flreturn").text('saved!');
  386. GM_setValue('fbe_flname_' + $('.fl_name').attr('fl_id'), $('.fl_name').val());
  387. $.facebox.close();
  388. });
  389.  
  390. changeConversationSize();
  391.  
  392. search.keyup(function(){
  393. if (search_field.val() != "")
  394. list.hide();
  395. else
  396. list.show();
  397. })
  398. .blur(function(){
  399. search.val("");
  400. list.show();
  401. });
  402.  
  403. $('.seti').bind('click', function() {
  404. var saved_height = parseInt(GM_getValue('fbe_chat_height'));
  405. var saved_consize = GM_getValue('fbe_con_size');
  406. var saved_pics = GM_getValue('fce_show_pics');
  407. var ichecked = [];
  408. if( saved_height ) {
  409. saved_height = parseInt(saved_height);
  410. } else {
  411. saved_height = '500';
  412. }
  413. if( saved_consize == 2 ) {
  414. var disp2 = 'checked="checked"';
  415. } else {
  416. var disp1 = 'checked="checked"';
  417. }
  418. if( saved_pics == 1 ) {
  419. var pics1 = 'selected';
  420. } else {
  421. var pics0 = 'selected';
  422. }
  423. jQuery.facebox('<center><b>Size of the Chatbar (px): <input type="text" id="winsize" value="' + saved_height + '" size="2"><br>Size of the Conversation Window:<br>' +
  424. '<input type="radio" name="consizchooser" '+disp2+' value="2"/>Large<br><input type="radio" '+disp1+' id="test1" name="consizchooser" value="1"/>Normal<br>' +
  425. 'Show Profilepictures: <select name="picchooser" id="picchooser"><option '+pics0+' value="0">No</option><option '+pics1+' value="1">Yes</option></select>' +
  426. '</b><br><input type="submit" id="test1" class="winsend" value="save"><div class="winreturn"></div>');
  427. });
  428. $(".winsend").bind('click', function() {
  429. $(".winreturn").text('saved!');
  430. GM_setValue('fbe_chat_height', $("#winsize").val());
  431. GM_setValue('fbe_con_size', parseInt($("input[name='consizchooser']:checked").val()));
  432. GM_setValue('fce_show_pics', $('#picchooser').val());
  433. $.facebox.close();
  434. });
  435. ProfilLinks();
  436. }
  437. }
  438. }
  439.  
  440. })();
Advertisement
Add Comment
Please, Sign In to add comment