Created
December 11, 2014 15:22
-
-
Save killua99/d974cd5ee1440e7ea753 to your computer and use it in GitHub Desktop.
Instagram Preview on Tweetdeck Webapp
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 Show Instagram photos | |
// @namespace http://killua.me/ | |
// @version 0.1 | |
// @description This allows instagram pictures to be shown like normal | |
// @match http*.twitter.com/* | |
// @copyright 2014+, Luigi Guevara | |
// @require https://code.jquery.com/jquery-1.11.1.min.js | |
// @grant none | |
// ==/UserScript== | |
;(function($, document, window) { | |
'use strict'; | |
if (typeof $ == 'undefined') { | |
var $ = unsafeWindow.jQuery; | |
} | |
var insta_pic; | |
var raw_data; | |
var target = $('#container')[0]; | |
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; | |
var Config = { childList: true, characterData: true, attributes: true, subtree: true }; | |
var showInstagramPic = function(pic) { | |
var html_output; | |
html_output += '<div class="js-media-preview-container position-rel margin-vm">'; | |
html_output += '<a href="' + pic + '"><img src="' + pic + 'media" alt="' + pic + 'media" /></a>'; | |
html_output += '<div>'; | |
return html_output; | |
}; | |
var Observer = new MutationObserver (function( mutations ) { | |
console.log(mutations); | |
mutations.forEach(function( mutation ) { | |
console.log(mutation.type); | |
// DOM NodeList | |
var newNodes = mutation.addedNodes; | |
if( newNodes !== null ) { | |
var $nodes = $(newNodes); | |
for (var i = 0; i < $nodes.lenght; i++) { | |
raw_data = $nodes[i].attr('data-full-url').match(/http:..instagram.com....*\//); | |
if (raw_data !== null) { | |
insta_pic = $nodes[i].attr('data-full-url'); | |
$nodes[i].html(showInstagramPic(insta_pic)); | |
} | |
} | |
} | |
}); | |
}); | |
Observer.observe(target, Config); | |
}) (jQuery.noConflict(true), document, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment