LoginSignup
9
9

More than 5 years have passed since last update.

Qiitaの記事タイトルとURLを楽にコピーするブックマークレットを改良してみた

Last updated at Posted at 2015-09-17

前回:
Qiitaの記事タイトルとURLを楽にコピーするブックマークレット作ってみた

いただいた編集リクエストを参考にMarkdown記法をコピーできるテキストエリアとEscキーでウィンドウを削除する機能を追加しました。
(個人的には選択肢が多い方がいいと思ったため、元のコピー機能も残しました)

以下圧縮済みコードです。

javascript:void (function(e){var f=location.href;f=f.split("?")[0]||f;if(f.split("/")[4]!="items"){return;}(function d(){var m=e.getElementsByTagName("h1")[0].innerHTML;
var b=e.body||e.getElementsByTagName("body")[0];var n=e.createElement("div");n.setAttribute("style","z-index: 9999;position: fixed;top: 0px;bottom: 0px;left: 0px;right: 0px;width: 50%;height: 50%;margin: auto;padding: 1%;border-radius: 5px;background: #666;");
var c=e.createElement("div");c.setAttribute("style","z-index: 9999;position: absolute;width: 5%;height: 100%;top: 0px;right: 0px;background: #f93;text-align: center;border-radius: 5px;font-size: 150%;cursor: pointer;");
c.onclick=function(){var g=this.parentNode;b.removeChild(g);};c.onmouseover=function(){this.style.backgroundColor="#fa6";this.style.color="#666";};c.onmouseout=function(){this.style.backgroundColor="#f93";
this.style.color="#000";};var k=e.createElement("p");k.setAttribute("style","position: absolute;top: 0px;bottom: 0px;left: 0px;right: 0px;height: 1em;width: 1em;margin: auto;padding: 0;font-weight: bold;user-select: none;");
k.innerHTML="×";c.appendChild(k);var a=e.createElement("textarea");a.setAttribute("style","width: 95%;height: 50%;padding: 1%;text-align: center;border-radius: 5px;border: none;resize: none;");
var l=a.cloneNode(true);a.innerHTML=m+"\r\n"+f;l.innerHTML="["+m+"]("+f+")";l.onfocus=a.onfocus=function(){this.select();};l.onkeydown=a.onkeydown=function(g){if(g.which==27){c.click();
}};n.appendChild(a);n.appendChild(l);n.appendChild(c);b.appendChild(n);}());}(document));

また時間のある時にGreaseMonkeyのスクリプトとして整形しようと思います。
作成したのでリンク:
Qiitaの記事タイトルとURLを楽にコピーするGreaseMonkeyスクリプトを改良してみた

追記:
GreaseMonkey用のコードを改変していたのでブックマークレット用コードに修正しました。

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9