Generates current active page to markdown link format. Makes guthub repo_top/issue/pr links to a formatted title
/*
* @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
*/
(function(){
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 url = location.href;
var title = "";
if (githubRegexp.test(url)){
if (githubRepoRegexp.test(url)) {
title = "Github " + url.replace(githubRepoRegexp, "$1/$2");
} else if (githubIssueRegexp.test(url)) {
title = "Issue#" + url.replace(githubIssueRegexp, "$3") + " " + document.evaluate(githubTitleXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML.trim();
} else if (githubPullRegexp.test(url)) {
title = "PR#" + url.replace(githubPullRegexp, "$3") + " " + document.evaluate(githubTitleXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML.trim();
} else {
title = document.title;
}
} else {
title = document.title;
}
title = title.replace(/[\[\]]/g,"\\$&").replace(/\\$/, "");
return void(prompt("Press Ctrl/Cmd + v to copy markdown", "[" + title + "](" + url + ")"));
})();