Skip to content

Instantly share code, notes, and snippets.

@belst
Created December 28, 2016 15:45
Show Gist options
  • Save belst/2072eaa898425062dc9286ac984f68ec to your computer and use it in GitHub Desktop.
Save belst/2072eaa898425062dc9286ac984f68ec to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Crates.io Readme
// @namespace https://bel.st/
// @version 0.1
// @description loads Readme files from github and displays them in the crate info area
// @author belst
// @match https://crates.io/crates/*
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant none
// ==/UserScript==
(function($) {
"use strict";
// TODO: remove waitForKeyElements
waitForKeyElements('#crate-links a:contains("Repository")', getReadme);
//getReadme($('#crate-links a:contains("Repository")'));
function getReadme(rep) {
let url = rep[0];
if(!url.hostname.endsWith('github.com')) return;
$.ajax({
headers: {
Accept: 'application/vnd.github.v3.html+json'
},
method: 'GET',
url: `https://api.github.com/repos${url.pathname.match(/^(.*?)(?:\.git)?$/)[1]}/readme`,
success: (data) => {
// TODO: Fix styling.
$('#main > div.crate-info > div.docs').append(`
<div class="readme" style="display: flex">
${data}
</div>`);
},
});
}
})(Ember.$);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment