Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save yuiAs/9a7a7464a3383bcd1583 to your computer and use it in GitHub Desktop.

Select an option

Save yuiAs/9a7a7464a3383bcd1583 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Tweetdeck Thumbnail from TwitterCards
// @include https://tweetdeck.twitter.com/*
// @version 1.0
// @grant unsafeWindow
// @license MIT License
// ==/UserScript==
(function(){
var TD = unsafeWindow.TD;
TD.services.TwitterStatus.prototype.fromJSONObject_prev = TD.services.TwitterStatus.prototype.fromJSONObject;
TD.services.TwitterStatus.prototype.fromJSONObject = function(e) {
if (!e.entities.media && e.cards) {
var cards = e.cards.photos || e.cards.summaries || e.cards.players;
var card = cards[0];
if (card && card.images.web) {
var url = {
// expanded_url: card.images.web.image_url,
expanded_url: card.images.web.image_url_2x,
url: "",
display_url: "",
indices: [0, 0],
};
// e.entities.urls.unshift(url);
e.entities.urls.push(url);
}
}
return this.fromJSONObject_prev(e);
};
TD.services.TwitterMedia.SERVICES["twittercards"] = /^https?:\/\/\w+\.twimg\.com\/\d\/proxy\.(?:jpe?g|png|gif|bmp)\?.+/;
TD.services.TwitterMedia.prototype.small_prev = TD.services.TwitterMedia.prototype.small;
TD.services.TwitterMedia.prototype.small = function() {
if (this.service === "twittercards") {
return this.urlMatches[0];
}
return this.small_prev();
};
TD.services.TwitterMedia.prototype.medium_prev = TD.services.TwitterMedia.prototype.medium;
TD.services.TwitterMedia.prototype.medium = function() {
if (this.service === "twittercards") {
return this.small();
}
return this.medium_prev();
};
TD.services.TwitterMedia.prototype.large_prev = TD.services.TwitterMedia.prototype.large;
TD.services.TwitterMedia.prototype.large = function() {
if (this.service === "twittercards") {
return this.small();
}
return this.large_prev();
};
TD.services.TwitterStatus.prototype.render_prev = TD.services.TwitterStatus.prototype.render;
TD.services.TwitterStatus.prototype.render = function(e) {
var medias = this._media;
if (medias && medias.length > 0) {
for (var i = 0; i < medias.length; i++) {
if (medias[i].service === "twittercards") {
e.mediaPreviewSize = TD.vo.Column.MEDIA_PREVIEW_SIZE_SMALL;
break;
}
}
}
return this.render_prev(e);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment