Created
March 28, 2015 14:57
-
-
Save yuiAs/9a7a7464a3383bcd1583 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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