Google Light Navbar のユーザースクリプトを修正してみた

Google Light Navbar は便利なユーザースクリプトだったけれど、
Cookieが使えない環境では、起動するたびに設定をし直す必要があった。


そこで、Cookieを使わないように元のコードをフォークし、修正してみた。
(元のソースは、userscripts.orgにて公開されている (MITライセンス))


修正内容は以下。

  • デフォルトの色をハードコーディング
  • Cookieを使用しないため、不要な箇所を削除
  • 名前は迷ったけれど、「for Screenshot」を追加
  • 動作確認はChromeのみ


コードは以下。

// ==UserScript==
// @name        Google Light Navbar for Screenshot
// @namespace   http://d.hatena.ne.jp/thinkAmi/
// @description Fork Google Light Navbar, main color is black and without cookie
// @author      thinkAami
// @version     1.0
// @license     MIT License
// @source      https://gist.github.com/1697132
// @include     http://*.google.*
// @include     https://*.google.*
// ==/UserScript==

// Fork of Google Light Navbar (http://userscripts.org/scripts/review/105735)
// original author is akira@Taiwan (http://userscripts.org/users/336234)

// スクリーンショットを撮りやすくするために、デフォルトの色を黒に統一
// Cookieの状態に依存しないよう、デフォルトの色をハードコーディングし、不要な部分を削除

(function(){

// Helper Functions
function $(q, root, single, context) {
	root = root || document;
	context = context || root;
	if (q[0] == '#') return root.getElementById(q.substr(1));
	if (q.match(/^[\/*]|^\.[\/\.]/)) {
		if (single) return root.evaluate(q, context, null, 9, null).singleNodeValue;
		var arr = [], xpr = root.evaluate(q, context, null, 7, null);
		for (var i = 0, length = xpr.snapshotLength; i < length; i++) arr.push(xpr.snapshotItem(i));
		return arr;
	}
	if (q[0] == '.') {
		if (single) return root.getElementsByClassName(q.substr(1))[0];
		return root.getElementsByClassName(q.substr(1));
	}
	if (single) return root.getElementsByTagName(q)[0];
	return root.getElementsByTagName(q);
}
function $create(tag, attributes) {
	var element = document.createElement(tag);
	if (attributes && typeof attributes == 'object') {
		for (attribute in attributes) {
			if (attribute) element[attribute] = attributes[attribute];
		}
	}
	return element;
}


var backgroundColor = '#000000',
	foregroundColor = '#000000',
	borderColor = '#DAE2F2';
	

// Insert CSS rules.
var style = $create('style', {type: 'text/css'});

style.innerHTML = '\
	#gbx3, #gbx4 { border-bottom: 1px solid ' + borderColor + ' !important; background: ' + backgroundColor + ' url("//ssl.gstatic.com/gb/images/b_8d5afc09.png") 0 -138px repeat-x; opacity: 1; }\
	.gbts { color: ' + foregroundColor + '; }\
	.gbz0l .gbtb2 { border-top-color: ' + borderColor + ' !important; }\
	.gbz0l .gbts { color: ' + foregroundColor + '; font-weight: bold; }\
	.gbzt:hover, .gbgt:hover { background-color: ' + borderColor + '; }\
	#gbi5 { background-position: -6px -22px; }\
	.msel, .tbos, #leftnav h2 { color: ' + foregroundColor + ' !important; font-weight: bold; }\
	.mitem:hover { background: ' + borderColor + '; }\
	.micon { background: transparent url("//www.google.com/images/srpr/nav_logo73.png"); }\
	';
	
$('head')[0].appendChild(style);

})();


GitHubのサービスの中で、一ファイルを公開するのに便利なgistが提供されていたため、
上記のファイルはgistでも公開。
gist: 1697132 - GitHub