Skip to content

Instantly share code, notes, and snippets.

@RoxasShadow
Last active August 29, 2016 21:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoxasShadow/4111c4ad781613069928 to your computer and use it in GitHub Desktop.
Save RoxasShadow/4111c4ad781613069928 to your computer and use it in GitHub Desktop.
[https://jii.moe/4kxSLhecl.png] Add an "Open images" link inside the gear to the left of the "Following" button in the tweet modal to open the uncompressed version of each image.
// ==UserScript==
// @name Twimg gallery opener
// @namespace https://gist.github.com/RoxasShadow/4111c4ad781613069928
// @description Add an "Open images" link inside the gear to the left of the "Following" button in the tweet modal to open the uncompressed version of each image.
// @include https://twitter.com/*
// @author Roxas Shadow
// @version 3
// @grant none
// ==/UserScript==
window.addEventListener('load', function() {
// https://raw.githubusercontent.com/adampietrasiak/jquery.initialize/master/jquery.initialize.js
!function(a){a.fn.initialize=function(b,c){var d=this,e=d.selector;if("function"!=typeof b||!e)return a(d);var f=a("body")[0];if(d.firstInitsCalled=d.firstInitsCalled||[],"function"==typeof c&&d.firstInitsCalled.indexOf(c)==-1&&(d.firstInitsCalled.push(c),c()),d.initData=d.initData||{},d.initData[e]=d.initData[e]||[],d.initData[e].push(b),a(this).each(function(){this.initsCalled=this.initsCalled||[],this.initsCalled.indexOf(b)==-1&&(this.initsCalled.push(b),a(this).each(b))}),!this.initializedObserver){this.initializedObserver=!0,window.MutationObserver=window.MutationObserver||window.WebKitMutationObserver;var g=new MutationObserver(function(b){a.each(b,function(b,c){var f=a();"attributes"==c.type&&(f=a(c.target)),"childList"==c.type&&c.addedNodes.length&&a.each(c.addedNodes,function(a,b){f=f.add(b)});for(e in d.initData){var g=d.initData[e],h=f.find(e);f.is(e)&&(h=h.add(f)),h.each(function(){var b=this;b.initsCalled=b.initsCalled||[],a.each(g,function(c,d){b.initsCalled.indexOf(d)==-1&&(b.initsCalled.push(d),a(b).each(d))})})}})}),h={attributes:!0,childList:!0,characterData:!1,subtree:!0};g.observe(f,h)}return a(this)}}(jQuery);
var $tweet = $('.permalink-tweet-container');
var galleryTpl = '' +
'<li class="__open-gallery pretty-link not-blocked" role="presentation">' +
'<button class="dropdown-link" type="button" role="menuitem">' +
'Open images' +
'</button>' +
'</li>' +
'';
$tweet.initialize(function() {
$tweet.find('li:first').after(galleryTpl);
});
$(document).on('click', '.__open-gallery button', function() {
$.unique($tweet
.find('.AdaptiveMedia-photoContainer > img')
.add($tweet.find('.OldMedia-photoContainer > img'))
.map(function(i, e) { return e.src + ':orig' })
.sort()
).each(function(i, e) {
window.open(e);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment