2006-10-21
『 色んなところにfaviconを - 準二級.jp』の改良
『Going My Way: Googleの検索結果やはてなブックマークにfaviconを表示するGreasemonkeyユーザースクリプト』経由
はてブと Google のリストに favicon を表示できる Greesemonkey スクリプトがあった]ので導入してみました.そこのコメントで議論されているように,favicon.ico が存在しないサイトがあるとガタガタになってしまう欠点があります.製作者の jun29 さんと同じく,私も favicon があると楽しいですから,それで全然問題無いです.
でもやっぱり,favicon.ico が無いサイトには Firefox のデフォルトアイコンを表示させたいですよね.そこで,スクリプトを改良しました.
改良版スクリプト
それぞれのスクリプト名には 2 って付けて違うものにしてあります.同時にインストールした場合は,どちらかを Disable にしましょう.
まず Google 用:
// ==UserScript==
// @name Favicon with Google 2
// @namespace http://libelabo.jp/
// @description A script to add favicons next to links on Google search results
// @include http://*google.*/*q=*
// @exclude http://mail.google.com/*
// ==/UserScript==
(function(){
// apply the function to each element found by the path
function forEachMatch(path, f, root) {
var root = (root == null) ? document : root;
var matches = root.evaluate(
path, root, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < matches.snapshotLength; i++)
f(matches.snapshotItem(i));
}
// adds the link favicon before itselft
function add_favicon(link) {
var g = link.parentNode;
var container = document.createElement('div');
container.style.marginLeft = '16px';
container.style.paddingLeft = '1ex';
while (g.firstChild != null) {
var e = g.firstChild;
g.removeChild(e);
container.appendChild(e);
}
var favicon_container = document.createElement('div');
favicon_container.style.cssFloat = 'left';
favicon_container.style.minWidth = '16px';
favicon_container.style.minHeight = '16px';
favicon_container.style.backgroundImage =
'url("chrome://global/skin/icons/folder-item.png")';
var favicon = document.createElement('img');
favicon.src = "http://" + link.hostname + "/favicon.ico";
favicon.width = 16;
favicon.alt = "";
favicon_container.appendChild(favicon);
g.appendChild(favicon_container);
g.appendChild(container);
}
// apply to all recent links, popular and your bookmarks
forEachMatch(
"//a[@class='l']",add_favicon);
}())
続いて,はてブ用:
// ==UserScript==
// @name Favicon with Hatena Bookmark 2
// @namespace http://www.libelabo.jp/
// @description A script to add favicons next to links on Hatena Bookmark
// @include http://b.hatena.ne.jp/*
// @exclude http://b.hatena.ne.jp/rss/*
// ==/UserScript==
(function(){
// apply the function to each element found by the path
function forEachMatch(path, f, root) {
var root = (root == null) ? document : root;
var matches = root.evaluate(
path, root, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < matches.snapshotLength; i++)
f(matches.snapshotItem(i));
}
// adds the link favicon before itselft
function add_favicon(link) {
var entry_body = link.parentNode;
var container = document.createElement('div');
container.style.marginLeft = '16px';
container.style.paddingLeft = '1ex';
while (entry_body.firstChild != null) {
var e = entry_body.firstChild;
entry_body.removeChild(e);
container.appendChild(e);
}
var favicon_container = document.createElement('div');
favicon_container.style.cssFloat = 'left';
favicon_container.style.minWidth = '16px';
favicon_container.style.minHeight = '16px';
favicon_container.style.backgroundImage =
'url("chrome://global/skin/icons/folder-item.png")';
var favicon = document.createElement('img');
favicon.src = 'http://' + link.hostname + '/favicon.ico';
favicon.alt = '';
favicon.width = 16;
favicon_container.appendChild(favicon);
entry_body.appendChild(favicon_container);
entry_body.appendChild(container);
}
// apply to all recent links, popular and your bookmarks
forEachMatch(
"//a[@class='bookmark'] | //a[@class='news_title']",add_favicon);
}())
スクリーンショット
雑感
トラックバック - http://d.hatena.ne.jp/mrkn/20061021/1161417780
- http://d.hatena.ne.jp/tsaka/20061029
- http://d.hatena.ne.jp/kei-s/20061110
- faviconのつけ方
- http://d.hatena.ne.jp/waajeed/20070620
- 方向性∞ - Greasemonkey×はてな×Favicon×Google Reader[f:id:NT...
- ヒビノキロク - Googleウェブ履歴にサムネイルとfaviconを表示するG...
- 方向性∞ - 私のFirefoxカスタマイズメモ
- やぬすさんとこの日記 - Firefox
- blooo - あらゆる所にFaviconを付けられる可能性を秘めたGreasemonk...
リンク元
- 737 http://designwork-s.com/article/44393662.html
- 545 http://june29.jp/2006/10/18/favicon-greasemonkey/
- 476 http://caramel-tea.com/2007/01/google_greasemonkey/
- 151 http://d.hatena.ne.jp/kei-s/20061110/1163182451
- 70 http://caramel-tea.com/2007/01/fav_favicon/
- 52 http://d.hatena.ne.jp/
- 42 http://reader.livedoor.com/reader/
- 33 http://d.hatena.ne.jp/nozom/20071110/1194696498
- 33 http://memo.xight.org/2006-10-21-2
- 32 http://white.s151.xrea.com/wiki/index.php?diary/2007-06-01/AutoPagerize








