getHTMLsource
by
sin5
2010-06-25 [2010/06/25 22:49:28]
選択した範囲のHTMLのソースを整形して表示してくれるWEBサービスに飛ばします。
@@ -1,14 +1,18 @@
/*
- * @title bookmarklet
- * @description my bookmarklet
- * @include http://*javascript:"http%3A%2F%2Flet.hatelabo.jp%2Fsin5%2Ft%2Fc0dcf3aaf894370fa1d9a22eb8cfc4eb7246e70b.js%20%28arg%29".replace%28%2F%28%5CS%2B%29%5Cs%2B%28%5CS%2A%29%2F%2Cfunction%28s%2Curl%2Carg%29%7Bs%3Ddocument.createElement%28"script"%29%3Bs.charset%3D"utf-8"%3Bs.src%3Durl%2B"%3Fs%3D"%2BencodeURIComponent%28arg%29%3Bdocument.body.appendChild%28s%29%7D%29%3Bvoid%280%29%3B
+ * @title getHTMLsource
+ * @description get selected HTML source
* @license MIT License
- * @require
* @private
*/
-con = document.getSelection().getRangeAt(0).cloneContents();
-div = document.createElement('div');
-document.body.appendChild(div);
-div.appendChild(con);
-alert(div.innerHTML);
+var source = "";
+if(document.getSelection){
+ con = document.getSelection().getRangeAt(0).cloneContents();
+ div = document.createElement('div');
+ document.body.appendChild(div);
+ div.appendChild(con);
+ source = div.innerHTML
+} else if(document.selection){
+ source = document.selection.createRange().htmlText;
+}
+alert(source);
/*
* @title getHTMLsource
* @description get selected HTML source
* @license MIT License
* @private
*/
var source = "";
if(document.getSelection){
con = document.getSelection().getRangeAt(0).cloneContents();
div = document.createElement('div');
document.body.appendChild(div);
div.appendChild(con);
source = div.innerHTML
} else if(document.selection){
source = document.selection.createRange().htmlText;
}
alert(source);
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。