Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A first stab at a instagram loader for the web version of TweetDeck. It needs to be run on a loop and also needs to keep a record of all the links it has gathered.
// ==UserScript==
// @name TweetDeck Instagram
// @description Adds instagram to Tweetdeck
// @include https://tweetdeck.twitter.com/*
// @include chrome-extension://hbdpomandigafcibbmofojjchbcdagbl/*
// @version 0.1
// ==/UserScript==
var func = function () {
var Instagram = function () {
this.links = [];
};
Instagram.prototype.add = function (url, element) {
if (this.links.indexOf(url) !== -1) {
// already done this link
return;
}
this.links.push(url);
var script = document.createElement('script'),
// create a random callback
callback = 'instagram_' + Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
// add the url
script.src = 'https://api.instagram.com/oembed?url=' + url + '&callback=' + callback;
// append the script
document.head.appendChild(script);
// create the callback on the window object since this is annoyomoused
window[callback] = function (res) {
var ext = res.url.substring(res.url.lastIndexOf('.') + 1),
obj = false;
if (ext === 'mp4') {
obj = document.createElement('video');
obj.controls = 'true';
} else {
obj = document.createElement('img');
}
obj.src = res.url;
obj.width = "230";
obj.style.marginTop = "10px";
this.insertBefore(obj);
}.bind(element);
};
var instagram = new Instagram();
var poll = function () {
var nodes = document.getElementsByTagName('a');
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].innerHTML.indexOf('instagram.com') !== -1) {
instagram.add(nodes[i].innerHTML, nodes[i]);
}
}
};
setInterval(poll, 1000);
};
var script = document.createElement("script");
script.textContent = "(" + func.toString() + ")();";
document.body.appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment