getSearchWords.js
3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* リファラーから検索文字列を取得しArrayを返す
* 引数referrerが指定されてるときはその文字列(URL)から検索文字列を取得しArrayを返す
*/
function getSearchWords(referrer) {
//引数が無ければリファラーを取得
if (!referrer) {
referrer = document.referrer;
}
//referrer(文字列)をパースしてURIオブジェクトへ(要parseUri 1.2.2)
uri = parseUri(referrer);
//ホスト判定してからクエリの検索文字列と区切り文字を取得
queryString = "";
delimiter = "+";
//文字列のデコードを行う関数(要ecl.js Ver.041208)
DecodeFunction = UnescapeUTF8;
switch(uri.host) {
case "www.google.com": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} break;
case "www.google.co.jp": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} break;
case "search.msn.co.jp": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} else
if (queryString = uri.queryKey.MT) {DecodeFunction = UnescapeUTF8;} break;
case "www.bing.com": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} break;
case "search.livedoor.com": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeEUCJP;} break;
case "home.search.biglobe.ne.jp": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeEUCJP;} break;
case "search.live.com": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} break;
case "jp.ask.com": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} break;
case "search.nifty.com": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} else
if (queryString = uri.queryKey.Text) {DecodeFunction = UnescapeUTF8;} break;
case "www.altavista.com": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} break;
case "www.alltheweb.com": if (queryString = uri.queryKey.q) {DecodeFunction = UnescapeUTF8;} break;
case "search.yahoo.co.jp": if (queryString = uri.queryKey.p) {DecodeFunction = UnescapeUTF8;} break;
case "search.yahoo.com": if (queryString = uri.queryKey.p) {DecodeFunction = UnescapeUTF8;} break;
case "search.goo.ne.jp": if (queryString = uri.queryKey.MT) {DecodeFunction = UnescapeEUCJP;} break;
case "www.excite.co.jp": if (queryString = uri.queryKey.search) {DecodeFunction = UnescapeSJIS;} break;
case "search.www.infoseek.co.jp": if (queryString = uri.queryKey.qt) {DecodeFunction = UnescapeUTF8;} break;
default:
return "";
break;
}
//検索文字列デコード+Array化
words = queryString=="" ? [] : DecodeFunction(queryString).split(delimiter);
return words;
}
function SetHighLightWords(words, HighLightID, BeginHighLightTAG, EndHighLightTAG) {
if (words == "" || HighLightID == ""){ return "";}
var TaregetText = document.getElementById(HighLightID).innerHTML;
var pattern = new RegExp(words.join("|"), "gi");
var SetHighLightTag = function SetHighLightTag(SearchWord){
if ((BeginHighLightTAG =="" || EndHighLightTAG=="") || (!BeginHighLightTAG || !EndHighLightTAG)){
return '<span style="color:#FF0000; font-weight:bold;">' + SearchWord + '</span>';
}else{
return BeginHighLightTAG + SearchWord + EndHighLightTAG;
}
}
document.getElementById(HighLightID).innerHTML = TaregetText.replace(pattern, SetHighLightTag);
}