Page2LinkMD

    @@ -1,7 +1,10 @@ -// ==ClosureCompiler== -// @output_file_name default.js -// @compilation_level SIMPLE_OPTIMIZATIONS -// ==/ClosureCompiler== +/* + * @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;
  • /*
     * @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;
      } else if (githubPullRegexp.test(url)) {
        title = "PR#" + url.replace(githubPullRegexp, "$3") + " " + document.evaluate(githubTitleXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
      } 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 + ")"));
    })()
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2017/05/08 17:53:07 - 2017-05-08
  2. 2017/05/08 17:45:34 - 2017-05-08
  3. 2017/05/08 17:45:12 - 2017-05-08
  4. 2017/05/08 17:42:43 - 2017-05-08
  5. 2017/05/08 17:41:43 - 2017-05-08
  6. 2017/05/08 17:36:52 - 2017-05-08
  7. 2017/05/08 17:05:26 - 2017-05-08
  8. 2017/05/08 17:00:14 - 2017-05-08
  9. 2017/05/08 16:58:06 - 2017-05-08