Last active
December 19, 2015 00:39
-
-
Save jrunning/5870126 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
| var seenLinks = {} | |
| function removeNewsItemParent(el) { | |
| return $(el).closest('.news > .alert').remove() | |
| } | |
| function getGist(gistId) { | |
| return $.get('https://api.github.com/gists/' + gistId); | |
| } | |
| function getGistDescription(gist) { | |
| if(gist.description && gist.description.length) { | |
| return gist.description; | |
| } | |
| return Object.keys(gist.files)[0]; | |
| } | |
| function gistPrettyName(gist) { | |
| var name = "Gist #" + gist.id, | |
| desc = getGistDescription(gist) | |
| ; | |
| if(desc) { name += ": " + desc; } | |
| return name; | |
| } | |
| function gistTitlesInit() { | |
| $(".news a[href*='gist.github']:not([data-pretty-title])") | |
| .each(function() { | |
| if(seenLinks[this.href]) { | |
| removeNewsItemParent(this); | |
| return | |
| } | |
| seenLinks[this.href] = true; | |
| gistId = this.href.split('/').pop(); | |
| getGist(gistId).done($.proxy(function(gist) { | |
| this.innerText = gistPrettyName(gist); | |
| this.setAttribute('data-pretty-title', true); | |
| }, this)); | |
| }); | |
| } | |
| $(function() { | |
| gistTitlesInit(); | |
| $(document).ajaxSuccess(function(e, xhr, opts) { | |
| if(opts.url.match(/^\/dashboard\/index/)) { gistTitlesInit(); } | |
| return true; | |
| }); | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment