Facebook Old NavBar by LaNouille974

Set positions of Facebook navbar elements as in the previous version of the social network: friends requests, messages and notifications on the left (next to logo) and the other ones on the right.

目前為 2014-07-31 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Facebook Old NavBar by LaNouille974 
// @description Set positions of Facebook navbar elements as in the previous version of the social network: friends requests, messages and notifications on the left (next to logo) and the other ones on the right.
// @namespace   https://www.facebook.com
// @include     https://www.facebook.com/*
// @version     1.1.01
// @grant       none
// @require     https://code.jquery.com/jquery-1.11.0.min.js
// ==/UserScript==

$.noConflict();
jQuery( document ).ready(function($) {
    
    /*** Configuration ***/
    var defaultNickName = 'LaNouille974';
    var defaultPic = 'http://img11.hostingpics.net/pics/962935runico.png';
    
    var navBar = $('#blueBarNAXAnchor');
    var logo = navBar.find('h1:first')
    /**** End Configuration ***/
    
    var originalNavRight = navBar.find('div.rfloat:first');
    
    //Cloner la navRight
    var newNavRight = originalNavRight.clone();
    
    //Un peu de CSS pour les nouvelles navBar
    newNavRight.css({
        'float': 'left',
		'margin-left': logo.width() + 2 + 'px',
		'margin-right': '10px'
    });  
    
    //Retirer les éléments indésirables de chaque navBar
    removeNavElements(originalNavRight, 'old');
    removeNavElements(newNavRight, 'new');
    
    
    //Personnalisation
    var li = $("<li/>");
    li.attr('id', 'thenoodle');
    li.attr('title', 'Cliquer pour changer le texte');
    li.addClass('navItem tinyman litestandNavItem').text(defaultNickName);
    li.prependTo(originalNavRight.children('ul:first'));
    
    $('li#thenoodle').css({
        'height': '25px',
        'line-height': '25px',
        'color': 'white',
        'font-weight': 'bold',
        'position': 'relative',
        'left': '-25px',
        'top': '-2px',
        'background-image': "url('"+ defaultPic +"')",
        'background-repeat': 'no-repeat',
        'background-size': '25px 25px',
        'padding-left' : '32px',
        'cursor': 'pointer',
        'float': 'left'
    });
    
	//Animation fadeIn/fadeOut perpétuel
    infiniteFadeInOut($('li#thenoodle'), true);
    
    //Changer le pseudo à la volée
    $('li#thenoodle').click(function(){
        changeNickName($(this));
    });
    
    //Ajoute la nouvelle navBar à gauche
    newNavRight.prependTo(logo.parent());
    
    //Modifier emplacements popup
    //Messages
    $("#fbMessagesFlyout").parent().click(function() {
        //Fleche
        $('#fbMessagesFlyout .beeperNub').css({
             'right': '0',
             'left': '35px'
        });
        
        //Popup
        $('#fbMessagesFlyout').css({
            'right': '0',
             'left': '-30px'
        });
    });
    
    //Friends requests
    $("#fbRequestsFlyout").parent().click(function() {
        //Fleche
        $('#fbRequestsFlyout .beeperNub').css({
            'left': '4px' 
        });
        
        //Popup
        $("#fbRequestsFlyout").css({
            'left': '0',
        });
    });
    
    //Notifications
    $('#fbNotificationsFlyout').parent().click(function(){
        //Fleche
        $('#fbNotificationsFlyout .beeperNub').css({
            'right': '0',
             'left': '4px'
         });
        
        //Popup
        $("#fbNotificationsFlyout").css({
            'right': 'auto',
        });
    });

    
    /*** FUNCTIONS ***/
    
    //FadeIn puis fadeOut en boucle de l'élément passé en paramètre
    function infiniteFadeInOut (elem, fadeOut) {
        var targetOpacity = fadeOut ? 0.5 : 1;
        var duration = fadeOut ? 2000 : 500;
        
        fadeOut = !fadeOut; 
            
        elem.animate({
            opacity: targetOpacity 
        }, duration, 'swing', function() {
            infiniteFadeInOut($(this), fadeOut);
        });
    }
    
    //Retire les li indésirables de la navBar passé en param
    //Type = old ou Type = new
    function removeNavElements(navBar, type) {
      
        var elementsToRemove = [];
        
        if (type == 'new')
            elementsToRemove = [0, 1, 4, 5, 6];
        else
            elementsToRemove = [2, 3];
        
        navBar.children('ul:first').children('li').each(function(i) {
            
            //console.log(elementsToRemove);
            
            if ($.inArray(i, elementsToRemove) !== -1) {
               $(this).remove();
               //console.log(i);
            }
        });
    }
    
    function changeNickName(domElem) {
        var precNickName = domElem.text();
        var newNick = '';
        
        do {
            newNick = prompt('Nouveau texte (12 caractères max, taper "!q" pour quitter) :');
            
            if (newNick === null || newNick == '!q') break;
            else if (newNick.length > 12) 
                alert('Nouveau texte trop long ! 12 caractères max. (' + newNick.length + ' saisis)');
            
        } while (newNick.length > 12 || newNick == '')
        
        console.log(newNick);    
        
        if (newNick == null ) {
            if (precNickName == '')
                newNick = defaultNickName;
            else
                newNick = precNickName;
        } 
        else if(newNick == '!q') newNick = precNickName;    
            
        domElem.text(newNick);
    }
});