Skip to content

Instantly share code, notes, and snippets.

@dtsn
Last active December 24, 2015 21:38
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dtsn/6866575 to your computer and use it in GitHub Desktop.
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