Created
December 10, 2012 10:42
-
-
Save ethertank/4249887 to your computer and use it in GitHub Desktop.
Bookmarklet: LinkToThisPage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function() { | |
var a = document.createElement("a"), | |
u = location.href, | |
t = document.title || u, | |
e = (function() { | |
var map = { | |
'<': '<', | |
'>': '>', | |
'&': '&', | |
'"': '"' | |
}, | |
r = function(s) { | |
return map[s]; | |
}; | |
return function(S) { | |
return S.replace(/<|>|&|"/g, r); | |
}; | |
})(), | |
t = e(t); | |
a.href = e(u); | |
a.title = a.innerText = t; | |
prompt(t, a.outerHTML); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li>Bookmarklet: <a href="javascript:(function(){var%20a=document.createElement(%22a%22),u=location.href,t=document.title||u,e=(function(){var%20map={'<':'<','>':'>','&':'&','%22':'"'},r=function(s){return%20map[s];};return%20function(S){return%20S.replace(/<|>|&|%22/g,r);};})(),t=e(t);a.href=e(u);a.title=a.innerText=t;prompt(t,a.outerHTML);})();">リンクタグ生成-ethertank-20121211</a></li> | |
</ul> | |
| |
<!-- | |
「閲覧中のページへのリンクを作成」 | |
属性: href, title | |
以前作ったものはエスケープがなく問題が出たので再作成。引用符が多くて鬱陶しかったので構造も変えた。 | |
作り直すのが面倒だったので再作成前に Web 検索したが、同種のブックマークレットの殆どに同じ問題が有ったので結局自作。 | |
document.title が存在しない場合(PDF などの場合)、URL 文字列をタイトルの代替とする。 | |
また改善案が出たら直す。document.title が無い時に [PDF] って文字列を突っ込むとかどうかなとか色々考えたけど、 | |
もうちょいちゃんと練ってから追加する。とりあえずこれでいいわ。 | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment