Greasy Fork is available in English.

何も選択していない状態でCtrl+Cを押すとページのタイトル+改行+URL+改行をクリップボードにコピーする

Amazonや静画(漫画)ならURLの無駄を削る ニコ動・静画・Web漫画アンテナのマイリスト画面ならリストの列挙をコピー

Mint 2018.06.08.. Lásd a legutóbbi verzió

// ==UserScript==
// @name        何も選択していない状態でCtrl+Cを押すとページのタイトル+改行+URL+改行をクリップボードにコピーする
// @description Amazonや静画(漫画)ならURLの無駄を削る ニコ動・静画・Web漫画アンテナのマイリスト画面ならリストの列挙をコピー
// @match       *://*/*
// @version     0.2
// @grant       none
// @namespace https://greasyfork.org/users/181558
// ==/UserScript==

(function() {

  document.addEventListener("keydown", function(e) { //キー入力
      if (!/input|textarea/i.test(e.target.tagName) && !e.shiftKey && !e.altKey && !e.ctrlKey && e.which == 65 && /www\.nicovideo\.jp\/my\/mylist/.test(location.href)) { // ニコ動マイリストでAで全てチェック
        for (let a of elegeta('//div[@class="checkBoxOuter"]/input[@name="checkbox"]')) a.click();
        return;
      }
      if (!e.shiftKey && !e.altKey && e.ctrlKey && e.which == 67) {
        if (/input|textarea/i.test(e.target.tagName)) return;
        if (window.getSelection() != "") {
          //選択文字列がある
          popup("<B>" + window.getSelection().toString().length + "文字:</B><BR><pre><code>" + window.getSelection().toString() + "</code></pre>");
          return;
        }

        var doc = location.href;
        var txt1 = doc;
        var txt2 = txt1;

        if ((txt1.indexOf("www.amazon.co.jp/") != -1) && (txt1.indexOf("/dp/") != -1))
          txt2 = "http://www.amazon.co.jp/dp/" + txt1.substr(txt1.indexOf("/dp/") + 4, 10);

        if ((txt1.indexOf("www.amazon.co.jp/") != -1) && (txt1.indexOf("/ASIN/") != -1))
          txt2 = "http://www.amazon.co.jp/dp/" + txt1.substr(txt1.indexOf("/ASIN/") + 6, 10);

        if ((txt1.indexOf("www.youtube.com/embed/") != -1) && (txt1.indexOf("/ASIN/") != -1))
          txt2 = "http://www.amazon.co.jp/dp/" + txt1.substr(txt1.indexOf("/ASIN/") + 6, 10);

        if (/seiga\.nicovideo\.jp\/comic/.test(txt1)) txt2 = txt1.replace(/\?track=.*/, ""); // 静画(マンガ)短縮
        if (/seiga\.nicovideo\.jp\/watch\/mg/.test(txt1)) txt2 = txt1.replace(/\?track=.*/, "");

        if (/www\.youtube\.com\/embed\//.test(txt1)) txt2 = txt1.replace(/\?.*/, "").replace(/embed/, "watch");

        var ret = (navigator.platform.indexOf("Win") != -1) ? "\r\n" : "\n";
        var title = document.title.replace(/ https?:.*/, "");
        var txt = document.title + ret + txt2 + ret;

        // 列挙するタイプのサイトなら
        if (/seiga\.nicovideo\.jp\/my\/manga\/favorite|webcomics\.jp\/mylist|webcomics\.jp\/bookmark|www\.nicovideo\.jp\/my\/mylist|seiga\.nicovideo\.jp\/my\/clip/.test(txt1)) {
          var rekkyo = ['//div[@class="title"]/a', '//div[@class="entry-title"]/a', '//div[@class="mylistVideo"]/h5/a', '//div[@class="illust_box_li cfix"]/div/div[@class="text_ttl"]/a'];
          txt = ""; //title+ret;
          txt2 = "";
          var num = 0;
          for (let target of rekkyo) {
            var ele = elegeta(target);
            for (let a of ele) {
              num++;
              txt += a.innerText + ret + a.href.replace(/\?track=.*/, "") + ret;
              txt2 += a.innerText + "<BR>" + a.href.replace(/\?track=.*/, "") + "<BR>";
            }
          }
          title += " " + num + "件";
          txt = title + ret + txt;
        }

        // クリップボードにコピー
        var a = document.createElement("textarea");
        a.value = txt;
        document.body.appendChild(a);
        a.select();
        document.execCommand("copy");
        a.parentElement.removeChild(a);

        // バルーン表示
        popup("<B>" + title + "</B><BR>" + txt2);
        //        popup("<TT><B>" + title + "</B><BR>" + txt2 +"</TT>");

        e.preventDefault();
        return;
      }
    },
    false);
  return;

  function elegeta(xpath) {
    var ele = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    var array = [];
    for (var i = 0; i < ele.snapshotLength; i++) array[i] = ele.snapshotItem(i);
    return array;
  }

  function eleget0(xpath) {
    var ele = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    return ele.snapshotLength > 0 ? ele.snapshotItem(0) : "";
  }
  // バルーン表示
  function popup(txt) {
    var panel = document.createElement("div");
    panel.setAttribute("style", "max-width:95%; right:0; top:0; z-index:2147483647; opacity:0.8; text-align:left; line-height:1.1; position:fixed; font-size:15px; margin:15px;  text-decoration:none; padding:15px 15px; border-radius:7px; background-color:#000000; color:#ffffff;  box-shadow:5px 5px 8px #0004; border:2px solid #fff; font-family: 'MS UI Gothic','Meiryo UI','Yu Gothic UI','Arial',sans-serif;");
    //    panel.setAttribute("style", "max-width:95%; right:0; top:0; z-index:10000; opacity:1; text-align:left; line-height:1.1; position:fixed; font-size:15px; margin:15px;  text-decoration:none; padding:15px 15px; border-radius:7px; background-color:rgba(0,0,0,0.8); color:rgba(255,255,255,1);  box-shadow:5px 5px 8px #0004; border:2px solid rgba(255,255,255,0.9); font-family: 'MS UI Gothic','Meiryo UI','Yu Gothic UI','Arial',sans-serif;");
    //panel.setAttribute("style", "right:0; top:0; z-index:10000; opacity:1; text-align:left; line-height:1.1; position:fixed; font-size:15px; margin:15px;  text-decoration:none; padding:15px 15px; border-radius:7px; background-color:#ffffe0; color:#000000;  box-shadow:5px 5px 5px #0004; border:1.5px solid #000; font-family: 'MS UI Gothic','Meiryo UI','Yu Gothic UI','Arial',sans-serif;");
    panel.innerHTML = txt;

    document.body.appendChild(panel);
    setTimeout(function() { panel.parentElement.removeChild(panel); }, 4000);
    return;
  }
})();