/*
* @title Page2LinkMD
* @description Generates current active page to markdown link format. Makes guthub repo_top/issue/pr links to a formatted title
* @include http://*
* @license MIT License
* @require
*/
var __githubRegexp = /^https?:\/\/github.com.*/g;
var __githubRepoRegexp = /^https?:\/\/github.com\/([^\/]+)\/([^\/]+)\/?$/g;
var __githubIssueRegexp = /^https?:\/\/github.com\/([^\/]+)\/([^\/]+)\/issues\/(\d+)/g;
var __githubPullRegexp = /^https?:\/\/github.com\/([^\/]+)\/([^\/]+)\/pull\/(\d+)/g;
var __githubTitleXPath = '//*[@id="partial-discussion-header"]/div[1]/h1/span[1]';
var __location_href_url = location.href;
var __link_title = "";
if (__githubRegexp.test(__location_href_url)){
if (__githubRepoRegexp.test(__location_href_url)) {
__link_title = __location_href_url.replace(__githubRepoRegexp, "$1/$2");
} else if (__githubIssueRegexp.test(__location_href_url)) {
__link_title = "Issue#" + __location_href_url.replace(__githubIssueRegexp, "$3") + " " + document.evaluate(__githubTitleXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
} else if (__githubPullRegexp.test(__location_href_url)) {
__link_title = "PR#" + __location_href_url.replace(__githubPullRegexp, "$3") + " " + document.evaluate(__githubTitleXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
} else {
__link_title = document.title;
}
} else {
__link_title = document.title;
}
__link_title = __link_title.replace(/[\[\]]/g,"\\$&").replace(/\\$/, "");
prompt("Press Ctrl/Cmd + v to copy markdown", "[" + __link_title + "](" + __location_href_url + ")");