// ==UserScript==
// @name 何も選択していない状態でCtrl+Cでページのタイトル+改行+URL+改行をクリップボードにコピー
// @description Amazonや静画(漫画)やGoogle検索ならURLのゴミを除去 ニコ動・静画・Web漫画アンテナのマイリスト画面ならリストの列挙をコピー(押すたびにソート条件変更) Shift+Cで除去文字列設定 Calil・yahooテレビ・駿河屋・ニコ動検索ならタイトルに検索ワードを挿入 Shift+Tでページタイトル部分後回し文字列設定
// @match *://*/*
// @version 0.5
// @grant none
// @namespace https://greasyfork.org/users/181558
// ==/UserScript==
(function() {
var sakujoRE = localStorage.getItem("ctrlcsakujoRE") || "";
var cckaisuu = 0;
var sakujoTitleRE = localStorage.getItem("ctrlcsakujoTitleRE") || "";
// Shift+T ページタイトル部分後回し
if (sakujoTitleRE) {
var hit = document.title.match(RegExp(sakujoTitleRE, "g"));
if (hit) document.title = document.title.replace(RegExp(sakujoTitleRE, "g"), "") + " " + hit;
}
// 検索ワードをページタイトルの最初に付ける
addtitle(/calil.jp\/local\/search/, "", '//form[@class="search"]/div/input|//input[@id="query"]'); //,'//div[@class="message"]',/$^/," | "); // calil検索
addtitle(/tv\.yahoo\.co\.jp\/search\/\?q=/, "", '//input[@class="generic_inputText floatl"]'); // yahooテレビ検索
addtitle(/www\.nicovideo\.jp\/mylist_search\//, "", '//input[@id="search_united"]', "", "", " - マイリスト検索 "); // ニコ動マイリスト検索
if (document.title.indexOf("|") === -1) addtitle(/www\.suruga-ya\.jp\/search\?/, "", '//input[@id="searchText"]', '//div[@id="topicPath"]', /駿河屋TOP.≫.|駿河屋TOP/gi); // 駿河屋検索
document.addEventListener("keydown", function(e) { //キー入力
if (/input|textarea/i.test(e.target.tagName)) return;
if (!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 == 84) { // shift+T ページタイトル部分後回し文字列設定
var str = prompt("shift+T:\r\n\"" + document.domain + "\" でページタイトルで後ろに移動したい文字列を正規表現で入力してください\r\n\r\n現在値:" + sakujoTitleRE + "\r\n", sakujoTitleRE);
sakujoTitleRE = str === null ? sakujoTitleRE : str;
if (sakujoTitleRE != "") {
localStorage.setItem("ctrlcsakujoTitleRE", sakujoTitleRE);
var hit = document.title.match(RegExp(sakujoTitleRE, "g"));
if (hit) document.title = document.title.replace(RegExp(sakujoTitleRE, "g"), "") + " " + hit;
} else { localStorage.removeItem("ctrlcsakujoTitleRE"); }
return;
}
if (e.shiftKey && !e.altKey && !e.ctrlKey && e.which == 67) { // shift+C 除去文字列設定
var str = prompt("shift+C:\r\n\"" + document.domain + "\" で Ctrl+C 押下時タイトルやURLや選択文字列から除去したい文字列を正規表現で入力してください\r\n\r\n現在値:" + sakujoRE + "\r\n", sakujoRE);
sakujoRE = str === null ? sakujoRE : str;
if (sakujoRE != "") { localStorage.setItem("ctrlcsakujoRE", sakujoRE); } else { localStorage.removeItem("ctrlcsakujoRE"); }
return;
}
if (!e.shiftKey && !e.altKey && e.ctrlKey && e.which == 67) { // ctrl+c
if (window.getSelection() != "") {
//選択文字列がある
var selection = window.getSelection().toString();
if (sakujoRE) {
selection = selection.replace(RegExp(sakujoRE, "gm"), ""); // Shift+C 除去文字列を除去
if (window.getSelection().toString() !== selection) copy2cb(selection);
}
popup("<B>" + selection.length + "文字:</B><BR><pre><code>" + selection + "</code></pre>");
return;
}
var doc = location.href;
var txt1 = doc;
var txt2 = txt1;
if (/www\.amazon\.co\.jp\/|www\.amazon\.com\//.test(txt1) && (txt1.indexOf("/dp/") != -1)) // Amazonのパラメータ除去
txt2 = "https://" + document.domain + "/dp/" + txt1.substr(txt1.indexOf("/dp/") + 4, 10);
if ((txt1.indexOf("www.amazon.co.jp/") != -1) && (txt1.indexOf("/ASIN/") != -1))
txt2 = "https://www.amazon.co.jp/dp/" + txt1.substr(txt1.indexOf("/ASIN/") + 6, 10);
if (/\/\/www\.google\.co\.jp\/search\?|\/\/www\.google\.com\/search\?/.test(txt1)) { // google検索結果のパラメータ除去
var para = txt1.split(/[&?]/);
txt2 = para[0] + "?";
var j = 0;
for (var i = 1; i < para.length; i++) {
console.log(para[i]);
var a = para[i].replace(/^ei=.*/, "").replace(/^oq=.*/, "").replace(/^gs_l=.*/, "").replace(/^hl=ja/, "").replace(/^source=.*/, "").replace(/^sa=.*/, "").replace(/^ved=.*/, "").replace(/^biw=.*/, "").replace(/^bih=.*/, "").replace(/^dpr=.*/, "").replace(/^ie=.*/, "").replace(/^oe=.*/, "").replace(/^client=.*/, "").replace(/^aqs=.*/, "").replace(/^sourceid=.*/, "").replace(/^btnG=.*/, "");
if (a !== "") {
txt2 += (j > 0 ? "&" : "") + a;
j++;
}
}
}
// google翻訳のパラメータ除去
if (/https?:\/\/translate\.google\.com\/translate|https?:\/\/translate\.googleusercontent\.com\/translate_c/.test(txt2)) {
txt2 = (txt2.match(/https?:\/\/translate\.google\.com\/translate|https?:\/\/translate\.googleusercontent\.com\/translate_c/)[0] + txt2.match(/[\?&]u=[^&]*/)).replace(/&/, "?");
}
if (/seiga\.nicovideo\.jp\/comic/.test(txt1)) txt2 = txt1.replace(/\?track=.*|\?_topic.*/, ""); // 静画(マンガ)のパラメータ除去
if (/seiga\.nicovideo\.jp\/watch\/mg/.test(txt1)) txt2 = txt1.replace(/\?track=.*|\?_topic.*/, "");
if (/www\.nicovideo\.jp\/user/.test(txt1)) txt2 = txt1.replace(/\?_topic.*/, ""); // ニコ動のパラメータ除去
if (/www\.nicovideo\.jp\/tag\//.test(txt1)) txt2 = txt1.replace(/[\?&]ref=[^&]*/, ""); // ニコ動のパラメータ除去
if (/www\.nicovideo\.jp\/search\//.test(txt1)) txt2 = txt1.replace(/\?f_range=0\&l_range=0\&opt_md=\&start=\&end=|[\?&]track=[^&]*/, ""); // ニコ動のパラメータ除去
if (/www\.youtube\.com\/embed\//.test(txt1)) txt2 = txt1.replace(/\?.*/, "").replace(/embed\//, "watch?v="); // youtube埋め込み //document.referrer;//
var ret = (navigator.platform.indexOf("Win") != -1) ? "\r\n" : "\n";
var title = document.title.replace(/ https?:.*/, "");
title = title.replace(RegExp(sakujoRE, "g"), ""); // Shift+C 除去文字列を除去
txt2 = txt2.replace(RegExp(sakujoRE, "g"), "");
if (cckaisuu % 1 == 0) { var txt = title + ret + txt2 + ret; var bal = "<B>" + title + "</B><BR>" + txt2; }
var sort = "";
// 列挙するタイプのサイトなら
if (/seiga\.nicovideo\.jp\/my\/manga\/favorite|webcomics\.jp\/mylist|webcomics\.jp\/bookmark|www\.nicovideo\.jp\/my\/mylist|seiga\.nicovideo\.jp\/my\/clip|www\.nicovideo\.jp\/my\/fav\/|www\.nicovideo\.jp\/my\/channel|www\.nicovideo\.jp\/my\/community|www\.nicovideo\.jp\/my\/top\/all/.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', '//div[@class="outer"]/div/h5/a', '//div[@class="outer"]/h5/a', '//div[@class="log-target-info"]/a'];
txt = ""; //title+ret;
txt2 = "";
var num = 0;
for (let target of rekkyo) {
var ele = elegeta(target);
if (cckaisuu % 4 == 1) { sort = " 名前↓"; ele.sort(function(a, b) { return (a.innerText > b.innerText) ? 1 : -1; }); }
if (cckaisuu % 4 == 2) { sort = " URL↓"; ele.sort(function(a, b) { return (a.href.split(/\/\//g)[1]) > (b.href.split(/\/\//g)[1]) ? 1 : -1; }); }
if (cckaisuu % 4 == 3) { sort = " URL↑"; ele.sort(function(a, b) { return (a.href.split(/\/\//g)[1]) < (b.href.split(/\/\//g)[1]) ? 1 : -1; }); }
for (let a of ele) {
// if (a.style.display=="none"){ // 非表示じゃないやつだけ
var cleanurl = a.href.replace(/\?track=.*|\?.*/g, "")
txt += a.innerText + ret + cleanurl + ret;
txt2 += a.innerText + "<BR>" + cleanurl + "<BR>";
num++;
// }
}
}
title += " " + num + "件" + sort;
txt = title + ret + txt;
var bal = "<B>" + title + "</B><BR>" + txt2;
}
// クリップボードにコピー
var a = document.createElement("textarea");
a.value = txt;
document.body.appendChild(a);
a.select();
document.execCommand("copy");
a.parentElement.removeChild(a);
// バルーン表示
popup(bal);
e.preventDefault();
cckaisuu++;
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 ele = eleget0("//span[@id='ctrlc']");
var opa = ele ? 0.9 : 0.8;
var panel = document.createElement("span");
panel.setAttribute("style", "max-width:95%; right:0; top:0; z-index:2147483647; opacity:" + opa + "; 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.innerHTML = txt;
panel.id = "ctrlc";
document.body.appendChild(panel);
setTimeout(function() { panel.parentElement.removeChild(panel); }, 4000);
return;
}
// タイトルに足す
function addtitle(url, txt1, xpath, optionxpath = "", optionReplaceRE = /$^/, separator = " - ") {
if (url.test(location.href)) {
var ele = eleget0(xpath).value;
if (!ele) { ele = eleget0(xpath).innerText; }
var ret = ele.trim() > "" ? ele.trim() + separator : "";
if (optionxpath && eleget0(optionxpath)) { ret += "" + (eleget0(optionxpath).innerText.trim().replace(optionReplaceRE, "")) + " "; }
document.title = ret + document.title;
}
return;
}
// クリップボードにコピー
function copy2cb(txt) {
var a = document.createElement("textarea");
a.value = txt;
document.body.appendChild(a);
a.select();
document.execCommand("copy");
a.parentElement.removeChild(a);
}
})();