Advertisement
XT-8147

disable_t.co.user

May 16th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Twitter - Disable t.co
  3. // @namespace   localhost
  4. // @description Rewrites links in tweets to not use the t.co shortener.
  5. // @include     https://twitter.com/*
  6. // @version     1.0
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. // We can accomplish this with a MutationObserver.  This will also affect the
  11. // initial page load, because the document mutates a few times during the
  12. // initial page load.
  13. var observerInit = { attributes: false, childList: true, characterData: false, subtree: true };
  14.  
  15. // because our observerInit tells the observer to ignore attribute mutations,
  16. // this observer's callback doesn't need to disconnect and reconnect the observer
  17. var observer = new MutationObserver( function( objects, observer ) {
  18.  var links, i;
  19.  links = document.querySelectorAll( 'a.twitter-timeline-link[data-expanded-url]:not([data-tco-disabled])' );
  20.  
  21.  for( i = 0; i < links.length; i++ ) {
  22.   links[i].setAttribute( 'href', links[i].getAttribute( 'data-expanded-url' ) );
  23.   links[i].setAttribute( 'data-tco-disabled', 'true' );
  24.  }
  25. } );
  26.  
  27. observer.observe( document.body, observerInit );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement