hagino3000's blog

平成アーカイブス (更新停止)

ページタイトルとURLを表示するブックマークレット

greasemonkeyでminibuffer使えば5行くらいで終わる所をわざわざブックマークレットにしてみました。Firefox3RC1でgreasemonkeyが無効化されてしまったのでその対策+ブックマークレットの復習として。

こんな感じで画面上部からにゅ〜っとパネルが出てきます。


コード

javascript:(function(){var isMSIE = /*@cc_on!@*/false;var opacity = 70;var setOpacity = function(elm){if(isMSIE) {elm.style.filter = 'alpha(opacity='+ opacity +')';} else {elm.style.MozOpacity = (opacity/100);}};var info = document.createElement('div');info.style.position = isMSIE ? 'absolute':'fixed';info.style.top  = '0';info.style.left = '0';info.style.width  = '100%';info.style.background = '#000000';info.style.color = '#FCFCFC';info.style.textAlign = 'left';info.style.zIndex = 1000;info.style.MozBorderRadius = '0 0 20px 20px';info.style.height = 0;setOpacity(info);var body = document.getElementsByTagName('body')[0];body.appendChild(info);var h = 0;show = setInterval(function(){info.style.height = (h + 'em');h += 0.4;if(h > 6) {clearInterval(show);info.innerHTML = '<div style="margin:1em 0 0 2em">' + document.title + '<br />' + location.href + '</div>';wait = setTimeout(function(){hide = setInterval(function(){opacity -= 10;setOpacity(info);if(opacity == 0) {body.removeChild(info);clearInterval(hide);clearTimeout(wait);}},25);}, 5000);}},30);})();void(0);


改行とコメントありの状態はこちら

javascript:(function(){
	// ブラウザ判定
	var isMSIE = /*@cc_on!@*/false;
	// 透明度
	var opacity = 70;
	// opacity設定処理を定義 operaは動かないかも
	var setOpacity = function(elm){
		if(isMSIE) {
			elm.style.filter = 'alpha(opacity='+ opacity +')';
		} else {
			elm.style.MozOpacity = (opacity/100);
		}
	};

	// パネル用エレメント作成
	var info = document.createElement('div');
	// スタイル設定
	info.style.position = isMSIE ? 'absolute':'fixed';
	info.style.top  = '0';
	info.style.left = '0';
	info.style.width  = '100%';
	info.style.background = '#000000';
	info.style.color = '#FCFCFC';
	info.style.textAlign = 'left';
	info.style.zIndex = 1000;
	info.style.MozBorderRadius = '0 0 20px 20px';
	info.style.height = 0;
	setOpacity(info);
	
	// bodyに追加
	var body = document.getElementsByTagName('body')[0];
	body.appendChild(info);

	// 領域を広げる
	var h = 0;
	show = setInterval(function(){
		info.style.height = (h + 'em');
		h += 0.4;
		if(h > 6) {
			// タイマー削除
			clearInterval(show);
			// 文字の挿入
			info.innerHTML = '<div style="margin:1em 0 0 2em">' + document.title + '<br />' + location.href + '</div>';
			// 5秒後に消去
			wait = setTimeout(function(){
				hide = setInterval(function(){
					opacity -= 10;
					setOpacity(info);
					if(opacity == 0) {
						body.removeChild(info);
						clearInterval(hide);
						clearTimeout(wait);
					}
				},25);
			}, 5000);
		}
	},30);
})();void(0);