Created
July 26, 2008 12:16
-
-
Save monmon/2644 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name nifty_cilp_rss_search | |
// @namespace http://github.com/monmon | |
// @description googleの検索結果に自分のクリップを入れる | |
// @include http://www.google.co.jp/* | |
// ==/UserScript== | |
(function(){ | |
var user = 'monmon'; // 自分のユーザ名 | |
var input = $x("//input[@type='text']")[0]; // 空欄の時用 | |
var keyword = input ? input.value.split(/\s/)[0] | |
: ''; | |
var url = 'http://pipes.yahoo.com/pipes/pipe.run?_id=BMY0rpRi3BGxrheMLO2fWQ&_render=json&user=' | |
+ user + '&keyword=' + keyword; | |
// コールバック | |
function showClip(obj){ | |
var clip = eval('(' + obj.responseText + ')'); // pipes情報 | |
if (! clip.count) return; // 情報なかったら抜ける | |
var strArray = []; | |
clip.value.items.map(function(a){ | |
strArray.push('<p style="font-size:90%;"><a href="', a.link, '">', | |
a.title.toString().replace(keyword,'<strong>' + keyword + '</strong>'), '</a></p>', | |
'<p style="font-size:70%"><span style="color:green;">【', a["dc:subject"].toString().replace(keyword,'<strong>' + keyword + '</strong>'), '】</span><br />', | |
//a.description.toString().replace(keyword,'<strong>' + keyword + '</strong>'), | |
'<br /></p>'); | |
}); | |
var str = strArray.join(''); | |
// 箱づくり | |
var div = document.createElement('div'); | |
divStyle = div.style; // styleを何回も | |
divStyle.marginLeft = '50px'; | |
divStyle.width = '28%'; | |
divStyle.overflow = 'scroll'; | |
divStyle.position = 'absolute'; | |
divStyle.top = '150px'; | |
divStyle.right = '0px'; | |
divStyle.backgroundColor = '#fff'; | |
divStyle.borderLeft = 'solid #eee 5px'; | |
divStyle.paddingLeft = '10px'; | |
divStyle.lineHeight = '100%'; | |
div.innerHTML = str; | |
// スポンサーリンク削除 | |
var ad = $('mbEnd'); | |
if (ad) { | |
ad.style.display = 'none'; | |
} | |
var res = $('res'); | |
res.appendChild(div); | |
} | |
// クリップ情報を取ってくる | |
GM_xmlhttpRequest({ | |
method: 'get', | |
url: url, | |
onload: showClip | |
}); | |
// システム系の関数(コピペ) | |
/** | |
* $x() | |
* http://lowreal.net/2006/shibuya-js-1-lt.html | |
* http://lowreal.net/logs/2006/03/16/1 | |
* // セクションクラスな div 列挙 | |
* $X("//div[@class='section']"); | |
* | |
* // 最初の h1 要素 | |
* $X("//h1[0]"); | |
* | |
* // 最後の p 要素 | |
* $X("//p[last()]"); | |
* | |
* // address 要素以下で、 | |
* // mailto スキームから始まる a 要素 | |
* $X("//address//a[starts-with(@href, 'mailto:')]"); | |
* | |
* // 要素選択以外でも使えるよ? | |
* $X("string()", node); //=> "Foo Bar" | |
* | |
*/ | |
function $x(exp, context) { | |
if (!context) context = document; | |
var resolver = function (prefix) { | |
var o = document.createNSResolver(context)(prefix); | |
return o ? o : (document.contentType == "text/html") ? "" : "http://www.w3.org/1999/xhtml"; | |
} | |
var exp = document.createExpression(exp, resolver); | |
var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); | |
switch (result.resultType) { | |
case XPathResult.STRING_TYPE : return result.stringValue; | |
case XPathResult.NUMBER_TYPE : return result.numberValue; | |
case XPathResult.BOOLEAN_TYPE: return result.booleanValue; | |
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: { | |
result = exp.evaluate(context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
var ret = []; | |
for (var i = 0, len = result.snapshotLength; i < len ; i++) { | |
ret.push(result.snapshotItem(i)); | |
} | |
return ret; | |
} | |
} | |
return null; | |
} | |
/** | |
* $() | |
*/ | |
function $(id){ return document.getElementById(id) } | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment