Advertisement
JZersche

FB Timestamps+PostID

Mar 22nd, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     FB: Full Timestamps 2018
  3. // @match    https://www.facebook.com/*
  4. // @match    https://*.facebook.com/*
  5. // @match    http://www.facebook.com/*
  6. // @match    http://*.facebook.com/*
  7. // @run-at   document-start
  8. // @grant    GM_addStyle
  9. // @author   wOxxOm & JZersche
  10. // @require  https://greasyfork.org/scripts/12228/code/setMutationHandler.js
  11. // @require  http://momentjs.com/downloads/moment.min.js
  12. // @version 3.1
  13. // @namespace https://greasyfork.org/users/95175
  14. // @description Shows full timestamps on Facebook posts
  15. // @downloadURL none
  16. // ==/UserScript==
  17.  
  18. var options = { weekday: 'long', year: 'numeric', month: 'numeric', day: '2-digit' };
  19.  
  20.  
  21. GM_addStyle(
  22.     '.full-timestamp { opacity: 0.85; color: #09f; }' +
  23.     '.full-timestamp:hover { opacity: 1.0; }' +
  24.     '.full-timestamp:before { content: ""; }' +
  25.     '.full-timestamp:after  { content: ""; }' +
  26.     '.timestampContent {display: none; }'
  27. );
  28.  
  29. // process the already loaded portion of the page if any
  30. expandDates(document.querySelectorAll('abbr[data-utime]'));
  31.  
  32. // process the stuff added from now on
  33. setMutationHandler(document, 'abbr[data-utime]', expandDates);
  34. setMutationHandler(document, '._5pcq', expandPostIDs);
  35.  
  36. function expandDates(nodes) {
  37.     for ( var i = 0, abbr; (abbr = nodes[i++]); )
  38. {
  39.         if (abbr.querySelector('.full-timestamp')) {
  40.             // already processed
  41.             continue;
  42.         }
  43.  
  44.         abbr.insertAdjacentHTML('beforeend', '<span class="full-timestamp">' +
  45.         ' on ' + abbr.title
  46.                                 .replace(/am|pm/,'')
  47.  
  48.                                 .replace(/0\d/, number => number[1]).replace(218,2018) +
  49.  
  50.                                 (moment(new Date(abbr.dataset.utime * 1000)).format(':ss') + abbr.title.match('pm|am') + '' ));
  51.     }
  52. }
  53.  
  54. function expandPostIDs(nodes) {
  55.     for ( var i = 0; i < nodes.length; i++ )
  56.     {
  57.         var element = nodes[i];
  58.         if(element.innerHTML.includes('Post ID') === false && element.className === '_5pcq')
  59.         {
  60.          element.insertAdjacentHTML('beforeend', '<br> ' +  element.href.replace('/groups/','Group: ').replace('/permalink/','<br>Post ID: ').slice(24,100).replace('/',''));
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement