Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Twitter - Disable t.co
- // @namespace localhost
- // @description Rewrites links in tweets to not use the t.co shortener.
- // @include https://twitter.com/*
- // @version 1.0
- // @grant none
- // ==/UserScript==
- // We can accomplish this with a MutationObserver. This will also affect the
- // initial page load, because the document mutates a few times during the
- // initial page load.
- var observerInit = { attributes: false, childList: true, characterData: false, subtree: true };
- // because our observerInit tells the observer to ignore attribute mutations,
- // this observer's callback doesn't need to disconnect and reconnect the observer
- var observer = new MutationObserver( function( objects, observer ) {
- var links, i;
- links = document.querySelectorAll( 'a.twitter-timeline-link[data-expanded-url]:not([data-tco-disabled])' );
- for( i = 0; i < links.length; i++ ) {
- links[i].setAttribute( 'href', links[i].getAttribute( 'data-expanded-url' ) );
- links[i].setAttribute( 'data-tco-disabled', 'true' );
- }
- } );
- observer.observe( document.body, observerInit );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement