Last active
October 26, 2017 05:46
-
-
Save mavc/727c5a4c68f992f628440824a86b9a78 to your computer and use it in GitHub Desktop.
This file contains 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 twimg-icon | |
// @namespace github.com/mavc | |
// @description Download source images on Twitter. | |
// @include https://twitter.com/* | |
// @exclude https://twitter.com/i/* | |
// @version 1.1.1 | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js | |
// @grant none | |
// ==/UserScript== | |
$(document).ready(function () { | |
const SELECTOR = 'div.AdaptiveMedia-container img'; | |
let findImages = (tweet) => { | |
return tweet | |
.find(SELECTOR) | |
.map((i, img) => $(img).attr('src')) | |
.get() | |
.filter(src => /\.twimg\./.test(src)) | |
.map(src => `${src}:orig`); | |
}; | |
let makeIcon = (src) => { | |
let icon = $('<span>').addClass('Icon Icon--camera'); | |
icon = $('<span>') | |
.addClass('IconContainer') | |
.append(icon); | |
icon = $('<span>') | |
.addClass('ProfileTweet-actionButton u-textUserColorHover') | |
.append(icon); | |
return $('<a>') | |
.css({display: 'inline-block', 'min-width': '25px'}) | |
.addClass('twimg-button') | |
.attr('href', src) | |
.attr('target', '_blank') | |
.append(icon); | |
}; | |
$('body') | |
.on('mouseenter', 'div.tweet', function () { | |
const tweet = $(this); | |
const imgs = findImages(tweet); | |
if (imgs.length > 0) { | |
console.debug('Images: ', imgs); | |
tweet.find('.twimg-button').remove(); | |
const footer = tweet.find('div.stream-item-footer div.ProfileTweet-actionList'); | |
imgs.forEach(src => { footer.append(makeIcon(src)); }); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment