// ==UserScript==
// @name Facebook Old Chat Sidebar
// @namespace rocki
// @description Replaces new Facebook sidebar with one like the original.
// @version 2.6.2
// @grant none
// @include http://*.facebook.com/*
// @include https://*.facebook.com/*
// @match http://*.facebook.com/*
// @match https://*.facebook.com/*
// @exclude http://*.facebook.com/ajax/*
// @exclude https://*.facebook.com/ajax/*
// @downloadURL https://update.greasyfork.icu/scripts/5219/Facebook%20Old%20Chat%20Sidebar.user.js
// @updateURL https://update.greasyfork.icu/scripts/5219/Facebook%20Old%20Chat%20Sidebar.meta.js
// ==/UserScript==
// Author: rocki.hack@gmail.com
// License: GNU General Public License v3 (GPL)
// contentEval (http://wiki.greasespot.net/Content_Script_Injection)
(function(source) {
// Check for function input.
if ('function' == typeof source) {
// Execute this function with no arguments, by adding parentheses.
// One set around the function, required for valid syntax, and a
// second empty set calls the surrounded function.
source = '(' + source + ')();'
}
// Create a script node holding this source code.
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = source;
// Insert the script node into the page, so it will run, and immediately
// remove it to clean up.
document.body.appendChild(script);
document.body.removeChild(script);
})
(function(){
var w = window,
d = w.document;
var settings = {
// open buddylist on load
Onload: true,
// set buddylist sticky ( stay opened )
Sticky: true,
// show online friends
Online: true,
// show idle friends
Idle: true,
// show mobile friends
Mobile: true,
// buddylist style
Margin: '0px 10px',
MinHeight: '140px',
Width: '200px'
};
function ajax(url){
this.Url = url;
this.XMLHttpRequest = new w.XMLHttpRequest();
}
ajax.prototype = {
'send':function(type,data,callback){
try{
this.Callback = callback;
this.XMLHttpRequest.open(type,this.Url,true);
this.XMLHttpRequest.onreadystatechange = this.stdcallback.bind(this);
this.XMLHttpRequest.send(data);
return true;
}catch(e){
return false;
}
},
'stdcallback':function(){
if(this.XMLHttpRequest.readyState === 4 && this.XMLHttpRequest.status === 200){
if(typeof this.Callback === 'function') this.Callback(this.XMLHttpRequest);
}
}
};
var util = {
'insertRule':function(rule){
if(!this.css){
this.css = d.createElement('style');
d.querySelector('head').appendChild(this.css);
}
return this.css.appendChild(d.createTextNode(rule));
},
'getItem':function(key){
return unescape(d.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + escape(key).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
},
'setItem':function(key,value){
d.cookie = escape(key) + '=' + escape(value) + '; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/';
},
'removeItem':function(key){
d.cookie = escape(key) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
}
};
var rocki = {
'DOMContentLoaded':function(){
w.toggle_list = function(r){
if(util.getItem('toggle' + r) === 'true'){
util.setItem('toggle' + r,'false');
}else{
util.setItem('toggle' + r,'true');
}
w.render_chat();
};
w.change_order = function(r){
var f = d.querySelectorAll('ul.fbChatOrderedList li.separator[id]');
for(var i = 1, j = f.length; i < j; i++){
if(f.item(i).id === r){
util.setItem('order' + f.item(i).id,i-1);
util.setItem('order' + f.item(i-1).id,i);
}else{
util.setItem('order' + f.item(i).id,i);
}
}
w.render_chat();
};
w.Arbiter.subscribe('sidebar/initialized',function(a,d){
var csv = w.require('ChatSidebarVisibility');
csv.isViewportCapable = function(){ return false; };
csv.shouldShowSidebar = function(){ return false; };
d.hide();
});
var user_data = w.require('CurrentUserInitialData');
rocki.user_id = user_data.id || user_data.USER_ID;
w.Arbiter.subscribe('sidebar/initialized',function(a,c){
var av = w.require('AvailableList'),
sp = w.require('ShortProfiles'),
ol = w.require('ChatOrderedList'),
tl = w.require('Toggler'),
oa = w.require('debounceAcrossTransitions'),
ps = w.require('PresenceStatus'),
at = w.require('LastMobileActiveTimes');
w.ChatOpenTab = w.require('ChatOpenTab');
var getAvailableList = function(){
return ps.getAvailableIDs().filter(function(r){
switch(av.get(r)){
case av.ACTIVE: return settings.Online;
case av.IDLE: return settings.Idle;
default: return false;
}
});
};
var sortAlpha = function(x,y){
var r = sp.getNow(x), s = sp.getNow(y);
if(!r || !s) return 0;
var t = r.name.toLowerCase(),
u = s.name.toLowerCase();
return t < u ? -1 : 1;
};
var sortLists = function(x,y){
if(!x.member || !y.member) return 0;
var r = Number(util.getItem('order' + x.uid)),
s = Number(util.getItem('order' + y.uid));
if(r === s) return 0;
return r < s ? -1 : 1;
};
ol.prototype._getListItem = function(id){
this.itemCache = this.itemCache || {};
if(!this.itemCache.hasOwnProperty(id)){
var usr = sp.getNow(id);
this.itemCache[id] = d.createElement('li');
this.itemCache[id].setAttribute('onclick', 'ChatOpenTab.openUserTab(' + usr.id + ');');
this.itemCache[id].className = '__42fz';
this.itemCache[id].innerHTML =
'\
\