そのへんにぺろっと貼ってあるgreasemonkeyスクリプトにインストールボタンを付けるgreasemonkeyスクリプト

これスゲェ便利だなぁ。

そのへんにぺろっと貼ってあるgreasemonkeyスクリプトにインストールボタンを付ける

// ==UserScript==
// @name           pasted script installer
// @namespace      http://d.hatena.ne.jp/kusigahama/
// @include        http://*.g.hatena.ne.jp/*
// @include        http://d.hatena.ne.jp/*
// @include        http://anond.hatelabo.jp/*
// ==/UserScript==

(function(){

	var a = document.getElementsByTagName('pre');
	for (var i=0 ; i<a.length ; ++i) {
		//if ( a[i].className != "syntax-highlight" ) continue;
		
		var stripTags = function(s) { return s.replace(/<\/?[^>]+>/gi, ''); }
		var s = stripTags(a[i].innerHTML)
		if ( !s.match(/^\/\/ ==UserScript==/) ) continue;

		var unescapeHTML = function(s) {
			var div = document.createElement('div');
			div.innerHTML = stripTags(s);
			return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
		}
		s = unescapeHTML(s);
		
		var div = document.createElement('div');
		div.style.marginBottom = "1em";
		var l = document.createElement('a');
		l.href = "data:text/html;charset=utf-8," + escape(s) + "//.user.js";
		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;">&raquo;</span>' +
			'<span style="font-weight: bold;">Install this script</span></span>';
		div.appendChild(l);
		a[i].insertBefore(div, a[i].firstChild);
	}

})();