Raw Source
chewbaka / facebook flat

// ==UserScript==
// @name        facebook flat
// @namespace   facebook flat
// @include     https://*.facebook.com/*
// @version     0.1.0
// @grant       none
// @author Chewbaka
// @homepageURL http://hack-free.net
// @updateURL https://openuserjs.org/src/scripts/chewbaka/facebook_flat.meta.js
// @downloadURL https://openuserjs.org/src/scripts/chewbaka/facebook_flat.meta.js
// ==/UserScript==
// var interoldcol = setInterval(getleftcol, 1000);
// function getleftcol() {
// 	var leftcolold = document.getElementById("pagelet_navigation").innerHTML;
// 				if(leftcolold) {
// 						window.leftoldpaste = leftcolold;
// 						console.log(leftoldpaste);
// 						var topaste = document.getElementsByClassName("droxdownabsext")[0];
// 						topaste.appendChild(leftoldpaste);
// 						clearInterval(interoldcol);
// 				}
// }
function prependMenu() {
  var profile_url = document.getElementsByClassName('_2dpe') [0].getAttribute('href');
  var profn = document.getElementsByClassName('_2dpe') [0].childNodes[0].getAttribute('id');
  var nok = profn.split('_');
  var prof_id = nok[3];
  var sp = profile_url.split('facebook.com/');
  var profile_only_url = sp[1];
  var profile_pic = document.getElementsByClassName('_2dpe') [0].firstChild.getAttribute('src');
  var profile_name = document.getElementsByClassName('_2dpe') [0].lastChild.innerHTML;
  var userLang = navigator.language || navigator.userLanguage;
  var nb_event = 0;
  var nb_event_message = '';
  if (userLang == 'fr') {
    var my_newsfeed = 'Mes Nouvelles';
    var my_friends = 'Mes Amis';
    var my_messages = 'Mes Messages';
    var my_photos = 'Mes Photos';
    var my_videos = 'Mes Vidéos';
    var my_groups = 'Mes groupes';
    var my_likes = 'Mes Goûts';
    var my_apps = 'Mes jeux';
    var my_notifications = 'Mes Notifications';
    var my_pages = 'Mes pages';
    var most_recent = 'Le plus récent';
    var top_stories = 'A la une';
    var my_events = 'Mes événements';
    var event_upcoming = 'A venir';
    var event_calendar = 'Calendrier';
    var event_subscribed = 'Abonnés';
    var event_past = 'Passés';
    var new_event = 'Créer un événement';
    var my_save = 'Mes sauvegardes';
    var my_pages_feed = 'Pages';
    var create_page = 'Créer une page';
    var my_frien_birthday = 'Mes Anniversaire';
    var settings = 'Options';
    var old_menu = 'Menu +'
    var goup = 'Haut';
    var profil_visitor = 'Visiteurs';
  } else {
    var my_newsfeed = 'My newsfeed';
    var my_friends = 'My friends';
    var my_messages = 'My messages';
    var my_photos = 'My photos';
    var my_videos = 'My videos';
    var my_groups = 'My groups';
    var my_likes = 'My likes';
    var my_apps = 'My apps';
    var my_notifications = 'My notifications';
    var my_pages = 'My pages';
    var most_recent = 'Most recent stories';
    var top_stories = 'Top stories';
    var my_events = 'My events';
    var event_upcoming = 'Upcoming';
    var event_calendar = 'Calendar';
    var event_subscribed = 'Subscribed';
    var event_past = 'Past';
    var new_event = 'Create';
    var goup = 'Go up';
    var profil_visitor = 'Profile visitors';
  }
  // function detectExtension(extensionId, callback) { 
  //     var img; 
  //     img = new Image(); 
  //     img.src = "chrome-extension://" + extensionId + "/48ico.png"; 
  //     img.onload = function() { 
  //             console.log('installed');
  //     }; 
  //     img.onerror = function() { 
  //             console.log('ne_katus');
  //     }; 
  // }
  // detectExtension('iffpnhdnfeeadmggdiojbnagempmklff');

  function onlyUnique(value, index, self) {
    return self.indexOf(value) === index;
  }
  function visitorsfu() {
    // setTimeout(function() {
    if (!document.getElementById('visitorsblockflat')) {
      var strsource = document.documentElement.innerHTML;
      var numsor = strsource.indexOf('InitialChatFriendsList');
      var fisrtindex = strsource.substring(numsor + 36, strsource.indexOf('],"groups":'));
      var seclaster = fisrtindex.replace(/"/g, '');
      var arraylasted2 = seclaster.split(',');
      var arraylasted11 = [
      ];
      for (var i = 0; i < arraylasted2.length; i++) {
        arraylasted11.push(arraylasted2[i].substr(0, arraylasted2[i].indexOf('-')));
      }
      var arraylasted = arraylasted11.filter(onlyUnique);
      var visitorsblockflat = document.createElement('div');
      visitorsblockflat.id = 'visitorsblockflat';
      visitorsblockflat.style.width = '400px';
      visitorsblockflat.style.height = '500px';
      visitorsblockflat.style.position = 'fixed';
      visitorsblockflat.style.zIndex = '9999';
      visitorsblockflat.style.top = '100px';
      visitorsblockflat.style.background = '#213D6D';
      visitorsblockflat.style.boxShadow = 'rgb(39, 39, 39) 0px 0px 2px';
      visitorsblockflat.style.left = 'calc((100% - 530px) / 5.6)';
      visitorsblockflat.style.overflowY = 'scroll';
      visitorsblockflat.style.overflowX = 'hidden';
      visitorsblockflat.style.padding = '20px 0 0 10px';
      visitorsblockflat.style.display = 'none';
      document.getElementById('leftCol').appendChild(visitorsblockflat);
      var peoplemost = document.createElement('p');
      peoplemost.class = 'mostpeople';
      peoplemost.style.width = '100%';
      peoplemost.style.textAlign = 'center';
      peoplemost.style.fontSize = '12px';
      peoplemost.style.float = 'left';
      peoplemost.style.color = 'white';
      peoplemost.innerHTML = 'People that visit your profile most';
      document.getElementById('visitorsblockflat').appendChild(peoplemost);
      var skdfjnsdlf = document.createElement('div');
      skdfjnsdlf.class = 'skdfjnsdlf';
      if (arraylasted.length > 3) {
        for (var i = 0; i < 20; i++) {
          var sum = i + 1;
          var visitor = '<div style="width:100%;float:left;margin:0 0 0 123px"><a style="float:left;" href="https://www.facebook.com/' + arraylasted[i] + '" target="_blank" class="visitflatone"><p style="float: left;  margin: 23px 0 0 0;font-size: 12px;color: #A5B8C5;">' + sum + '. </p><img style="float:left;margin:5px 10px;border-radius:50px" src="https://graph.facebook.com/' + arraylasted[i] + '/picture" /><p style="float:left;margin: 23px 0 0 0;color: white;">Go to profile</p></a></div>';
          var parser = new DOMParser()
          var el = parser.parseFromString(visitor, 'text/html');
          skdfjnsdlf.appendChild(el.body.firstChild);
        }
        document.getElementById('visitorsblockflat').appendChild(skdfjnsdlf);
      } else {
        var visitor = '<div style="float:left;text-align: center;width: 80%;margin: 30px 0 0 10%;color:white;">Not available now. Try to <a style="color:white;text-decoration:underline" href="https://www.facebook.com">refresh a page</a></div>';
        var parser = new DOMParser()
        var el = parser.parseFromString(visitor, 'text/html');
        skdfjnsdlf.appendChild(el.body.firstChild);
        document.getElementById('visitorsblockflat').appendChild(skdfjnsdlf);
      }
      var visitorslistone = document.createElement('div');
      visitorslistone.class = 'visitorslistone';
      // }, 1000);
    }
  }
  if (document.getElementById('event_reminders_link') != null) {
    // GET NB EVENTS
    var col_event = document.getElementById('event_reminders_link');
    var line_event = col_event.getElementsByClassName('fbRemindersTitle') [0].getElementsByTagName('strong');
    var nb = line_event[0].innerHTML.split(' ');
    if (nb[1] == 'events') {
      nb_event = nb[0];
    } 
    else
    {
      nb_event = 1;
    }
    if (nb_event != 0) {
      nb_event_message = '<not>' + nb_event + '</not>';
    }
  }
  var menu = '<div id="profile_column_js"><a href="' + profile_url + '" class="menuoneava"><img src="' + profile_pic + '" /><p>' + profile_name + '</p></a><div class="menuone dropdownextcl"><div class="droxdownabsext"><a href="/?sk=h_chr">' + most_recent + '</a><a href="/?sk=h_nor">' + top_stories + '</a></div><span></span><a href="https://www.facebook.com">' + my_newsfeed + ' &nbsp;&nbsp;&#8594;</a></div><div class="menuone"><span></span><a href="https://www.facebook.com/profile.php?id=' + prof_id + '&sk=friends">' + my_friends + '</a></div><div class="menuone"><span></span><a href="https://www.facebook.com/messages">' + my_messages + '</a></div><div class="menuone"><span></span><a href="https://www.facebook.com/profile.php?id=' + prof_id + '&sk=photos">' + my_photos + '</a></div><div class="menuone"><span></span><a href="https://www.facebook.com/profile.php?id=' + prof_id + '&sk=videos">' + my_videos + '</a></div><div class="menuone" id="profvis"><span></span><p>' + profil_visitor + '</p><b class="yellow">new</b></div><div class="menuone"><span></span><a href=https://www.facebook.com/profile.php?id=' + prof_id + '&sk=likes>' + my_likes + '</a></div><div class="menuone"><span></span><a href=https://www.facebook.com/games/?from_bookmark=1>' + my_apps + '</a></div><div class="menuone"><span></span><a href="/notifications">' + my_notifications + '</a></div><div class="menuone events dropdownextcl"><div class="droxdownabsext"><a href="/events/upcoming">' + event_upcoming + '</a><a href="/events/calendar">' + event_calendar + '</a><a href="/events/subscribed">' + event_subscribed + '</a><a href="/events/past">' + event_past + '</a><a href="#" role="button" data-gt="{"rank":"5"}" rel="dialog" ajaxify="/ajax/events/create/?acontext={"ref":2,"ref_dashboard_filter":"upcoming","action_history":"null"}">' + new_event + '</a></div><span></span>' + nb_event_message + '<a href="https://www.facebook.com/events/upcoming">' + my_events + '</a> <b class="green">new</b></div><div class="menuone dropdownextcl"><div class="droxdownabsext"><a href="/groups/?category=membership">' + my_groups + '</a><a href="/saved/">' + my_save + '</a><a href="/pages/feed?ref=bookmarks">' + my_pages_feed + '</a><a href=https://www.facebook.com/bookmarks/pages>' + my_pages + '</a><a href="/pages/create/?ref_type=bookmark">' + create_page + '</a><a href="https://developers.facebook.com/">Developer</a><a href="https://www.facebook.com/events/birthdays">' + my_frien_birthday + '</a><a href="https://www.facebook.com/settings">' + settings + '</a></div><span></span><a href="https://www.facebook.com">' + old_menu + ' &nbsp;&nbsp;→</a></div></div>';
  var parser = new DOMParser()
  var el = parser.parseFromString(menu, 'text/html');
  document.getElementById('leftCol').appendChild(el.body.firstChild);
  document.getElementById('leftCol').style.display = 'block';
  document.getElementById('profvis').onclick = function (e) {
    //console.log('clclcl');
    if (!document.getElementById('visitorsblockflat') || document.getElementById('visitorsblockflat').style.display == 'none') {
      visitorsfu();
      document.getElementById('visitorsblockflat').style.display = 'block';
      this.style.background = 'rgb(52, 93, 144)';
    } else {
      document.getElementById('visitorsblockflat').style.display = 'none';
      this.style.background = 'none';
    }
  }
}
window.onload = function () {
  // document.getElementsByClassName("uiSearchInput")[1].style.color = 'white';
  if (document.getElementById('profile_column_js') == null && hasClass(document.body, 'timelineLayout') || document.getElementById('profile_column_js') == null && hasClass(document.body, 'home') || document.getElementById('profile_column_js') == null && document.location.href.indexOf('facebook.com/messages') > 0 || document.getElementById('profile_column_js') == null && document.location.href.indexOf('facebook.com/groups') > 0) {
    prependMenu();
  }
}
setInterval(function () {
  if (document.getElementById('profile_column_js') == null && hasClass(document.body, 'timelineLayout') || document.getElementById('profile_column_js') == null && hasClass(document.body, 'home') || document.getElementById('profile_column_js') == null && document.location.href.indexOf('facebook.com/messages') > 0 || document.getElementById('profile_column_js') == null && document.location.href.indexOf('facebook.com/groups') > 0) {
    prependMenu();
  }
}, 1000);
function hasClass(element, cls) {
  return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > - 1;
}
function readCookie(name) {
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}