Created
April 7, 2015 15:01
-
-
Save orderthruchaos/2d964dbe9d61fb1e6276 to your computer and use it in GitHub Desktop.
Greasemonkey User Script: add hexdoc.pm link to hex.pm package information page.
This file contains 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 hex_pm_hexdocs_link | |
// @namespace http://orderthruchaos.bitbucket.org/ | |
// @copyright 2015+, Brett DiFrischia | |
// @license | |
// @description | |
// @grant GM_log | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js | |
// @include https://hex.pm/packages/* | |
// ==/UserScript== | |
this.$J = this.jQuery = jQuery.noConflict(true); | |
( | |
function () { | |
var get_package_id = function () { | |
return $J("div.container div.page-header h2 a").first().text() || ""; | |
}; | |
var safe_package_id = function () { | |
var pid = get_package_id(); | |
pid = pid.replace(/&/g, '&'); | |
pid = pid.replace(/</g, '<'); | |
pid = pid.replace(/>/g, '>'); | |
return pid; | |
}; | |
var safe_package_id = function () { | |
return encodeURIComponent(get_package_id()); | |
}; | |
var on_load = function() { | |
var css = 'div.container div.row div.col-sm-8 ' + | |
'dl.dl-horizontal.package-meta'; | |
var pid = safe_package_id(); | |
var dt = "<dt>hexdocs</dt>"; | |
var hexdocs_link = | |
"<a target='_blank' href='http://hexdocs.pm/" + safe_package_id()+ | |
"/'>" + pid + "</a>"; | |
var all = dt + "<dd>" + hexdocs_link + "</dd>"; | |
$J(css).first().append(all); | |
}; | |
$J(on_load); | |
} | |
)(); | |
// vim: sts=2 sw=2 ts=8 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment