markdown/scrapbox記法URL取得

Copy URL in markdown/scrapbox format

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name     markdown/scrapbox記法URL取得
// @version  1
// @grant    none
// @namespace https://twitter.com/root_T2
// @description Copy URL in markdown/scrapbox format
// @description:ja
// ==/UserScript==

// クリップボード
// https://qiita.com/butakoma/items/642c0ec4b77f6bb5ebcf
// https://qiita.com/simiraaaa/items/2e7478d72f365aa48356
// ショートカット
// https://stackoverflow.com/questions/3168574/how-can-i-create-a-shortcut-for-firefox-in-greasemonkey
// ascii code http://www9.plala.or.jp/sgwr-t/c_sub/ascii.html

var title = document.title;
title = title.replace(/\s*[\[\]]\s*/g,' ');
// scrapbox用
var str = '[' + title + ' ' + document.URL + ']';
// markdown
var str2 = '[' + title + '](' + document.URL + ')';


(function(){
document.addEventListener('keydown', function(e) {
  // pressed alt+a
  if (e.keyCode == 65 && !e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey) {
    var listener = function(e){

    e.clipboardData.setData("text/plain" , str);
    // 本来のイベントをキャンセル
    e.preventDefault();
    // 終わったら一応削除
    document.removeEventListener("copy", listener);
    }
  // コピーのイベントが発生したときに、クリップボードに書き込むようにしておく
  document.addEventListener("copy" , listener);

  // コピー
  document.execCommand("copy");
  // markdown alt+q
  }else if(e.keyCode == 81 && !e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey){
    var listener = function(e){

      e.clipboardData.setData("text/plain" , str2);
      e.preventDefault();
      document.removeEventListener("copy", listener);
      }
    document.addEventListener("copy" , listener);
    document.execCommand("copy");
  }
}, false);
})();