Facebook Chat Emoticons Bar

Adds an emoticon bar to Facebook chat

  1. // ==UserScript==
  2. // @name Facebook Chat Emoticons Bar
  3. // @description Adds an emoticon bar to Facebook chat
  4. // @include http://facebook.com/*
  5. // @include http://*.facebook.com/*
  6. // @include https://facebook.com/*
  7. // @include https://*.facebook.com/*
  8. // @exclude http://*.channel.facebook.com/*
  9. // @exclude https://*.channel.facebook.com/*
  10. // @author bitMAN
  11. // @version 0.21
  12. // @versionnumber 0.21
  13. // @license Attribution-NonCommercial-NoDerivs 3.0 Unported (CC BY-NC-ND 3.0); http://creativecommons.org/licenses/by-nc-nd/3.0/
  14. // @namespace http://userscripts.org/scripts/show/50826
  15. // ==/UserScript==
  16. //
  17.  
  18. // List of emoticons
  19. // :) :( :D >:( -_- :/ o.O :p :'( >:O :v 3:) :o :3 ;) :* :|] 8) <3 (Y) :putnam: 8| ^_^ (^^^) O:) <(") :42: <(") O.o
  20.  
  21. var version, HttpsOn, ImagesURL, ResourcesURL, storage, emotsInfo, spemotsInfo, headTag, styleTag, ArrowStyleUp, ArrowStyleDown, fEmotBarDom, fEmotsListDom, fArrow;
  22.  
  23. version = 0.19;
  24. HttpsOn = window.location.href.match('https://')?true:false;
  25. ImagesURL = HttpsOn?'https://s-static.ak.fbcdn.net/images/':'http://static.ak.fbcdn.net/images/';
  26. ResourcesURL = HttpsOn?'https://s-static.ak.fbcdn.net/rsrc.php/':'http://static.ak.fbcdn.net/rsrc.php/';
  27.  
  28. /* START: This part of the code was written (partialy) by Vaughan Chandler for FFixer, special thanks to him :) */
  29.  
  30. storage = 'none';
  31.  
  32. try {
  33. if (typeof GM_getValue === 'function' && typeof GM_setValue === 'function') {
  34. GM_setValue('testkey', 'testvalue');
  35. if (GM_getValue('testkey', false) === 'testvalue') { storage='greasemonkey'; }
  36. }
  37. } catch(x) {}
  38. if (storage=='none' && typeof localStorage == 'object') { storage='localstorage'; }
  39.  
  40. function setValue(key, value) {
  41. switch (storage) {
  42. case 'greasemonkey':
  43. GM_setValue('0-'+key, value);
  44. break;
  45. case 'localstorage':
  46. localStorage['femotbar-0-'+key] = value;
  47. break;
  48. }
  49. }
  50.  
  51. function getValue(key, value) {
  52. switch (storage) {
  53. case 'greasemonkey':
  54. return GM_getValue('0-'+key, value);
  55. case 'localstorage':
  56. var val = localStorage['femotbar-0-'+key];
  57. if (val=='true') { return true; }
  58. else if (val=='false') { return false; }
  59. else if (val) { return val; }
  60. break;
  61. }
  62. return value;
  63. }
  64. function xmlhttpRequest(params, callBack) {
  65. if (typeof GM_xmlhttpRequest !== 'undefined') {
  66. params['onload'] = callBack;
  67. return GM_xmlhttpRequest(params);
  68. }
  69. return null;
  70. }
  71.  
  72. function openInTab(url) {
  73. if (typeof GM_openInTab !== 'undefined') { GM_openInTab(url); }
  74. else { window.open(url); }
  75. }
  76.  
  77. function UpdateCheck() {
  78. if(parseInt(getValue('LastUpdate', '0')) + 86400000 <= (new Date().getTime())) {
  79. try {
  80. xmlhttpRequest( { method: 'GET',
  81. url: 'http://userscripts.org/scripts/source/50826.meta.js?' + new Date().getTime(),
  82. headers: {'Cache-Control': 'no-cache'} },
  83. handleUpdateResponse);
  84. }
  85. catch (err) {
  86. alert('An error occurred while checking for updates:\n' + err);
  87. }
  88. }
  89. }
  90. function handleUpdateResponse(r) {
  91. setValue('LastUpdate', new Date().getTime() + '');
  92. if (r.responseText.match(/@version\s+(\d+\.\d+)/)[1] > version) {
  93. if(confirm( "There's an update available for 'Facebook Chat Emoticons Bar'.\n" +
  94. "Your version: " + version + "\n" +
  95. "New version: " + r.responseText.match(/@version\s+(\d+\.\d+)/)[1] + "\n" +
  96. "Do you wish to install it?")
  97. ) openInTab('http://userscripts.org/scripts/source/50826.user.js');
  98. }
  99. }
  100. // END
  101.  
  102. function createSelection(field, start, end) {
  103. if( field.createTextRange ) {
  104. var selRange = field.createTextRange();
  105. selRange.collapse(true);
  106. selRange.moveStart('character', start);
  107. selRange.moveEnd('character', end);
  108. selRange.select();
  109. } else if( field.setSelectionRange ) {
  110. field.setSelectionRange(start, end);
  111. } else if( field.selectionStart ) {
  112. field.selectionStart = start;
  113. field.selectionEnd = end;
  114. }
  115. field.focus();
  116. }
  117. function getCursorPosition(field) {
  118. var CursorPos = 0;
  119. if (field.selectionStart || field.selectionStart == '0') CursorPos = field.selectionStart;
  120. return (CursorPos);
  121. }
  122. UpdateCheck();
  123. emotsInfo = [':)', ':(', ':p', ':D', ':o', ';)', '8)', '8|', '>:(', ':/', ':\'(', '3:)', 'O:)', ':*', '<3', '^_^', '-_-', 'o.O', '>:O', ':v', ':3', '(Y)'];
  124. spemotsInfo = [':|]', 'emote/robot.gif', '(^^^)', 'emote/shark.gif', ':putnam:', 'emote/putnam.gif', '<(")', 'emote/penguin.gif', ':42:', 'emote/42.gif'];
  125.  
  126. headTag = document.getElementsByTagName('head')[0];
  127. if (headTag) {
  128. styleTag = document.createElement('style');
  129. styleTag.type = 'text/css';
  130. styleTag.innerHTML =
  131. '.chat_tab_emot_bar {padding-top: 2px; padding-bottom: 6px; line-height: 16px; padding-left: 2px; background:#EEEEEE none repeat scroll 0 0; border-style: solid; border-width: 0px 0px 1px 0px; border-color: #C9D0DA; position: static; }'+
  132. '.chat_arrow { background-image: url("'+ ResourcesURL + 'v1/zp/r/SBNTDM0S-7U.png"); background-position: 0 -48px; height: 5px; width: 9px; }';
  133. headTag.appendChild(styleTag);
  134. }
  135. ArrowStyleUp = 'cursor: pointer; position: absolute; right: 2px; -moz-transform: rotate(180deg); -webkit-transform: rotate(180deg);'
  136. ArrowStyleDown = 'cursor: pointer; position: absolute; right: 2px;'
  137. fEmotBarDom = document.createElement('div');
  138. fEmotBarDom.setAttribute('class','chat_tab_emot_bar');
  139. fEmotsListDom = document.createElement('div');
  140. fEmotsListDom.setAttribute('name','EmotsList');
  141. fEmotBarDom.appendChild(fEmotsListDom);
  142. for(i=0;i<emotsInfo.length;i+=1) {
  143. var fEmotsDom = document.createElement('img');
  144. fEmotsDom.setAttribute('alt',emotsInfo[i]);
  145. fEmotsDom.setAttribute('style','cursor: pointer; background-position: -'+ 16*i +'px 0px;');
  146. fEmotsDom.setAttribute('src',ImagesURL + 'blank.gif');
  147. fEmotsDom.setAttribute('class','emote_img');
  148. fEmotsListDom.appendChild(fEmotsDom);
  149. }
  150. for(i=0;i<spemotsInfo.length;i+=2) {
  151. var fEmotsDom = document.createElement('img');
  152. fEmotsDom.setAttribute('alt',spemotsInfo[i]);
  153. fEmotsDom.setAttribute('src',ImagesURL + spemotsInfo[i+1]);
  154. fEmotsDom.setAttribute('style','cursor: pointer;');
  155. fEmotsDom.setAttribute('class','emote_custom');
  156. fEmotsListDom.appendChild(fEmotsDom);
  157. }
  158. fArrow = document.createElement('i');
  159. fArrow.setAttribute('alt','');
  160. fArrow.setAttribute('class','img chat_arrow');
  161. fArrow.setAttribute('style',ArrowStyleUp);
  162. fEmotBarDom.appendChild(fArrow);
  163. var setting_visible = getValue('visible',true);
  164. document.addEventListener('DOMNodeInserted', fInsertedNodeHandler, false);
  165.  
  166. function fInsertedNodeHandler(event) {
  167. if(event.target.getElementsByClassName && event.target.getElementsByClassName('fbNubFlyout fbDockChatTabFlyout')[0])
  168. fInsertEmotBar(event.target);
  169. }
  170.  
  171. function fInsertEmotBar(fChatWrapper) {
  172. fChatToolBox = fChatWrapper.getElementsByClassName('fbNubFlyoutHeader')[0]
  173. fNewEmotBar = fEmotBarDom.cloneNode(true);
  174. setVisibility(fNewEmotBar);
  175. for(i=0;i<fNewEmotBar.firstChild.childNodes.length;i++) fNewEmotBar.firstChild.childNodes[i].addEventListener('click', fEmotClickHandler , false);
  176. fNewEmotBar.childNodes[1].addEventListener('click', fHideShowEmotBar , false);
  177. if(fChatToolBox.childNodes) fChatToolBox.insertBefore(fNewEmotBar,fChatToolBox.childNodes[1]);
  178. }
  179.  
  180. function fEmotClickHandler(event){
  181. var fChatInput = event.target.parentNode.parentNode.parentNode.parentNode.getElementsByClassName('fbNubFlyoutFooter')[0].getElementsByClassName('inputContainer')[0].getElementsByClassName('uiTextareaAutogrow input')[0];
  182. var pos = getCursorPosition(fChatInput);
  183. var txtbef = ''; var txtaft = '';
  184. if (fChatInput.value.charAt(pos-1) != ' ' && pos-1 > 0) txtbef = ' ';
  185. if (fChatInput.value.charAt(pos) != ' ') txtaft = ' ';
  186. fChatInput.value = fChatInput.value.substring(0,pos) + txtbef + event.target.getAttribute('alt') + txtaft + fChatInput.value.substring(pos);
  187. createSelection(fChatInput,pos + event.target.getAttribute('alt').length + txtaft.length + txtbef.length,pos + event.target.getAttribute('alt').length + txtaft.length + txtbef.length);
  188. }
  189. function fHideShowEmotBar(event){
  190. fChatBar = document.getElementsByName('EmotsList');
  191. if(fChatBar[0].getAttribute('style') == 'display: none;') {
  192. for(i=0;i<fChatBar.length;i++) {
  193. fChatBar[i].setAttribute('style','display: block;');
  194. fChatBar[i].parentNode.childNodes[1].setAttribute('style',ArrowStyleUp);
  195. fixHeightAndScroll(fChatBar[i]);
  196. }
  197. }
  198. else {
  199. for(i=0;i<fChatBar.length;i++) {
  200. fChatBar[i].setAttribute('style','display: none;');
  201. fChatBar[i].parentNode.childNodes[1].setAttribute('style',ArrowStyleDown);
  202. fixHeightAndScroll(fChatBar[i]);
  203. }
  204. }
  205. setValue('visible',!setting_visible);
  206. setting_visible = !setting_visible;
  207. }
  208. function setVisibility(DOM) {
  209. if(setting_visible) {
  210. DOM.firstChild.setAttribute('style','display: block;');
  211. DOM.childNodes[1].setAttribute('style',ArrowStyleUp);
  212. }
  213. else {
  214. DOM.firstChild.setAttribute('style','display: none;');
  215. DOM.childNodes[1].setAttribute('style',ArrowStyleDown);
  216. }
  217. }
  218. function fixHeightAndScroll(bar) {
  219. fChatContainer = bar.parentNode.parentNode.parentNode;
  220. var oldheight = parseInt(fChatContainer.children[2].style.height.replace("px",""));
  221. var newheight = 285 - (fChatContainer.children[0].clientHeight + fChatContainer.children[1].clientHeight + fChatContainer.children[3].clientHeight + 1);
  222. fChatContainer.children[2].style.height = newheight + "px";
  223. fChatContainer.children[2].scrollTop += oldheight - newheight;
  224. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址