TODO:
1. 加入別的搜尋引擎,目前是 google only
2. 修正版面亂掉的問題
3. 做成一個bookmarklet版本似乎比較好
4. 加入取消效果的機制
以下範例是在 google 搜尋 ppk javascript 進入第二個搜尋結果,使用前:

使用後:

// ==UserScript==
// @name birdegg's search engine highlighter
// @namespace http://chunghe.blogspot.com
// @description highlight the keyword
// @include *
// @exclude http://www.google.tld/*
// ==/UserScript==
(function(){
if(document.referrer.indexOf('google')<0) return;
var b = document.body.innerHTML;
var r = document.referrer.split('&');
for(var i=0; i<r.length && (r[i].indexOf('q=')<0); i++);
var k = r[i].substring(2).split('+');
for(var j=0; j<k.length; j++){
// the second argument of replace function can be a function !
document.body.innerHTML = document.body.innerHTML.replace(new RegExp(k[j], 'gi'), function(w){
return '<span style="background:yellow;">'+w+'</span>';
});
}
})();
沒有留言:
張貼留言