Facebook Old NavBar by LaNouille974

Automatically repositions the elements of the Facebook navigation bar as they were in the previous version of the social network: friends requests, messages and notifications on the left (next to the logo), the other ones on the right. Lets also add a short personalized text (eg. a nickname) in the navbar. Ability to change the background color of the navigation bar.

当前为 2015-08-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Facebook Old NavBar by LaNouille974
  3. // @name:fr Ancienne barre de navigation de Facebook par LaNouille974
  4. // @description Automatically repositions the elements of the Facebook navigation bar as they were in the previous version of the social network: friends requests, messages and notifications on the left (next to the logo), the other ones on the right. Lets also add a short personalized text (eg. a nickname) in the navbar. Ability to change the background color of the navigation bar.
  5. // @description:fr Repositionne automatiquement les éléments de la barre de navigation de Facebook tels qu'ils étaient dans la version précédente du réseau social : invitations en ami, messages et notifications à gauche (à côté du logo), le reste à droite. Permet également d'ajouter un court texte personnalisé (ex: un pseudo) à la barre de navigation. Possibilité de changer la couleur de fond de la barre.
  6. // @namespace https://www.facebook.com
  7. // @include https://www.facebook.com/*
  8. // @version 1.3
  9. // @icon http://img15.hostingpics.net/pics/772325facebookoldnavbar11bylanouille974.png
  10. // @grant none
  11. // @require https://code.jquery.com/jquery-1.11.0.min.js
  12. // ==/UserScript==
  13.  
  14. $.noConflict();
  15.  
  16. jQuery( document ).ready(function($) {
  17. /*** Configuration ***/
  18. var defaultNickName = 'LaNouille974';
  19. var defaultNavBarColor = '';
  20. var defaultPic = 'http://img11.hostingpics.net/pics/962935runico.png';
  21. var colorpickerPic = 'http://img4.hostingpics.net/pics/387100colorpicker.png';
  22. var navBar = $('#blueBarNAXAnchor');
  23. var logo = navBar.find('h1:first')
  24. /**** End Configuration ***/
  25. /*** Global vars ***/
  26. var colorChanged = false;
  27. /*** End Global vars ***/
  28. var originalNavRight = navBar.find('div._2gyk:first');
  29. //Cloner la navRight
  30. var newNavRight = originalNavRight.clone();
  31. //Un peu de CSS pour les nouvelles navBar
  32. newNavRight.css({
  33. 'float': 'left',
  34. 'margin-left': logo.width() + 2 + 'px',
  35. 'margin-right': '10px',
  36. 'position': 'relative'
  37. });
  38. //Remettre les boutons permettant d'ouvrir les popups au premier plan
  39. newNavRight.find('a.jewelButton').css({
  40. 'z-index': '100'
  41. });
  42. //Retirer les éléments indésirables de chaque navBar
  43. removeNavElements(originalNavRight, 'old');
  44. removeNavElements(newNavRight, 'new');
  45. //Personnalisation
  46. var li = $("<li/>");
  47. li.attr('id', 'thenoodle');
  48. li.attr('title', 'Cliquer pour changer le texte');
  49. li.addClass('navItem tinyman litestandNavItem').text(defaultNickName);
  50. li.prependTo(originalNavRight.children('ul:first'));
  51. $('li#thenoodle').css({
  52. 'height': '25px',
  53. 'line-height': '25px',
  54. 'color': 'white',
  55. 'font-weight': 'bold',
  56. 'position': 'relative',
  57. 'left': '-25px',
  58. 'top': '-2px',
  59. 'background-image': "url('"+ defaultPic +"')",
  60. 'background-repeat': 'no-repeat',
  61. 'background-size': '25px 25px',
  62. 'padding-left' : '32px',
  63. 'cursor': 'pointer',
  64. 'float': 'left'
  65. });
  66. //Création du colorPicker invisible
  67. $('<input/>').attr({ type: 'color', id: 'colorpicker', name: 'colorpicker'}).appendTo('body');
  68. $('#colorpicker').css({
  69. 'position': 'absolute',
  70. 'top': -9999,
  71. 'left': -9999,
  72. });
  73. //Ajouter bouton colorPicker
  74. var liPicker = $("<li/>");
  75. liPicker.attr('id', 'pickerOpenerLi');
  76. var divPicker = $("<div/>");
  77. divPicker.attr('id', 'pickerOpenerDiv');
  78. divPicker.appendTo(liPicker);
  79. $('#thenoodle').after(liPicker);
  80. $('#pickerOpenerLi').css({
  81. 'position': 'relative',
  82. 'border-radius': '2px',
  83. 'cursor': 'pointer',
  84. 'width': '27px',
  85. 'height': '27px',
  86. 'float': 'left',
  87. 'top': '-3px',
  88. 'margin-right': '5px'
  89. });
  90. $('#pickerOpenerDiv').css({
  91. 'background-image': "url('"+ colorpickerPic +"')",
  92. 'background-repeat': 'no-repeat',
  93. 'background-size': '19px 19px',
  94. 'border-radius': '2px',
  95. 'width': '19px',
  96. 'height': '19px',
  97. 'position': 'relative',
  98. 'top': '4px',
  99. 'left': '4px'
  100. });
  101. liPicker.mouseenter(function(e){
  102. $(this).css('background', 'none repeat scroll 0 0 rgba(0, 0, 0, 0.1)');
  103. });
  104. liPicker.mouseleave(function(e){
  105. $(this).css('background', 'transparent');
  106. });
  107. //Ouvrir le colorPicker au clic
  108. $('#pickerOpenerLi').click(function(e) {
  109. $('#colorpicker').trigger('click');
  110. });
  111. $('#colorpicker').on('input', function() {
  112. changeColor($(this).val());
  113. });
  114. //Animation fadeIn/fadeOut perpétuel
  115. infiniteFadeInOut($('li#thenoodle'), true);
  116. //Changer le pseudo à la volée
  117. $('li#thenoodle').click(function(){
  118. changeNickName($(this));
  119. });
  120. //Ajoute la nouvelle navBar à gauche
  121. newNavRight.prependTo(logo.parent());
  122. //Modifier emplacements popup
  123. //Messages
  124. $("#u_0_5").parent().click(function() {
  125. //Fleche
  126. $('#u_0_5 .beeperNub').css({
  127. 'right': '0',
  128. 'left': '35px'
  129. });
  130. //Popup
  131. $('#u_0_5').css({
  132. 'right': '0',
  133. 'left': '-30px'
  134. });
  135. });
  136. //Friends requests
  137. $("#fbRequestsFlyout").parent().click(function() {
  138. //Fleche
  139. $('#fbRequestsFlyout .beeperNub').css({
  140. 'left': '4px'
  141. });
  142. //Popup
  143. $("#fbRequestsFlyout").css({
  144. 'left': '0',
  145. });
  146. });
  147. //Notifications
  148. $('#fbNotificationsFlyout').parent().click(function(){
  149. //Fleche
  150. $('#fbNotificationsFlyout .beeperNub').css({
  151. 'right': '0',
  152. 'left': '4px'
  153. });
  154. //Popup
  155. $("#fbNotificationsFlyout").css({
  156. 'right': 'auto',
  157. });
  158. });
  159. //Changer la couleur de la navBar au chargement si une couleur par défaut est définie
  160. changeColor(defaultNavBarColor);
  161.  
  162. /*$(document).on("DOMNodeInserted",function(evt){
  163. var target = $(evt.target);
  164. var parents = target.parents('#pagelet_timeline_recent');
  165. if (parents.length)
  166. console.log('node inserted in timeline');
  167. });*/
  168. /*** FUNCTIONS ***/
  169. //Change la couleur de la barre
  170. function changeColor(colorHex) {
  171. if (typeof colorHex === 'undefined' || colorHex == '')
  172. return;
  173. /*if (!colorChanged) {
  174. $('*').filter(function(i){
  175. return $(this).css("color") == $("<div style='color:#3b5998'/>").css("color");
  176. }).css("color", colorHex);
  177. colorChanged = true;
  178. }
  179. else {
  180. var currentNavBarColor = navBar.css('background-color');
  181.  
  182. $('*').filter(function(i){
  183. return $(this).css("color") == currentNavBarColor;
  184. }).css("color", colorHex);
  185. }*/
  186. navBar.css({
  187. 'background-color': colorHex,
  188. 'background-image' : 'none'
  189. });
  190. }
  191. //FadeIn puis fadeOut en boucle de l'élément passé en paramètre
  192. function infiniteFadeInOut (elem, fadeOut) {
  193. var targetOpacity = fadeOut ? 0.5 : 1;
  194. var duration = fadeOut ? 2000 : 500;
  195. fadeOut = !fadeOut;
  196. elem.animate({
  197. opacity: targetOpacity
  198. }, duration, 'swing', function() {
  199. infiniteFadeInOut($(this), fadeOut);
  200. });
  201. }
  202. //Retire les li indésirables de la navBar passé en param
  203. //Type = old ou Type = new
  204. function removeNavElements(navBar, type) {
  205. var elementsToRemove = [];
  206. if (type == 'new')
  207. elementsToRemove = [0, 1, 4, 5, 6];
  208. else
  209. elementsToRemove = [2, 3];
  210. navBar.children('ul:first').children('li').each(function(i) {
  211. //console.log(elementsToRemove);
  212. if ($.inArray(i, elementsToRemove) !== -1) {
  213. $(this).remove();
  214. //console.log(i);
  215. }
  216. });
  217. }
  218. function changeNickName(domElem) {
  219. var precNickName = domElem.text();
  220. var newNick = '';
  221. do {
  222. newNick = prompt('Nouveau texte (12 caractères max, taper "!q" pour quitter) :');
  223. if (newNick === null || newNick == '!q') break;
  224. else if (newNick.length > 12)
  225. alert('Nouveau texte trop long ! 12 caractères max. (' + newNick.length + ' saisis)');
  226. } while (newNick.length > 12 || newNick == '')
  227. console.log(newNick);
  228. if (newNick == null ) {
  229. if (precNickName == '')
  230. newNick = defaultNickName;
  231. else
  232. newNick = precNickName;
  233. }
  234. else if(newNick == '!q') newNick = precNickName;
  235. domElem.text(newNick);
  236. }
  237. });