Guest User

Untitled

a guest
Mar 1st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var MAX_TICKER_ITEMS = 3;
  2.  
  3. // Run in the next event tick to avoid the wrath of competing
  4. // userscripts that may hide certain widgets by index in the DOM.
  5. setTimeout(function() {
  6.    
  7.     // Extract the Feeds ticker contents and inject them into the
  8.     // sidebar as a new widget.
  9.     var $feed = $('#ticker-items').addClass('sidebar-widget');
  10.     var $star_widget = $('#starred-posts').parent();
  11.     $feed.insertBefore($star_widget);
  12.    
  13.     // display:none will be overridden as soon as a new Feeds item
  14.     // comes in. This is enough.
  15.     $('#feed-ticker').css('visibility', 'hidden');
  16.    
  17.    
  18.    
  19.     // This isn't a stylesheet - we have manual styling to do and
  20.     // we need to re-apply it every time there's a new Feeds item.
  21.     //
  22.     // The same hook allows us to apply an upper bound on number
  23.     // of items shown.
  24.     var styleAndTrimTickerItems = function() {
  25.        
  26.         // Apply styles to feeds items
  27.         $('.ticker-item').css('margin-bottom', '10px');
  28.         $('.ticker-item a').css('font-size', '8pt');
  29.         $('.ticker-item img').css('margin-right', '5px');
  30.        
  31.         // Limit list length
  32.         $('#ticker-items div:gt(' + (MAX_TICKER_ITEMS + 1) + ')').remove();
  33.     }
  34.    
  35.     // (http://stackoverflow.com/a/11546242/560648)
  36.     MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  37.     var observer = new MutationObserver(styleAndTrimTickerItems);
  38.     observer.observe(document, {
  39.         subtree: true,
  40.         attributes: false,
  41.         childList: true
  42.     });
  43. }, 0);
Advertisement
Add Comment
Please, Sign In to add comment