Skip to content

Instantly share code, notes, and snippets.

@arabcoders
Last active December 16, 2015 20:59
Show Gist options
  • Save arabcoders/5496514 to your computer and use it in GitHub Desktop.
Save arabcoders/5496514 to your computer and use it in GitHub Desktop.
Slightly modified version of Twitter Instagram Cards by ChrisBradBury, i fixed few bugs with the @grant option, and i've added open/close button for images & its now works when you load older tweets or new tweets comes in. original script URL : https://userscripts.org/scripts/show/153881
// ==UserScript==
// @name Twitter Instagram Cards - Photo Viewer
// @namespace http://chrisbradbury.net
// @author Chris Bradbuyr
// @author AbdulMohsen B. A. A.
// @version 1.2
// @description Now that Instagram have pulled their twitter support, this script adds back inline instagram photos.
// @include https://twitter.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.js
// @grant setTimeout
// ==/UserScript==
$documentHeight = '';
debug = false;
function height() {
if (debug) {
console.log('Checking Tweets at Height ' + $(document).height() );
}
if ( $documentHeight != $(document).height() ) {
loadInstagram();
}
if (typeof timeout != 'undefined')
window.clearTimeout(timeout);
var timeout = window.setTimeout(height, 3000);
}
function loadInstagram(){
$documentHeight = $(document).height();
$('body').find('.js-tweet-text').each(function(key, value){
if ( value.innerHTML.indexOf("instagr.am") >= 0 ) {
if( value.innerHTML.indexOf('div class="instagram"') >= 0 ){ }else{
$instagram = value.innerHTML.split('http://instagr.am/p/');
$instagram = $instagram[1].split('/"');
$instagram = $instagram[0];
$(this).append('<br clear="both"><a onClick=\'$("#' + $instagram +'").toggle();\' href="javaScript:void(0);">Open/Close</a><br/><div class="instagram" id="'+ $instagram +'" style="margin-top: 10px; margin-bottom: 5px;"><img width="435" src="http://instagr.am/p/'+$instagram+'/media" /></div>');
if (debug) {
console.log('loading Instagram Image ID:' + $instagram);
}
}
}else if( value.innerHTML.indexOf("instagram.com/p/") >= 0 ){
if( value.innerHTML.indexOf('div class="instagram"') >= 0 ){ }else{
$instagram = value.innerHTML.split('instagram.com/p/');
$instagram = $instagram[1].split('/"');
$instagram = $instagram[0];
$(this).append('<br clear="both"><a onClick=\'$("#' + $instagram +'").toggle();\' href="javaScript:void(0);">Open/Close</a><br/><div class="instagram" id="'+ $instagram +'" style="margin-top: 10px; margin-bottom: 5px;"><img width="435" src="http://instagr.am/p/'+$instagram+'/media" /></div>');
if (debug) {
console.log('loading Instagram Image ID:' + $instagram);
}
}
}
});
}
$(document).ready(function(){
loadInstagram();
height();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment