Forked from lgp171188/auto-expand-tco-links-on-tweetdeck-website.user.js
Last active
June 22, 2016 08:45
-
-
Save darrik/0320b54d07d3ab99abfd to your computer and use it in GitHub Desktop.
Auto expand t.co links on Tweetdeck website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Auto expand t.co links on Tweetdeck website | |
// @namespace https://github.com/lgp171188 | |
// @include https://tweetdeck.twitter.com/* | |
// @version 2 | |
// @grant none | |
// ==/UserScript== | |
function expandTwitterShortlinks() { | |
var twitter_shortlinks = document.getElementsByClassName('url-ext'); | |
for (var i = 0; i < twitter_shortlinks.length; i++) { | |
var shortlink = twitter_shortlinks[i]; | |
if (shortlink.classList.contains('tco-url-expanded')) { | |
continue; | |
} | |
else { | |
var actual_url = shortlink.getAttribute('data-full-url'); | |
shortlink.setAttribute('href', actual_url); | |
shortlink.classList.add('tco-url-expanded'); | |
} | |
} | |
} | |
function expandTwitterShortimagelinks() { | |
var twitter_shortlinks = document.getElementsByClassName('js-media-image-link'), | |
i, shortlink, actual_url, tmp; | |
for(i = 0; i < twitter_shortlinks.length; i++) { | |
shortlink = twitter_shortlinks[i]; | |
if(shortlink.classList.contains('tco-url-expanded')) { | |
continue; | |
} | |
actual_url = shortlink.getAttribute('style'); | |
if(actual_url !== null) { | |
tmp = actual_url.match(/background-image:url\((.+?)\)/); | |
if(tmp !== null) { | |
shortlink.setAttribute('href', tmp[1]); | |
shortlink.classList.add('tco-url-expanded'); | |
} | |
} | |
} | |
} | |
function expandTwitterShortimagelinksInMediaEmbeds() { | |
var divs = document.getElementsByClassName('med-tray'), | |
tco = new RegExp('https?://t.co/[^"]+', 'g'), | |
i, medtray, full_link, ih; | |
for(i = 0; i < divs.length; i++) { | |
medtray = divs[i]; | |
if(medtray.classList.contains('tco-url-expanded')) { | |
continue; | |
} | |
ih = medtray.innerHTML; | |
full_link = ih.match(/img class=\"media-img\" src=\"([^\"]+)\"/); | |
if(full_link !== null && full_link.length > 0) { | |
medtray.classList.add('tco-url-expanded'); | |
medtray.innerHTML = ih.replace(tco, full_link[1]); | |
} | |
} | |
} | |
function allOfThem() { | |
expandTwitterShortlinks(); | |
expandTwitterShortimagelinks(); | |
expandTwitterShortimagelinksInMediaEmbeds(); | |
} | |
setInterval(allOfThem, 2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changes: Expand image links and don't run on every DOM change.