pastedbookmarkletinstaller.user.js
ひとまず仮。あとでちゃんと直す。
%0A
というのが改行コード? らしいのでこれ削除他にもスペース%20
とかいらない文字もとるほうがいいか?- install のボタンはボタンじゃなくて link でいい
AutoPageirze 対応のところを今風? に- そうしてみた
$X を外出しにする- そうしてみた
- 改行もスペースも正規表現の
\s
で削除するということか。それからencodeURI
すればいいんだな。たぶん。- そうしてみた
- あ! ヤベー var の後のスペースは消しちゃだめだった。
- ひとまず、 複数の
\s
はスペース1個に置きかえることにする
- ひとまず、 複数の
とかとか
もう一応完成でいいや。
説明:
bookmarklet(javascript:
で始まるヤツ)が改行やスペースが入ってて人に見易くなっているのが pre で貼り付けてあったら、それに install 用のリンクを付けるグリモンです。あー説明が適当だ。まあいいや自分でわかってれば。
// ==UserScript== // @name pasted bookmarklet installer // @namespace http://d.hatena.ne.jp/taizooo // @include http*://*.g.hatena.ne.jp/* // @include http://d.hatena.ne.jp/* // @include http://anond.hatelabo.jp/* // @require http://gist.github.com/raw/3242/9dc0cdee5e975d275c7ab71f581d272eb316674f/dollarX.js // ==/UserScript== var f = function(context){ var a = $X("descendant-or-self::pre[not(child::div)]", context); for (var i=0 ; i<a.length ; ++i) { var s = a[i].textContent; if ( !/^javascript:/.test(s) ) continue; var div = document.createElement('div'); div.style.marginBottom = "1em"; var l = document.createElement('a'); l.href = encodeURI(s.replace(/\s+/gi, ' ')); l.setAttribute("style", "border: 1px solid #666; text-decoration:none; padding: 3px 6px;font-family: Arial; font-size: 10px; background: white; color: black;"); l.setAttribute("onmousedown", "this.firstChild.style.left = '1px'; this.firstChild.style.top = '1px'"); l.setAttribute("onmouseup", "this.firstChild.style.left = '0px'; this.firstChild.style.top = '0px'"); l.innerHTML = '<span style="position: relative; left: 0px; top: 0px;">' + //'<img src="data:image/gif," width=10 height=8> ' + //'<span style="font-size: 1.3em; padding-right: 5px; color: #2c2;">»</span>' + '<span style="font-weight: bold; color: red;">install this bookmarklet</span></span>'; div.appendChild(l); a[i].insertBefore(div, a[i].firstChild); } } f(); //for AutoPagerize var x = function(){ window.AutoPagerize.addFilter(function(docs){docs.forEach(f);}); } if (window.AutoPagerize && window.AutoPagerize.addFilter) x(); else window.addEventListener('GM_AutoPagerizeLoaded', x, false);